Skip to content

Commit

Permalink
fix dummy agent
Browse files Browse the repository at this point in the history
  • Loading branch information
rbren committed Jan 1, 2025
1 parent 1afc867 commit 9f4771a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
44 changes: 14 additions & 30 deletions openhands/agenthub/dummy_agent/agent.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,6 +17,7 @@
)
from openhands.events.observation import (
AgentStateChangedObservation,
BrowserOutputObservation,
CmdOutputObservation,
FileReadObservation,
FileWriteObservation,
Expand Down Expand Up @@ -89,15 +90,25 @@ def __init__(self, llm: LLM, config: AgentConfig):
{
'action': BrowseURLAction(url='https://google.com'),
'observations': [
# BrowserOutputObservation('<html><body>Simulated Google page</body></html>',url='https://google.com',screenshot=''),
BrowserOutputObservation(
'<html><body>Simulated Google page</body></html>',
url='https://google.com',
screenshot='',
trigger_by_action='',
),
],
},
{
'action': BrowseInteractiveAction(
browser_actions='goto("https://google.com")'
),
'observations': [
# BrowserOutputObservation('<html><body>Simulated Google page after interaction</body></html>',url='https://google.com',screenshot=''),
BrowserOutputObservation(
'<html><body>Simulated Google page after interaction</body></html>',
url='https://google.com',
screenshot='',
trigger_by_action='',
),
],
},
{
Expand All @@ -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]

Expand Down Expand Up @@ -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)
3 changes: 3 additions & 0 deletions openhands/controller/agent_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 9f4771a

Please sign in to comment.