Rebase onto upstream (a4d95fd)
#12
+36
-1
@@ -636,8 +636,43 @@ class AgentLoop:
|
||||
args_str = json.dumps(tool_call.arguments, ensure_ascii=False)
|
||||
logger.info(f"Tool call: {tool_call.name}({args_str[:200]})")
|
||||
result = await self.tools.execute(tool_call.name, tool_call.arguments)
|
||||
|
||||
# Handle different result types (same logic as main handler)
|
||||
if isinstance(result, ToolResult):
|
||||
# Native Anthropic tool result
|
||||
# Add text content
|
||||
if result.output:
|
||||
text_content = result.output
|
||||
elif result.error:
|
||||
text_content = f"Error: {result.error}"
|
||||
else:
|
||||
text_content = ""
|
||||
|
||||
# If both output and error, combine them
|
||||
if result.output and result.error:
|
||||
text_content = f"{result.output}\n\nError: {result.error}"
|
||||
|
||||
# Note: Image handling for system messages not needed
|
||||
# (system messages don't render images to users)
|
||||
# But we should still log if present
|
||||
if result.base64_image:
|
||||
logger.warning(
|
||||
f"Tool {tool_call.name} returned image in system message context - "
|
||||
"images not supported here"
|
||||
)
|
||||
|
||||
tool_content = text_content
|
||||
|
||||
elif isinstance(result, CLIResult):
|
||||
# CLI-style tool result (text editor)
|
||||
tool_content = result.output
|
||||
|
||||
else:
|
||||
# Legacy string result from function tools
|
||||
tool_content = result
|
||||
|
||||
messages = self.context.add_tool_result(
|
||||
messages, tool_call.id, tool_call.name, result
|
||||
messages, tool_call.id, tool_call.name, tool_content
|
||||
)
|
||||
# Interleaved CoT: reflect before next action (skip when thinking is active)
|
||||
if not getattr(self.provider, 'thinking_budget', 0):
|
||||
|
||||
Reference in New Issue
Block a user