From 54422b5181c32baa7227f5ec3edffed4bbe37028 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 00:10:00 +0000 Subject: [PATCH] Final refinements: fix falsy value handling and add warning for extra ToolMessages Co-authored-by: jxxghp <51039935+jxxghp@users.noreply.github.com> --- app/agent/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/agent/__init__.py b/app/agent/__init__.py index 2144d2c8..7c1f31f2 100644 --- a/app/agent/__init__.py +++ b/app/agent/__init__.py @@ -219,7 +219,10 @@ class MoviePilotAgent: # Check if this is an AIMessage with tool_calls if isinstance(msg, AIMessage) and getattr(msg, 'tool_calls', None): # Extract tool_call IDs (ToolCall is a TypedDict, so it's a dict at runtime) - tool_call_ids = {tc.get('id') or tc.get('name') for tc in msg.tool_calls} + tool_call_ids = { + tc.get('id') if tc.get('id') is not None else tc.get('name') + for tc in msg.tool_calls + } # Find subsequent ToolMessages j = i + 1 @@ -231,6 +234,11 @@ class MoviePilotAgent: # Check if all tool_calls have corresponding ToolMessages found_tool_call_ids = {tm.tool_call_id for tm in found_tool_messages} + # Warn if there are extra ToolMessages that don't correspond to any tool_call + extra_tool_messages = found_tool_call_ids - tool_call_ids + if extra_tool_messages: + logger.warning(f"Found extra ToolMessages that don't correspond to any tool_call: {extra_tool_messages}") + if not tool_call_ids.issubset(found_tool_call_ids): # Missing some tool_call responses, skip this AIMessage and all its ToolMessages logger.warning("Removing incomplete tool_call AIMessage and its partial ToolMessages: missing tool_call responses")