Skip to content

Commit

Permalink
revert agent
Browse files Browse the repository at this point in the history
  • Loading branch information
enyst committed Nov 20, 2024
1 parent 6039734 commit e548e66
Showing 1 changed file with 15 additions and 33 deletions.
48 changes: 15 additions & 33 deletions openhands/agenthub/codeact_agent/codeact_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
ImageContent,
Message,
TextContent,
ToolCallContent,
ToolResponseContent,
)
from openhands.events.action import (
Expand Down Expand Up @@ -149,7 +148,6 @@ def get_action_message(
rather than being returned immediately. They will be processed later when all corresponding
tool call results are available.
"""
# create a regular message from an event
if isinstance(
action,
(
Expand All @@ -167,33 +165,17 @@ def get_action_message(
llm_response: ModelResponse = tool_metadata.model_response
assistant_msg = llm_response.choices[0].message

# Create content list with text if present
content = [TextContent(text=assistant_msg.content or '')] if assistant_msg.content else []

if self.llm.is_function_calling_active():
# Native function calling - use message-level tool_calls
pending_tool_call_action_messages[llm_response.id] = Message(
role=assistant_msg.role,
content=content,
tool_calls=assistant_msg.tool_calls,
function_calling_enabled=True
)
else:
# Non-native function calling - use ToolCallContent
if assistant_msg.tool_calls:
for tool_call in assistant_msg.tool_calls:
content.append(
ToolCallContent(
function_name=tool_call.function.name,
function_arguments=tool_call.function.arguments,
tool_call_id=tool_call.id
)
)
pending_tool_call_action_messages[llm_response.id] = Message(
role=assistant_msg.role,
content=content,
function_calling_enabled=False
)
# Add the LLM message (assistant) that initiated the tool calls
# (overwrites any previous message with the same response_id)
pending_tool_call_action_messages[llm_response.id] = Message(
role=assistant_msg.role,
# tool call content SHOULD BE a string
content=[TextContent(text=assistant_msg.content or '')]
if assistant_msg.content is not None
else [],
tool_calls=assistant_msg.tool_calls,
function_calling_enabled=self.llm.is_function_calling_active(),
)
return []
elif isinstance(action, MessageAction):
role = 'user' if action.source == 'user' else 'assistant'
Expand Down Expand Up @@ -306,15 +288,15 @@ def get_observation_message(
# Update the message as tool response properly
if (tool_call_metadata := obs.tool_call_metadata) is not None:
content_text = message.content[0].text if message.content else ''

if self.llm.is_function_calling_active():
# Native function calling - use message-level fields
tool_call_id_to_message[tool_call_metadata.tool_call_id] = Message(
role='tool',
content=[TextContent(text=content_text)],
tool_call_id=tool_call_metadata.tool_call_id,
name=tool_call_metadata.function_name,
function_calling_enabled=True
function_calling_enabled=True,
)
else:
# Non-native function calling - use ToolResponseContent
Expand All @@ -324,10 +306,10 @@ def get_observation_message(
ToolResponseContent(
tool_call_id=tool_call_metadata.tool_call_id,
name=tool_call_metadata.function_name,
content=content_text
content=content_text,
)
],
function_calling_enabled=False
function_calling_enabled=False,
)
return []

Expand Down

0 comments on commit e548e66

Please sign in to comment.