A React Native app for the ultimate thinking partner.
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
11(async () => {
12 try {
13 // Find the Co agent by tag
14 console.log('Looking for Co agent with tag: co-app');
15 const agents = await client.agents.list({ tags: ['co-app'], matchAllTags: true, limit: 1 });
16
17 if (!agents || agents.length === 0) {
18 console.log('No Co agent found with tag co-app');
19 return;
20 }
21
22 const coAgent = agents[0];
23 console.log('\n=== CO AGENT ===');
24 console.log('ID:', coAgent.id);
25
26 // Retrieve full agent details
27 const fullAgent = await client.agents.retrieve(coAgent.id);
28 const sleeptimeAgentId = fullAgent.multiAgentGroup?.agentIds?.[0];
29
30 if (!sleeptimeAgentId) {
31 console.log('No sleeptime agent found in multi_agent_group');
32 return;
33 }
34
35 console.log('\n=== SLEEPTIME AGENT ===');
36 console.log('ID:', sleeptimeAgentId);
37
38 // Find archival memory tools by name using API filtering
39 console.log('\n=== FINDING ARCHIVAL TOOLS ===');
40 const archivalSearchTools = await client.tools.list({ name: 'archival_memory_search' });
41 const archivalInsertTools = await client.tools.list({ name: 'archival_memory_insert' });
42
43 const archivalSearchTool = archivalSearchTools?.[0];
44 const archivalInsertTool = archivalInsertTools?.[0];
45
46 console.log('archival_memory_search tool:', archivalSearchTool ? archivalSearchTool.id : 'NOT FOUND');
47 console.log('archival_memory_insert tool:', archivalInsertTool ? archivalInsertTool.id : 'NOT FOUND');
48
49 if (!archivalSearchTool || !archivalInsertTool) {
50 console.log('\n⚠️ Could not find archival memory tools');
51 return;
52 }
53
54 // Check current tools on sleeptime agent
55 const sleeptimeAgent = await client.agents.retrieve(sleeptimeAgentId);
56 const currentToolNames = sleeptimeAgent.tools?.map(t => t.name) || [];
57 console.log('\n=== CURRENT SLEEPTIME AGENT TOOLS ===');
58 console.log(currentToolNames.join(', ') || 'none');
59
60 // Attach archival_memory_search if not present
61 if (!currentToolNames.includes('archival_memory_search')) {
62 console.log('\n=== ATTACHING archival_memory_search ===');
63 try {
64 await client.agents.tools.attach(sleeptimeAgentId, archivalSearchTool.id);
65 console.log('✓ Successfully attached archival_memory_search');
66 } catch (err) {
67 console.error('✗ Failed to attach archival_memory_search:', err.message);
68 if (err.body) console.error('Error details:', JSON.stringify(err.body, null, 2));
69 }
70 } else {
71 console.log('\n✓ archival_memory_search already attached');
72 }
73
74 // Attach archival_memory_insert if not present
75 if (!currentToolNames.includes('archival_memory_insert')) {
76 console.log('\n=== ATTACHING archival_memory_insert ===');
77 try {
78 await client.agents.tools.attach(sleeptimeAgentId, archivalInsertTool.id);
79 console.log('✓ Successfully attached archival_memory_insert');
80 } catch (err) {
81 console.error('✗ Failed to attach archival_memory_insert:', err.message);
82 if (err.body) console.error('Error details:', JSON.stringify(err.body, null, 2));
83 }
84 } else {
85 console.log('\n✓ archival_memory_insert already attached');
86 }
87
88 // Verify final state
89 console.log('\n=== FINAL VERIFICATION ===');
90 const updatedAgent = await client.agents.retrieve(sleeptimeAgentId);
91 const finalToolNames = updatedAgent.tools?.map(t => t.name) || [];
92 console.log('Sleeptime agent tools:', finalToolNames.join(', '));
93
94 const hasArchivalSearch = finalToolNames.includes('archival_memory_search');
95 const hasArchivalInsert = finalToolNames.includes('archival_memory_insert');
96 console.log('\narchival_memory_search:', hasArchivalSearch ? '✓' : '✗');
97 console.log('archival_memory_insert:', hasArchivalInsert ? '✓' : '✗');
98
99 } catch (e) {
100 console.error('Error:', e.message);
101 if (e.body) {
102 console.error('Error body:', JSON.stringify(e.body, null, 2));
103 }
104 if (e.stack) {
105 console.error('Stack:', e.stack);
106 }
107 }
108})();