a tool to help your Letta AI agents navigate bluesky

Update Letta client imports and method names

Changed files
+20 -16
+20 -16
mount.ts
··· 139 */ 140 export async function mount(): Promise<void> { 141 const agentId = Deno.env.get("LETTA_AGENT_ID"); 142 - const agentName = Deno.env.get("LETTA_PROJECT_NAME"); 143 144 if (!agentId) { 145 console.error( ··· 156 console.log(`Agent retrieved: ${agent.name}`); 157 158 // Get all existing blocks for this agent 159 - const existingBlocks = await client.agents.blocks.list(agentId); 160 console.log(`Agent has ${existingBlocks.length} existing memory blocks`); 161 162 // Build dynamic memory blocks array based on configuration ··· 216 ); 217 } else { 218 console.log(`Updating existing block: ${blockConfig.label}`); 219 - await client.blocks.modify(existingBlock.id, { 220 value: blockConfig.value, 221 description: blockConfig.description, 222 limit: blockConfig.limit, ··· 236 237 // Attach the block to the agent 238 if (newBlock.id) { 239 - await client.agents.blocks.attach(agentId, newBlock.id); 240 console.log(`✓ Attached block: ${blockConfig.label}`); 241 } else { 242 throw new Error(`Failed to create block: ${blockConfig.label}`); ··· 259 } 260 261 // Update agent with tool environment variables 262 - await client.agents.modify(agentId, { 263 - toolExecEnvironmentVariables: { 264 BSKY_USERNAME: bskyUsername || "", 265 BSKY_APP_PASSWORD: bskyAppPassword || "", 266 BSKY_SERVICE_URL: bskyServiceUrl || "https://bsky.social", ··· 286 } 287 288 // Get currently attached tools 289 - const attachedTools = await client.agents.tools.list(agentId); 290 const attachedToolNames = attachedTools.map((tool: any) => tool.name); 291 console.log(`Agent has ${attachedTools.length} tools currently attached`); 292 ··· 296 297 // Create a user-level client for tool operations 298 // Tools are user-level resources, not project-scoped 299 - const { LettaClient } = await import("@letta-ai/letta-client"); 300 - const userLevelClient = new LettaClient({ 301 - token: Deno.env.get("LETTA_API_KEY"), 302 }); 303 304 // First, process hardcoded required tools ··· 311 } 312 313 // Search for the tool in the global registry 314 - const existingTools = await userLevelClient.tools.list({ 315 name: toolName, 316 }); 317 318 if (existingTools.length > 0) { 319 const tool = existingTools[0]; 320 if (tool.id) { 321 - await client.agents.tools.attach(agentId, tool.id); 322 console.log(`✓ Attached required tool: ${toolName}`); 323 toolsAttached++; 324 } ··· 359 try { 360 // Attempt to create the tool - Letta will extract the function name from docstring 361 const createParams: any = { 362 - sourceCode: toolSource, 363 }; 364 365 // Add pip requirements if any were detected 366 if (pipRequirements.length > 0) { 367 - createParams.pipRequirements = pipRequirements; 368 } 369 370 tool = await userLevelClient.tools.create(createParams); ··· 384 const funcMatch = toolSource.match(/^def\s+(\w+)\s*\(/m); 385 if (funcMatch) { 386 const functionName = funcMatch[1]; 387 - const existingTools = await userLevelClient.tools.list({ 388 name: functionName, 389 }); 390 if (existingTools.length > 0) { 391 tool = existingTools[0]; 392 } ··· 409 410 // Attach the tool to the agent 411 if (tool.id) { 412 - await client.agents.tools.attach(agentId, tool.id); 413 if (wasCreated) { 414 console.log( 415 `✓ Created and attached tool: ${toolName} (from ${toolFileName}.py)`,
··· 139 */ 140 export async function mount(): Promise<void> { 141 const agentId = Deno.env.get("LETTA_AGENT_ID"); 142 + const agentName = Deno.env.get("LETTA_PROJECT_ID"); 143 144 if (!agentId) { 145 console.error( ··· 156 console.log(`Agent retrieved: ${agent.name}`); 157 158 // Get all existing blocks for this agent 159 + const existingBlocksPage = await client.agents.blocks.list(agentId); 160 + const existingBlocks = existingBlocksPage.items; 161 console.log(`Agent has ${existingBlocks.length} existing memory blocks`); 162 163 // Build dynamic memory blocks array based on configuration ··· 217 ); 218 } else { 219 console.log(`Updating existing block: ${blockConfig.label}`); 220 + await client.blocks.update(existingBlock.id, { 221 value: blockConfig.value, 222 description: blockConfig.description, 223 limit: blockConfig.limit, ··· 237 238 // Attach the block to the agent 239 if (newBlock.id) { 240 + await client.agents.blocks.attach(newBlock.id, { agent_id: agentId }); 241 console.log(`✓ Attached block: ${blockConfig.label}`); 242 } else { 243 throw new Error(`Failed to create block: ${blockConfig.label}`); ··· 260 } 261 262 // Update agent with tool environment variables 263 + await client.agents.update(agentId, { 264 + secrets: { 265 BSKY_USERNAME: bskyUsername || "", 266 BSKY_APP_PASSWORD: bskyAppPassword || "", 267 BSKY_SERVICE_URL: bskyServiceUrl || "https://bsky.social", ··· 287 } 288 289 // Get currently attached tools 290 + const attachedToolsPage = await client.agents.tools.list(agentId); 291 + const attachedTools = attachedToolsPage.items; 292 const attachedToolNames = attachedTools.map((tool: any) => tool.name); 293 console.log(`Agent has ${attachedTools.length} tools currently attached`); 294 ··· 298 299 // Create a user-level client for tool operations 300 // Tools are user-level resources, not project-scoped 301 + const { default: Letta } = await import("@letta-ai/letta-client"); 302 + const userLevelClient = new Letta({ 303 + apiKey: Deno.env.get("LETTA_API_KEY"), 304 }); 305 306 // First, process hardcoded required tools ··· 313 } 314 315 // Search for the tool in the global registry 316 + const existingToolsPage = await userLevelClient.tools.list({ 317 name: toolName, 318 }); 319 + const existingTools = existingToolsPage.items; 320 321 if (existingTools.length > 0) { 322 const tool = existingTools[0]; 323 if (tool.id) { 324 + await client.agents.tools.attach(tool.id, { agent_id: agentId }); 325 console.log(`✓ Attached required tool: ${toolName}`); 326 toolsAttached++; 327 } ··· 362 try { 363 // Attempt to create the tool - Letta will extract the function name from docstring 364 const createParams: any = { 365 + source_code: toolSource, 366 }; 367 368 // Add pip requirements if any were detected 369 if (pipRequirements.length > 0) { 370 + createParams.pip_requirements = pipRequirements; 371 } 372 373 tool = await userLevelClient.tools.create(createParams); ··· 387 const funcMatch = toolSource.match(/^def\s+(\w+)\s*\(/m); 388 if (funcMatch) { 389 const functionName = funcMatch[1]; 390 + const existingToolsPage = await userLevelClient.tools.list({ 391 name: functionName, 392 }); 393 + const existingTools = existingToolsPage.items; 394 if (existingTools.length > 0) { 395 tool = existingTools[0]; 396 } ··· 413 414 // Attach the tool to the agent 415 if (tool.id) { 416 + await client.agents.tools.attach(tool.id, { agent_id: agentId }); 417 if (wasCreated) { 418 console.log( 419 `✓ Created and attached tool: ${toolName} (from ${toolFileName}.py)`,