* Filter swarm-related fields from a tool's input schema. * Called at runtime when isAgentSwarmsEnabled() returns false.
( toolName: string, schema: Anthropic.Tool.InputSchema, )
| 94 | * Called at runtime when isAgentSwarmsEnabled() returns false. |
| 95 | */ |
| 96 | function filterSwarmFieldsFromSchema( |
| 97 | toolName: string, |
| 98 | schema: Anthropic.Tool.InputSchema, |
| 99 | ): Anthropic.Tool.InputSchema { |
| 100 | const fieldsToRemove = SWARM_FIELDS_BY_TOOL[toolName] |
| 101 | if (!fieldsToRemove || fieldsToRemove.length === 0) { |
| 102 | return schema |
| 103 | } |
| 104 | |
| 105 | // Clone the schema to avoid mutating the original |
| 106 | const filtered = { ...schema } |
| 107 | const props = filtered.properties |
| 108 | if (props && typeof props === 'object') { |
| 109 | const filteredProps = { ...(props as Record<string, unknown>) } |
| 110 | for (const field of fieldsToRemove) { |
| 111 | delete filteredProps[field] |
| 112 | } |
| 113 | filtered.properties = filteredProps |
| 114 | } |
| 115 | |
| 116 | return filtered |
| 117 | } |
| 118 | |
| 119 | export async function toolToAPISchema( |
| 120 | tool: Tool, |