From 9f4771ae495f518f38a2c558ad51df9a3f9e4597 Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Wed, 1 Jan 2025 16:59:46 -0500 Subject: [PATCH] fix dummy agent --- openhands/agenthub/dummy_agent/agent.py | 44 ++++++++---------------- openhands/controller/agent_controller.py | 3 ++ 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/openhands/agenthub/dummy_agent/agent.py b/openhands/agenthub/dummy_agent/agent.py index 9a17856545c0..06abacab3eb7 100644 --- a/openhands/agenthub/dummy_agent/agent.py +++ b/openhands/agenthub/dummy_agent/agent.py @@ -1,4 +1,4 @@ -from typing import TypedDict, Union +from typing import TypedDict from openhands.controller.agent import Agent from openhands.controller.state.state import State @@ -17,6 +17,7 @@ ) from openhands.events.observation import ( AgentStateChangedObservation, + BrowserOutputObservation, CmdOutputObservation, FileReadObservation, FileWriteObservation, @@ -89,7 +90,12 @@ def __init__(self, llm: LLM, config: AgentConfig): { 'action': BrowseURLAction(url='https://google.com'), 'observations': [ - # BrowserOutputObservation('Simulated Google page',url='https://google.com',screenshot=''), + BrowserOutputObservation( + 'Simulated Google page', + url='https://google.com', + screenshot='', + trigger_by_action='', + ), ], }, { @@ -97,7 +103,12 @@ def __init__(self, llm: LLM, config: AgentConfig): browser_actions='goto("https://google.com")' ), 'observations': [ - # BrowserOutputObservation('Simulated Google page after interaction',url='https://google.com',screenshot=''), + BrowserOutputObservation( + 'Simulated Google page after interaction', + url='https://google.com', + screenshot='', + trigger_by_action='', + ), ], }, { @@ -119,14 +130,6 @@ def step(self, state: State) -> Action: current_step = self.steps[state.iteration] action = current_step['action'] - if isinstance(action, (BrowseURLAction, BrowseInteractiveAction)): - try: - return self.simulate_browser_action(action) - except ( - Exception - ): # This could be a specific exception for browser unavailability - return self.handle_browser_unavailable(action) - if state.iteration > 0: prev_step = self.steps[state.iteration - 1] @@ -158,22 +161,3 @@ def step(self, state: State) -> Action: ) return action - - def simulate_browser_action( - self, action: Union[BrowseURLAction, BrowseInteractiveAction] - ) -> Action: - # Instead of simulating, we'll reject the browser action - return self.handle_browser_unavailable(action) - - def handle_browser_unavailable( - self, action: Union[BrowseURLAction, BrowseInteractiveAction] - ) -> Action: - # Create a message action to inform that browsing is not available - message = 'Browser actions are not available in the DummyAgent environment.' - if isinstance(action, BrowseURLAction): - message += f' Unable to browse URL: {action.url}' - elif isinstance(action, BrowseInteractiveAction): - message += ( - f' Unable to perform interactive browsing: {action.browser_actions}' - ) - return MessageAction(content=message) diff --git a/openhands/controller/agent_controller.py b/openhands/controller/agent_controller.py index e6dd3336c88f..10d058c934ee 100644 --- a/openhands/controller/agent_controller.py +++ b/openhands/controller/agent_controller.py @@ -211,6 +211,7 @@ async def _step_with_exception_handling(self): await self._react_to_exception(reported) def should_step(self, event: Event) -> bool: + print('should step?', event) if isinstance(event, Action): if isinstance(event, MessageAction) and event.source == EventSource.USER: return True @@ -535,7 +536,9 @@ async def _step(self) -> None: self.update_state_before_step() action: Action = NullAction() try: + print('STEP AGENT') action = self.agent.step(self.state) + print('GOT ACTION', action) if action is None: raise LLMNoActionError('No action was returned') except (