🙌 OpenHands: AI-Driven Development
Frontend support for delegation and rejection (#2608)
Boxuan Liee86d8d25e01
diff --git a/frontend/src/components/AgentControlBar.tsx b/frontend/src/components/AgentControlBar.tsxindex be2e2563cd..e33dd8d9e2 100644--- a/frontend/src/components/AgentControlBar.tsx+++ b/frontend/src/components/AgentControlBar.tsx@@ -15,6 +15,7 @@ const IgnoreTaskStateMap: { [k: string]: AgentState[] } = {AgentState.PAUSED,AgentState.STOPPED,AgentState.FINISHED,+ AgentState.REJECTED,AgentState.AWAITING_USER_INPUT,],[AgentState.RUNNING]: [@@ -22,6 +23,7 @@ const IgnoreTaskStateMap: { [k: string]: AgentState[] } = {AgentState.RUNNING,AgentState.STOPPED,AgentState.FINISHED,+ AgentState.REJECTED,AgentState.AWAITING_USER_INPUT,],[AgentState.STOPPED]: [AgentState.INIT, AgentState.STOPPED],diff --git a/frontend/src/components/AgentStatusBar.tsx b/frontend/src/components/AgentStatusBar.tsxindex 2509c4b488..aa46474bae 100644--- a/frontend/src/components/AgentStatusBar.tsx+++ b/frontend/src/components/AgentStatusBar.tsx@@ -49,6 +49,10 @@ function AgentStatusBar() {message: t(I18nKey.CHAT_INTERFACE$AGENT_FINISHED_MESSAGE),indicator: IndicatorColor.GREEN,},+ [AgentState.REJECTED]: {+ message: t(I18nKey.CHAT_INTERFACE$AGENT_REJECTED_MESSAGE),+ indicator: IndicatorColor.YELLOW,+ },[AgentState.ERROR]: {message: t(I18nKey.CHAT_INTERFACE$AGENT_ERROR_MESSAGE),indicator: IndicatorColor.RED,diff --git a/frontend/src/i18n/translation.json b/frontend/src/i18n/translation.jsonindex 2cee273df6..9e0d4c407a 100644--- a/frontend/src/i18n/translation.json+++ b/frontend/src/i18n/translation.json@@ -397,6 +397,11 @@"de": "Agent hat die Aufgabe erledigt.","zh-CN": "智能体已完成任务"},+ "CHAT_INTERFACE$AGENT_REJECTED_MESSAGE": {+ "en": "Agent has rejected the task.",+ "de": "Agent hat die Aufgabe abgelehnt.",+ "zh-CN": "智能体拒绝任务"+ },"CHAT_INTERFACE$AGENT_ERROR_MESSAGE": {"en": "Agent encountered an error.","de": "Agent ist auf einen Fehler gelaufen.",diff --git a/frontend/src/services/actions.ts b/frontend/src/services/actions.tsindex 724ede66e0..64c4245729 100644--- a/frontend/src/services/actions.ts+++ b/frontend/src/services/actions.ts@@ -36,6 +36,12 @@ const messageActions = {[ActionType.FINISH]: (message: ActionMessage) => {store.dispatch(addAssistantMessage(message.message));},+ [ActionType.REJECT]: (message: ActionMessage) => {+ store.dispatch(addAssistantMessage(message.message));+ },+ [ActionType.DELEGATE]: (message: ActionMessage) => {+ store.dispatch(addAssistantMessage(message.message));+ },[ActionType.RUN]: (message: ActionMessage) => {if (message.args.thought) {store.dispatch(addAssistantMessage(message.args.thought));diff --git a/frontend/src/services/observations.ts b/frontend/src/services/observations.tsindex 6677d0a236..9228f8a72c 100644--- a/frontend/src/services/observations.ts+++ b/frontend/src/services/observations.ts@@ -27,6 +27,12 @@ export function handleObservationMessage(message: ObservationMessage) {case ObservationType.AGENT_STATE_CHANGED:store.dispatch(changeAgentState(message.extras.agent_state));break;+ case ObservationType.DELEGATE:+ // TODO: better UI for delegation result (#2309)+ if (message.content) {+ store.dispatch(addAssistantMessage(message.content));+ }+ break;default:store.dispatch(addAssistantMessage(message.message));break;diff --git a/frontend/src/types/ActionType.tsx b/frontend/src/types/ActionType.tsxindex 37bd5b4d9d..89e5317f7c 100644--- a/frontend/src/types/ActionType.tsx+++ b/frontend/src/types/ActionType.tsx@@ -26,6 +26,9 @@ enum ActionType {// Interact with the browser instance.BROWSE_INTERACTIVE = "browse_interactive",+ // Delegate a (sub)task to another agent.+ DELEGATE = "delegate",+// Searches long-term memory.RECALL = "recall",@@ -33,6 +36,9 @@ enum ActionType {// use the finish action to stop working.FINISH = "finish",+ // Reject a request from user or another agent.+ REJECT = "reject",+// Adds a task to the plan.ADD_TASK = "add_task",diff --git a/frontend/src/types/AgentState.tsx b/frontend/src/types/AgentState.tsxindex ef5fe0116c..61db70d53a 100644--- a/frontend/src/types/AgentState.tsx+++ b/frontend/src/types/AgentState.tsx@@ -6,6 +6,7 @@ enum AgentState {PAUSED = "paused",STOPPED = "stopped",FINISHED = "finished",+ REJECTED = "rejected",ERROR = "error",}diff --git a/frontend/src/types/ObservationType.tsx b/frontend/src/types/ObservationType.tsxindex 122df3797d..ddc6a0d83b 100644--- a/frontend/src/types/ObservationType.tsx+++ b/frontend/src/types/ObservationType.tsx@@ -19,6 +19,9 @@ enum ObservationType {// Agent state has changedAGENT_STATE_CHANGED = "agent_state_changed",++ // Delegate result+ DELEGATE = "delegate",}export default ObservationType;diff --git a/opendevin/controller/agent_controller.py b/opendevin/controller/agent_controller.pyindex 9574c6d72a..977f647052 100644--- a/opendevin/controller/agent_controller.py+++ b/opendevin/controller/agent_controller.py@@ -284,7 +284,14 @@ class AgentController:self.delegateAction = None# update delegate result observation- obs: Observation = AgentDelegateObservation(outputs=outputs, content='')+ # TODO: replace this with AI-generated summary (#2395)+ formatted_output = ', '.join(+ f'{key}: {value}' for key, value in outputs.items()+ )+ content = f'Delegate agent finishes task with {formatted_output}'+ obs: Observation = AgentDelegateObservation(+ outputs=outputs, content=content+ )await self.event_stream.add_event(obs, EventSource.AGENT)returndiff --git a/opendevin/events/action/agent.py b/opendevin/events/action/agent.pyindex 7717ac04e4..a60a6a699d 100644--- a/opendevin/events/action/agent.py+++ b/opendevin/events/action/agent.py@@ -65,7 +65,10 @@ class AgentRejectAction(Action):@propertydef message(self) -> str:- return 'Task is rejected by the agent.'+ msg: str = 'Task is rejected by the agent.'+ if 'reason' in self.outputs:+ msg += ' Reason: ' + self.outputs['reason']+ return msg@dataclassdiff --git a/tests/integration/mock/ManagerAgent/test_edits/prompt_006.log b/tests/integration/mock/ManagerAgent/test_edits/prompt_006.logindex 7ede0ca4b6..7ab0d6692b 100644--- a/tests/integration/mock/ManagerAgent/test_edits/prompt_006.log+++ b/tests/integration/mock/ManagerAgent/test_edits/prompt_006.log@@ -70,7 +70,7 @@ as well as observations you've made. This only includes the MOST RECENTactions and observations--more may have happened before that.They are time-ordered, with your most recent action at the bottom.-[[{"source": "user", "action": "message", "args": {"content": "Fix typos in bad.txt. Do not ask me for confirmation at any point.", "wait_for_response": false}}, {"observation": "null", "content": "", "extras": {}}], [{"source": "agent", "action": "delegate", "args": {"agent": "TypoFixerAgent", "inputs": {"task": "Fix typos in bad.txt"}, "thought": ""}}, {"observation": "null", "content": "", "extras": {}}], [{"action": "null", "args": {}}, {"source": "agent", "observation": "delegate", "content": "", "extras": {"outputs": {"summary": {"file": "bad.txt", "typos_fixed": [{"original": "typoo", "corrected": "typo"}, {"original": "mor", "corrected": "more"}]}}}}]]+[[{"source": "user", "action": "message", "args": {"content": "Fix typos in bad.txt. Do not ask me for confirmation at any point.", "wait_for_response": false}}, {"observation": "null", "content": "", "extras": {}}], [{"source": "agent", "action": "delegate", "args": {"agent": "TypoFixerAgent", "inputs": {"task": "Fix typos in bad.txt"}, "thought": ""}}, {"observation": "null", "content": "", "extras": {}}], [{"action": "null", "args": {}}, {"source": "agent", "observation": "delegate", "content": "Delegate agent finishes task with summary: {'file': 'bad.txt', 'typos_fixed': [{'original': 'typoo', 'corrected': 'typo'}, {'original': 'mor', 'corrected': 'more'}]}", "extras": {"outputs": {"summary": {"file": "bad.txt", "typos_fixed": [{"original": "typoo", "corrected": "typo"}, {"original": "mor", "corrected": "more"}]}}}}]]If the last item in the history is an error, you should try to fix it. If youcannot fix it, call the `reject` action.diff --git a/tests/integration/mock/ManagerAgent/test_simple_task_rejection/prompt_006.log b/tests/integration/mock/ManagerAgent/test_simple_task_rejection/prompt_006.logindex 1b619a445b..fff4497b02 100644--- a/tests/integration/mock/ManagerAgent/test_simple_task_rejection/prompt_006.log+++ b/tests/integration/mock/ManagerAgent/test_simple_task_rejection/prompt_006.log@@ -70,7 +70,7 @@ as well as observations you've made. This only includes the MOST RECENTactions and observations--more may have happened before that.They are time-ordered, with your most recent action at the bottom.-[[{"source": "user", "action": "message", "args": {"content": "Write a git commit message for the current staging area. Do not ask me for confirmation at any point.", "wait_for_response": false}}, {"observation": "null", "content": "", "extras": {}}], [{"source": "agent", "action": "delegate", "args": {"agent": "CommitWriterAgent", "inputs": {}, "thought": ""}}, {"observation": "null", "content": "", "extras": {}}], [{"action": "null", "args": {}}, {"source": "agent", "observation": "delegate", "content": "", "extras": {"outputs": {"reason": "Not a valid git repository."}}}]]+[[{"source": "user", "action": "message", "args": {"content": "Write a git commit message for the current staging area. Do not ask me for confirmation at any point.", "wait_for_response": false}}, {"observation": "null", "content": "", "extras": {}}], [{"source": "agent", "action": "delegate", "args": {"agent": "CommitWriterAgent", "inputs": {}, "thought": ""}}, {"observation": "null", "content": "", "extras": {}}], [{"action": "null", "args": {}}, {"source": "agent", "observation": "delegate", "content": "Delegate agent finishes task with reason: Not a valid git repository.", "extras": {"outputs": {"reason": "Not a valid git repository."}}}]]If the last item in the history is an error, you should try to fix it. If youcannot fix it, call the `reject` action.