test_codeact_agent_parser.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import pytest
  2. from openhands.agenthub.codeact_agent.action_parser import (
  3. CodeActActionParserAgentDelegate,
  4. )
  5. from openhands.events.action import AgentDelegateAction
  6. @pytest.mark.parametrize(
  7. 'action_str, expected_agent, expected_thought, expected_task',
  8. [
  9. (
  10. 'I need to search for information.\n<execute_browse>Tell me who is the Vice President of the USA</execute_browse>',
  11. 'BrowsingAgent',
  12. 'I need to search for information.\nI should start with: Tell me who is the Vice President of the USA',
  13. 'Tell me who is the Vice President of the USA',
  14. ),
  15. (
  16. '<execute_browse>Search for recent climate change data</execute_browse>',
  17. 'BrowsingAgent',
  18. 'I should start with: Search for recent climate change data',
  19. 'Search for recent climate change data',
  20. ),
  21. (
  22. "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.",
  23. 'BrowsingAgent',
  24. "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",
  25. 'Find the population of Tokyo in 2023',
  26. ),
  27. ],
  28. )
  29. def test_codeact_action_parser_agent_delegate(
  30. action_str, expected_agent, expected_thought, expected_task
  31. ):
  32. parser = CodeActActionParserAgentDelegate()
  33. assert parser.check_condition(action_str)
  34. action = parser.parse(action_str)
  35. assert isinstance(action, AgentDelegateAction)
  36. assert action.agent == expected_agent
  37. assert action.thought == expected_thought
  38. assert action.inputs['task'] == expected_task
  39. def test_codeact_action_parser_agent_delegate_no_match():
  40. parser = CodeActActionParserAgentDelegate()
  41. action_str = 'This is a regular message without any browse command.'
  42. assert not parser.check_condition(action_str)
  43. with pytest.raises(AssertionError):
  44. parser.parse(action_str)