Skip to content

Commit b9abe54

Browse files
committed
repairToolCall: Also match agent ids with underscores
1 parent c7e3d5f commit b9abe54

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

sdk/src/impl/llm.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,17 @@ export async function* promptAiSdkStream(
234234
// Check if this is a NoSuchToolError for a spawnable agent
235235
// If so, transform to spawn_agents call
236236
if (NoSuchToolError.isInstance(error) && 'spawn_agents' in tools) {
237-
const isSpawnableAgent = spawnableAgents.some((agentId) => {
237+
// Also check for underscore variant (e.g., "file_picker" -> "file-picker")
238+
const toolNameWithHyphens = toolName.replace(/_/g, '-')
239+
240+
const matchingAgentId = spawnableAgents.find((agentId) => {
238241
const withoutVersion = agentId.split('@')[0]
239242
const parts = withoutVersion.split('/')
240243
const agentName = parts[parts.length - 1]
241-
return agentName === toolName || agentId === toolName
244+
return agentName === toolName || agentName === toolNameWithHyphens || agentId === toolName
242245
})
243-
const isLocalAgent = toolName in localAgentTemplates
246+
const isSpawnableAgent = matchingAgentId !== undefined
247+
const isLocalAgent = toolName in localAgentTemplates || toolNameWithHyphens in localAgentTemplates
244248

245249
if (isSpawnableAgent || isLocalAgent) {
246250
// Transform agent tool call to spawn_agents
@@ -281,10 +285,14 @@ export async function* promptAiSdkStream(
281285
),
282286
)
283287

288+
// Use the matching agent ID or corrected name with hyphens
289+
const correctedAgentType = matchingAgentId
290+
?? (toolNameWithHyphens in localAgentTemplates ? toolNameWithHyphens : toolName)
291+
284292
const spawnAgentsInput = {
285293
agents: [
286294
{
287-
agent_type: toolName,
295+
agent_type: correctedAgentType,
288296
...(prompt !== undefined && { prompt }),
289297
...(Object.keys(agentParams).length > 0 && {
290298
params: agentParams,

0 commit comments

Comments
 (0)