A React Native app for the ultimate thinking partner.
at main 96 lines 3.2 kB view raw
1const { LettaClient } = require('@letta-ai/letta-client'); 2const token = process.env.LETTA_API_KEY; 3 4if (!token) { 5 console.error('Please set LETTA_API_KEY environment variable'); 6 process.exit(1); 7} 8 9const client = new LettaClient({ token }); 10 11async function ensureSleeptimeTools(agent) { 12 try { 13 const sleeptimeAgentId = agent.multiAgentGroup?.agentIds?.[0]; 14 15 if (!sleeptimeAgentId) { 16 console.log('No sleeptime agent found for agent:', agent.id); 17 return; 18 } 19 20 console.log('Ensuring sleeptime agent has archival tools:', sleeptimeAgentId); 21 22 // Get the sleeptime agent to check its current tools 23 const sleeptimeAgent = await client.agents.retrieve(sleeptimeAgentId); 24 const sleeptimeToolNames = sleeptimeAgent.tools?.map(t => t.name) || []; 25 26 console.log('Current sleeptime tools:', sleeptimeToolNames); 27 28 // Attach missing tools 29 const requiredTools = ['archival_memory_search', 'archival_memory_insert']; 30 for (const toolName of requiredTools) { 31 if (!sleeptimeToolNames.includes(toolName)) { 32 console.log(`Attaching ${toolName} to sleeptime agent`); 33 try { 34 // Find tool by name 35 const tools = await client.tools.list({ name: toolName }); 36 if (!tools || tools.length === 0) { 37 console.error(`✗ Tool ${toolName} not found`); 38 continue; 39 } 40 41 const tool = tools[0]; 42 await client.agents.tools.attach(sleeptimeAgentId, tool.id); 43 console.log(`✓ Successfully attached ${toolName} (${tool.id})`); 44 } catch (error) { 45 console.error(`✗ Failed to attach ${toolName}:`, error.message); 46 if (error.body) console.error('Error details:', JSON.stringify(error.body, null, 2)); 47 } 48 } else { 49 console.log(`${toolName} already attached`); 50 } 51 } 52 } catch (error) { 53 console.error('Error in ensureSleeptimeTools:', error.message); 54 if (error.body) console.error('Error details:', JSON.stringify(error.body, null, 2)); 55 throw error; 56 } 57} 58 59(async () => { 60 try { 61 // Find the Co agent by tag 62 console.log('Looking for Co agent with tag: co-app'); 63 const agents = await client.agents.list({ tags: ['co-app'], matchAllTags: true, limit: 1 }); 64 65 if (!agents || agents.length === 0) { 66 console.log('No Co agent found with tag co-app'); 67 return; 68 } 69 70 const coAgent = agents[0]; 71 console.log('\n=== CO AGENT ==='); 72 console.log('ID:', coAgent.id); 73 74 // Retrieve full agent details 75 const fullAgent = await client.agents.retrieve(coAgent.id); 76 77 console.log('\n=== RUNNING ensureSleeptimeTools ==='); 78 await ensureSleeptimeTools(fullAgent); 79 80 console.log('\n=== VERIFICATION ==='); 81 const sleeptimeAgentId = fullAgent.multiAgentGroup?.agentIds?.[0]; 82 if (sleeptimeAgentId) { 83 const updatedAgent = await client.agents.retrieve(sleeptimeAgentId); 84 console.log('Final sleeptime tools:', updatedAgent.tools?.map(t => t.name).join(', ')); 85 } 86 87 } catch (e) { 88 console.error('Error:', e.message); 89 if (e.body) { 90 console.error('Error body:', JSON.stringify(e.body, null, 2)); 91 } 92 if (e.stack) { 93 console.error('Stack:', e.stack); 94 } 95 } 96})();