a tool to help your Letta AI agents navigate bluesky

mroe cleanup of formatting console logs when messaging agents.

Changed files
+33 -8
utils
+33 -8
utils/messageAgent.ts
··· 1 1 import { LettaClient } from "@letta-ai/letta-client"; 2 2 import { session } from "./session.ts"; 3 3 4 + // Helper function to format tool arguments as inline key-value pairs 5 + const formatArgsInline = (args: unknown): string => { 6 + try { 7 + const parsed = typeof args === "string" ? JSON.parse(args) : args; 8 + if (typeof parsed !== "object" || parsed === null) { 9 + return String(parsed); 10 + } 11 + return Object.entries(parsed) 12 + .map(([key, value]) => { 13 + const valueStr = typeof value === "object" 14 + ? JSON.stringify(value) 15 + : String(value); 16 + return `${key}=${valueStr}`; 17 + }) 18 + .join(", "); 19 + } catch { 20 + return String(args); 21 + } 22 + }; 23 + 24 + // Helper function to truncate long strings to 500 characters 25 + const truncateString = (str: string, maxLength = 500): string => { 26 + if (str.length <= maxLength) { 27 + return str; 28 + } 29 + return `${str.slice(0, maxLength)}... (truncated, ${str.length} total chars)`; 30 + }; 31 + 4 32 export const client = new LettaClient({ 5 33 token: Deno.env.get("LETTA_API_KEY"), 6 34 project: Deno.env.get("LETTA_PROJECT_NAME"), ··· 31 59 } else if (response.messageType === "assistant_message") { 32 60 console.log(`๐Ÿ’ฌ ${session.agentName}: ${response.content}`); 33 61 } else if (response.messageType === "tool_call_message") { 34 - const args = response.toolCall.arguments; 35 - const formattedArgs = typeof args === "string" 36 - ? JSON.stringify(JSON.parse(args), null, 2) 37 - : JSON.stringify(args, null, 2); 62 + const formattedArgs = formatArgsInline(response.toolCall.arguments); 38 63 console.log( 39 - `๐Ÿ—œ๏ธ tool called: ${response.toolCall.name} with args:\n${formattedArgs}`, 64 + `๐Ÿ—œ๏ธ tool called: ${response.toolCall.name} with args: ${formattedArgs}`, 40 65 ); 41 66 } else if (response.messageType === "tool_return_message") { 42 67 const toolReturn = response.toolReturn; 43 - const formattedReturn = typeof toolReturn === "string" 68 + const returnStr = typeof toolReturn === "string" 44 69 ? toolReturn 45 - : JSON.stringify(toolReturn, null, 2); 46 - console.log(`๐Ÿ”ง tool response:\n${formattedReturn}`); 70 + : JSON.stringify(toolReturn); 71 + console.log(`๐Ÿ”ง tool response: ${truncateString(returnStr)}`); 47 72 } else if (response.messageType === "usage_statistics") { 48 73 console.log(`๐Ÿ”ข total steps: ${response.stepCount}`); 49 74 } else if (response.messageType === "hidden_reasoning_message") {