From 7f7282c78d19d67bbc0114f8fdc0fcb2d9ab0677 Mon Sep 17 00:00:00 2001 From: teknium1 Date: Thu, 12 Mar 2026 17:35:01 -0700 Subject: [PATCH] fix(anthropic): guard memory flush tool_calls extraction for Anthropic response format The memory flush path extracted tool_calls from the response assuming OpenAI format (response.choices[0].message.tool_calls). When using the Anthropic client directly (aux unavailable), the response is an Anthropic Message object which has no .choices attribute. Now uses normalize_anthropic_response() to extract tool_calls correctly. --- run_agent.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/run_agent.py b/run_agent.py index afce4e92..3e0d9537 100644 --- a/run_agent.py +++ b/run_agent.py @@ -2692,12 +2692,17 @@ class AIAgent: } response = self.client.chat.completions.create(**api_kwargs, timeout=30.0) - # Extract tool calls from the response, handling both API formats + # Extract tool calls from the response, handling all API formats tool_calls = [] if self.api_mode == "codex_responses" and not _aux_available: assistant_msg, _ = self._normalize_codex_response(response) if assistant_msg and assistant_msg.tool_calls: tool_calls = assistant_msg.tool_calls + elif self.api_mode == "anthropic_messages" and not _aux_available: + from agent.anthropic_adapter import normalize_anthropic_response as _nar_flush + _flush_msg, _ = _nar_flush(response) + if _flush_msg and _flush_msg.tool_calls: + tool_calls = _flush_msg.tool_calls elif hasattr(response, "choices") and response.choices: assistant_message = response.choices[0].message if assistant_message.tool_calls: