Skip to content

Commit

Permalink
Fix issue #5154: [Bug]: FinishTool doesn't have a tool response so th…
Browse files Browse the repository at this point in the history
…e agent loses its content
  • Loading branch information
openhands-agent authored and enyst committed Nov 25, 2024
1 parent b5f542c commit 3e83fd2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion openhands/agenthub/codeact_agent/codeact_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 3e83fd2

Please sign in to comment.