π OpenHands: AI-Driven Development
AgentDelegateAction: make delegate start with the task in execute tags, not the rest of the parent LLM response (#4327)
Engel Nystdf23168c103e
diff --git a/openhands/agenthub/codeact_agent/action_parser.py b/openhands/agenthub/codeact_agent/action_parser.pyindex 4bfdb63ca4..5da42214d5 100644--- a/openhands/agenthub/codeact_agent/action_parser.py+++ b/openhands/agenthub/codeact_agent/action_parser.py@@ -158,8 +158,15 @@ class CodeActActionParserAgentDelegate(ActionParser):), 'self.agent_delegate should not be None when parse is called'thought = action_str.replace(self.agent_delegate.group(0), '').strip()browse_actions = self.agent_delegate.group(1).strip()- task = f'{thought}. I should start with: {browse_actions}'- return AgentDelegateAction(agent='BrowsingAgent', inputs={'task': task})+ thought = (+ f'{thought}\nI should start with: {browse_actions}'+ if thought+ else f'I should start with: {browse_actions}'+ )++ return AgentDelegateAction(+ agent='BrowsingAgent', thought=thought, inputs={'task': browse_actions}+ )class CodeActActionParserMessage(ActionParser):diff --git a/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_002.log b/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_002.logindex 4cc768dbd5..0291abdb13 100644--- a/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_002.log+++ b/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_002.log@@ -4,7 +4,7 @@ possible next action to accomplish your goal. Your answer will be interpretedand executed by a program, make sure to follow the formatting instructions.# Goal:-. I should start with: Get the content on "http://localhost:8000"+Get the content on "http://localhost:8000"# Action Spacediff --git a/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_003.log b/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_003.logindex 8f5834d031..2dba622e9d 100644--- a/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_003.log+++ b/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_003.log@@ -4,7 +4,7 @@ possible next action to accomplish your goal. Your answer will be interpretedand executed by a program, make sure to follow the formatting instructions.# Goal:-. I should start with: Get the content on "http://localhost:8000"+Get the content on "http://localhost:8000"# Action Spacediff --git a/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_004.log b/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_004.logindex a2a43cd643..f2ac1671c9 100644--- a/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_004.log+++ b/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_004.log@@ -4,7 +4,7 @@ possible next action to accomplish your goal. Your answer will be interpretedand executed by a program, make sure to follow the formatting instructions.# Goal:-. I should start with: Get the content on "http://localhost:8000"+Get the content on "http://localhost:8000"# Action Spacediff --git a/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_005.log b/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_005.logindex 421930ed6f..5444bc884d 100644--- a/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_005.log+++ b/tests/integration/mock/eventstream_runtime/CodeActAgent/test_browse_internet/prompt_005.log@@ -406,9 +406,9 @@ Browse localhost:8000, and tell me the ultimate answer to life. Do not ask me fo-----------+I should start with: Get the content on "http://localhost:8000"<execute_browse>-. I should start with: Get the content on "http://localhost:8000"+Get the content on "http://localhost:8000"</execute_browse>----------diff --git a/tests/unit/test_codeact_agent_parser.py b/tests/unit/test_codeact_agent_parser.pynew file mode 100644index 0000000000..5984f70b98--- /dev/null+++ b/tests/unit/test_codeact_agent_parser.py@@ -0,0 +1,53 @@+import pytest++from openhands.agenthub.codeact_agent.action_parser import (+ CodeActActionParserAgentDelegate,+)+from openhands.events.action import AgentDelegateAction+++ 'action_str, expected_agent, expected_thought, expected_task',+ [+ (+ 'I need to search for information.\n<execute_browse>Tell me who is the Vice President of the USA</execute_browse>',+ 'BrowsingAgent',+ 'I need to search for information.\nI should start with: Tell me who is the Vice President of the USA',+ 'Tell me who is the Vice President of the USA',+ ),+ (+ '<execute_browse>Search for recent climate change data</execute_browse>',+ 'BrowsingAgent',+ 'I should start with: Search for recent climate change data',+ 'Search for recent climate change data',+ ),+ (+ "Let's use the browsing agent to find this information.\n<execute_browse>Find the population of Tokyo in 2023</execute_browse>\nThis will help us answer the question.",+ 'BrowsingAgent',+ "Let's use the browsing agent to find this information.\n\nThis will help us answer the question.\nI should start with: Find the population of Tokyo in 2023",+ 'Find the population of Tokyo in 2023',+ ),+ ],+)+def test_codeact_action_parser_agent_delegate(+ action_str, expected_agent, expected_thought, expected_task+):+ parser = CodeActActionParserAgentDelegate()+ assert parser.check_condition(action_str)++ action = parser.parse(action_str)++ assert isinstance(action, AgentDelegateAction)+ assert action.agent == expected_agent+ assert action.thought == expected_thought+ assert action.inputs['task'] == expected_task+++def test_codeact_action_parser_agent_delegate_no_match():+ parser = CodeActActionParserAgentDelegate()+ action_str = 'This is a regular message without any browse command.'++ assert not parser.check_condition(action_str)++ with pytest.raises(AssertionError):+ parser.parse(action_str)