Skip to content

Commit

Permalink
Remove TaskAction functionality (#5959)
Browse files Browse the repository at this point in the history
Co-authored-by: openhands <[email protected]>
  • Loading branch information
rbren and openhands-agent authored Jan 2, 2025
1 parent 50a0b1d commit f846b31
Show file tree
Hide file tree
Showing 20 changed files with 32 additions and 466 deletions.
6 changes: 0 additions & 6 deletions frontend/src/types/action-type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ enum ActionType {
// Reject a request from user or another agent.
REJECT = "reject",

// Adds a task to the plan.
ADD_TASK = "add_task",

// Updates a task in the plan.
MODIFY_TASK = "modify_task",

// Changes the state of the agent, e.g. to paused or running
CHANGE_AGENT_STATE = "change_agent_state",
}
Expand Down
23 changes: 0 additions & 23 deletions frontend/src/types/core/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,6 @@ export interface BrowseInteractiveAction
};
}

export interface AddTaskAction extends OpenHandsActionEvent<"add_task"> {
source: "agent";
timeout: number;
args: {
parent: string;
goal: string;
subtasks: unknown[];
thought: string;
};
}

export interface ModifyTaskAction extends OpenHandsActionEvent<"modify_task"> {
source: "agent";
timeout: number;
args: {
task_id: string;
state: string;
thought: string;
};
}

export interface FileReadAction extends OpenHandsActionEvent<"read"> {
source: "agent";
args: {
Expand Down Expand Up @@ -144,6 +123,4 @@ export type OpenHandsAction =
| FileReadAction
| FileEditAction
| FileWriteAction
| AddTaskAction
| ModifyTaskAction
| RejectAction;
2 changes: 0 additions & 2 deletions frontend/src/types/core/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export type OpenHandsEventType =
| "browse"
| "browse_interactive"
| "reject"
| "add_task"
| "modify_task"
| "finish"
| "error";

Expand Down
2 changes: 0 additions & 2 deletions openhands/agenthub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
codeact_agent,
delegator_agent,
dummy_agent,
planner_agent,
)

__all__ = [
'codeact_agent',
'planner_agent',
'delegator_agent',
'dummy_agent',
'browsing_agent',
Expand Down
76 changes: 14 additions & 62 deletions openhands/agenthub/dummy_agent/agent.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from typing import TypedDict, Union
from typing import TypedDict

from openhands.controller.agent import Agent
from openhands.controller.state.state import State
from openhands.core.config import AgentConfig
from openhands.core.schema import AgentState
from openhands.events.action import (
Action,
AddTaskAction,
AgentFinishAction,
AgentRejectAction,
BrowseInteractiveAction,
Expand All @@ -15,10 +14,10 @@
FileReadAction,
FileWriteAction,
MessageAction,
ModifyTaskAction,
)
from openhands.events.observation import (
AgentStateChangedObservation,
BrowserOutputObservation,
CmdOutputObservation,
FileReadObservation,
FileWriteObservation,
Expand Down Expand Up @@ -49,20 +48,6 @@ class DummyAgent(Agent):
def __init__(self, llm: LLM, config: AgentConfig):
super().__init__(llm, config)
self.steps: list[ActionObs] = [
{
'action': AddTaskAction(
parent='None', goal='check the current directory'
),
'observations': [],
},
{
'action': AddTaskAction(parent='0', goal='run ls'),
'observations': [],
},
{
'action': ModifyTaskAction(task_id='0', state='in_progress'),
'observations': [],
},
{
'action': MessageAction('Time to get started!'),
'observations': [],
Expand Down Expand Up @@ -105,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 @@ -135,30 +130,6 @@ def step(self, state: State) -> Action:
current_step = self.steps[state.iteration]
action = current_step['action']

# If the action is AddTaskAction or ModifyTaskAction, update the parent ID or task_id
if isinstance(action, AddTaskAction):
if action.parent == 'None':
action.parent = '' # Root task has no parent
elif action.parent == '0':
action.parent = state.root_task.id
elif action.parent.startswith('0.'):
action.parent = f'{state.root_task.id}{action.parent[1:]}'
elif isinstance(action, ModifyTaskAction):
if action.task_id == '0':
action.task_id = state.root_task.id
elif action.task_id.startswith('0.'):
action.task_id = f'{state.root_task.id}{action.task_id[1:]}'
# Ensure the task_id doesn't start with a dot
if action.task_id.startswith('.'):
action.task_id = action.task_id[1:]
elif 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 @@ -190,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)
4 changes: 0 additions & 4 deletions openhands/agenthub/planner_agent/__init__.py

This file was deleted.

53 changes: 0 additions & 53 deletions openhands/agenthub/planner_agent/agent.py

This file was deleted.

Loading

0 comments on commit f846b31

Please sign in to comment.