From 3e83fd2c35a883f9044b69a857ac77c5c70b2298 Mon Sep 17 00:00:00 2001 From: openhands Date: Sun, 24 Nov 2024 04:02:30 +0000 Subject: [PATCH] Fix issue #5154: [Bug]: FinishTool doesn't have a tool response so the agent loses its content --- .../agenthub/codeact_agent/codeact_agent.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/openhands/agenthub/codeact_agent/codeact_agent.py b/openhands/agenthub/codeact_agent/codeact_agent.py index 34794d2ab1bb..87189efe3d45 100644 --- a/openhands/agenthub/codeact_agent/codeact_agent.py +++ b/openhands/agenthub/codeact_agent/codeact_agent.py @@ -157,7 +157,7 @@ def get_action_message( BrowseInteractiveAction, ), ) or ( - isinstance(action, (AgentFinishAction, CmdRunAction)) + isinstance(action, CmdRunAction) and action.source == 'agent' ): tool_metadata = action.tool_call_metadata @@ -198,6 +198,22 @@ def get_action_message( content=content, ) ] + elif isinstance(action, AgentFinishAction) and action.source == 'agent': + # For agent-sourced FinishAction, treat it as a message action + # This way it won't expect a tool response + tool_metadata = action.tool_call_metadata + assert tool_metadata is not None, ( + 'Tool call metadata should NOT be None when function calling is enabled. Action: ' + + str(action) + ) + llm_response: ModelResponse = tool_metadata.model_response + assistant_msg = llm_response.choices[0].message + return [ + Message( + role=assistant_msg.role, + content=[TextContent(text=assistant_msg.content or '')], + ) + ] return [] def get_observation_message(