From 4bf102fb278899f1132a14f751ff9e42450a2b33 Mon Sep 17 00:00:00 2001 From: Charles Packer Date: Wed, 31 Dec 2025 19:44:38 -0800 Subject: [PATCH] fix: Fix linkToolsToAgent to use parallel API calls for tool lookup (#443) Co-authored-by: Letta --- src/agent/modify.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/agent/modify.ts b/src/agent/modify.ts index e0f5459..b24a33d 100644 --- a/src/agent/modify.ts +++ b/src/agent/modify.ts @@ -202,17 +202,16 @@ export async function linkToolsToAgent(agentId: string): Promise { }; } - // Look up tool IDs from global tool list - // Use server names when querying, since that's how tools are registered on the server - const toolsToAddIds: string[] = []; - for (const toolName of toolsToAdd) { - const serverName = getServerToolName(toolName); - const toolsResponse = await client.tools.list({ name: serverName }); - const tool = toolsResponse.items[0]; - if (tool?.id) { - toolsToAddIds.push(tool.id); - } - } + // Look up tool IDs in parallel (instead of sequential calls) + const toolsToAddIds = ( + await Promise.all( + toolsToAdd.map(async (toolName) => { + const serverName = getServerToolName(toolName); + const toolsResponse = await client.tools.list({ name: serverName }); + return toolsResponse.items[0]?.id; + }), + ) + ).filter((id): id is string => !!id); // Combine current tools with new tools const newToolIds = [...currentToolIds, ...toolsToAddIds];