this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(bot): re-sync all tools on agent startup

Detach and re-attach all tools when finding existing agent.
This ensures tools have the correct webhook URLs after importing
an agent from a different environment (dev -> prod).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

alice 0df52506 ffdc8c0c

+22 -16
+22 -16
src/bot.ts
··· 28 28 const AGENT_NAME = 'adhd-support-agent'; 29 29 30 30 /** 31 - * Sync any missing tools to an existing agent 31 + * Sync tools to an existing agent 32 32 * 33 - * Compares registered tools with agent's attached tools and attaches any missing ones. 33 + * Detaches all current tools and re-attaches the registered tools. 34 + * This ensures the agent always has tools with the correct webhook URLs 35 + * (important after importing an agent from a different environment). 34 36 */ 35 37 async function syncToolsToAgent(client: ReturnType<typeof getLettaClient>, agentId: string): Promise<void> { 36 38 const registeredToolIds = getRegisteredToolIds(); ··· 38 40 return; 39 41 } 40 42 41 - // Get currently attached tools 42 - const attachedTools = new Set<string>(); 43 + // Detach all currently attached tools 44 + const attachedToolIds: string[] = []; 43 45 for await (const tool of client.agents.tools.list(agentId)) { 44 - attachedTools.add(tool.id); 46 + attachedToolIds.push(tool.id); 45 47 } 46 48 47 - // Attach any missing tools 49 + for (const toolId of attachedToolIds) { 50 + try { 51 + await client.agents.tools.detach(toolId, { agent_id: agentId }); 52 + } catch (err) { 53 + console.warn(`Failed to detach tool ${toolId}:`, err); 54 + } 55 + } 56 + 57 + // Attach all registered tools (with updated source_code/webhook URLs) 48 58 let attached = 0; 49 59 for (const toolId of registeredToolIds) { 50 - if (!attachedTools.has(toolId)) { 51 - try { 52 - await client.agents.tools.attach(toolId, { agent_id: agentId }); 53 - attached++; 54 - } catch (err) { 55 - console.warn(`Failed to attach tool ${toolId}:`, err); 56 - } 60 + try { 61 + await client.agents.tools.attach(toolId, { agent_id: agentId }); 62 + attached++; 63 + } catch (err) { 64 + console.warn(`Failed to attach tool ${toolId}:`, err); 57 65 } 58 66 } 59 67 60 - if (attached > 0) { 61 - console.log(`Attached ${String(attached)} new tools to existing agent`); 62 - } 68 + console.log(`Synced ${String(attached)} tools to agent (detached ${String(attachedToolIds.length)} old)`); 63 69 } 64 70 65 71 /**