this repo has no description
0
fork

Configure Feed

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

feat(logging): add detailed tool call logging

Now shows in console:
- ๐Ÿ“ค Messages sent to agent
- ๐Ÿ“จ Agent response breakdown with message types
- ๐Ÿ”ง TOOL CALL with name and args
- โœ… TOOL RETURN with status and result
- ๐Ÿ’ฌ ASSISTANT messages
- ๐Ÿง  REASONING messages
- ๐Ÿ”ง TOOL WEBHOOK when our handlers receive calls

Makes debugging tool calls much easier.

๐Ÿค– Generated with [Claude Code](https://claude.com/claude-code)

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

alice fb24d9c4 6f77c284

+43 -5
+37
src/bot.ts
··· 136 136 const client = getLettaClient(); 137 137 138 138 try { 139 + const msgPreview = message.slice(0, 100) + (message.length > 100 ? '...' : ''); 140 + console.log(`\n๐Ÿ“ค Sending message to agent ${agentId}: "${msgPreview}"`); 141 + 139 142 // Send message to agent (non-streaming mode for simplicity in M1) 140 143 const response = await client.agents.messages.create(agentId, { 141 144 input: message, 142 145 streaming: false, 143 146 }); 147 + 148 + // Log all messages in the response for debugging 149 + console.log(`๐Ÿ“จ Agent response contains ${String(response.messages.length)} messages:`); 150 + for (const msg of response.messages) { 151 + const msgType = msg.message_type; 152 + if (msgType === 'tool_call_message') { 153 + // Tool call - show tool name and args 154 + const toolMsg = msg as { tool_call?: { name?: string; arguments?: string } }; 155 + const toolName = toolMsg.tool_call?.name ?? 'unknown'; 156 + const toolArgs = toolMsg.tool_call?.arguments ?? '{}'; 157 + console.log(` ๐Ÿ”ง TOOL CALL: ${toolName}(${toolArgs})`); 158 + } else if (msgType === 'tool_return_message') { 159 + // Tool return - show result 160 + const returnMsg = msg as { tool_return?: string; status?: string }; 161 + const status = returnMsg.status ?? 'unknown'; 162 + const result = returnMsg.tool_return ?? ''; 163 + const truncated = result.length > 200 ? result.slice(0, 200) + '...' : result; 164 + console.log(` โœ… TOOL RETURN (${status}): ${truncated}`); 165 + } else if (msgType === 'assistant_message') { 166 + // Assistant message - show content preview 167 + const assistantMsg = msg as { content?: string | unknown[] }; 168 + const content = typeof assistantMsg.content === 'string' ? assistantMsg.content : '[complex content]'; 169 + const truncated = content.length > 100 ? content.slice(0, 100) + '...' : content; 170 + console.log(` ๐Ÿ’ฌ ASSISTANT: ${truncated}`); 171 + } else if (msgType === 'reasoning_message') { 172 + // Reasoning/thinking 173 + const reasoningMsg = msg as { reasoning?: string }; 174 + const reasoning = reasoningMsg.reasoning ?? ''; 175 + const truncated = reasoning.length > 100 ? reasoning.slice(0, 100) + '...' : reasoning; 176 + console.log(` ๐Ÿง  REASONING: ${truncated}`); 177 + } else { 178 + console.log(` ๐Ÿ“ ${String(msgType)}`); 179 + } 180 + } 144 181 145 182 // Extract the assistant's response from the messages 146 183 // The response contains an array of messages, we want the assistant's reply
+6 -2
src/index.ts
··· 109 109 const userId = typeof args['user_id'] === 'number' ? args['user_id'] : 0; 110 110 111 111 try { 112 - console.log(`Tool webhook: ${toolName}`, { userId, args }); 112 + console.log(`\n๐Ÿ”ง TOOL WEBHOOK RECEIVED: ${toolName}`); 113 + console.log(` Args: ${JSON.stringify(args)}`); 113 114 const result = await dispatchTool(toolName, args, { userId }); 115 + const resultStr = JSON.stringify(result); 116 + const truncated = resultStr.length > 300 ? resultStr.slice(0, 300) + '...' : resultStr; 117 + console.log(` Result: ${truncated}`); 114 118 return new Response(JSON.stringify(result), { 115 119 status: 200, 116 120 headers: { 'Content-Type': 'application/json' }, 117 121 }); 118 122 } catch (error: unknown) { 119 123 const errorMessage = error instanceof Error ? error.message : 'Unknown error'; 120 - console.error(`Tool webhook error (${toolName}):`, error); 124 + console.error(`โŒ TOOL WEBHOOK ERROR (${toolName}):`, errorMessage); 121 125 return new Response(JSON.stringify({ error: errorMessage }), { 122 126 status: 500, 123 127 headers: { 'Content-Type': 'application/json' },
-3
src/tools/dispatcher.ts
··· 126 126 } 127 127 128 128 try { 129 - console.log(`Dispatching tool: ${name}`, { args, userId: context.userId }); 130 129 const result = await tool.handler(args, context); 131 - console.log(`Tool '${name}' executed successfully`); 132 130 return result; 133 131 } catch (error: unknown) { 134 132 const errorMessage = error instanceof Error ? error.message : 'Unknown error'; 135 - console.error(`Tool '${name}' execution failed:`, error); 136 133 throw new Error(`Failed to execute tool '${name}': ${errorMessage}`); 137 134 } 138 135 }