π OpenHands: AI-Driven Development
Improve action and observation logging for the CLI interface (#2035)
Xingyao Wange731048ccff6
diff --git a/opendevin/controller/agent_controller.py b/opendevin/controller/agent_controller.pyindex 059fe0967a..35a622327f 100644--- a/opendevin/controller/agent_controller.py+++ b/opendevin/controller/agent_controller.py@@ -128,10 +128,12 @@ class AgentController:await self.set_agent_state_to(event.agent_state) # type: ignoreelif isinstance(event, MessageAction):if event.source == EventSource.USER:+ logger.info(event, extra={'msg_type': 'OBSERVATION'})await self.add_history(event, NullObservation(''))if self.get_agent_state() != AgentState.RUNNING:await self.set_agent_state_to(AgentState.RUNNING)elif event.source == EventSource.AGENT and event.wait_for_response:+ logger.info(event, extra={'msg_type': 'ACTION'})await self.set_agent_state_to(AgentState.AWAITING_USER_INPUT)elif isinstance(event, AgentDelegateAction):await self.start_delegate(event)diff --git a/opendevin/events/action/agent.py b/opendevin/events/action/agent.pyindex 3a5d57a9b1..7717ac04e4 100644--- a/opendevin/events/action/agent.py+++ b/opendevin/events/action/agent.py@@ -40,6 +40,11 @@ class AgentSummarizeAction(Action):def message(self) -> str:return self.summary+ def __str__(self) -> str:+ ret = '**AgentSummarizeAction**\n'+ ret += f'SUMMARY: {self.summary}'+ return ret+@dataclassclass AgentFinishAction(Action):diff --git a/opendevin/events/action/browse.py b/opendevin/events/action/browse.pyindex d536340aa1..949bb80876 100644--- a/opendevin/events/action/browse.py+++ b/opendevin/events/action/browse.py@@ -17,6 +17,13 @@ class BrowseURLAction(Action):def message(self) -> str:return f'Browsing URL: {self.url}'+ def __str__(self) -> str:+ ret = '**BrowseURLAction**\n'+ if self.thought:+ ret += f'THOUGHT: {self.thought}\n'+ ret += f'URL: {self.url}'+ return ret+@dataclassclass BrowseInteractiveAction(Action):@@ -28,3 +35,10 @@ class BrowseInteractiveAction(Action):@propertydef message(self) -> str:return f'Executing browser actions: {self.browser_actions}'++ def __str__(self) -> str:+ ret = '**BrowseInteractiveAction**\n'+ if self.thought:+ ret += f'THOUGHT: {self.thought}\n'+ ret += f'BROWSER_ACTIONS: {self.browser_actions}'+ return retdiff --git a/opendevin/events/action/commands.py b/opendevin/events/action/commands.pyindex 4d09ee883f..c6eb5f0d62 100644--- a/opendevin/events/action/commands.py+++ b/opendevin/events/action/commands.py@@ -21,7 +21,7 @@ class CmdRunAction(Action):def __str__(self) -> str:ret = '**CmdRunAction**\n'if self.thought:- ret += f'THOUGHT:{self.thought}\n'+ ret += f'THOUGHT: {self.thought}\n'ret += f'COMMAND:\n{self.command}'return ret@@ -52,7 +52,7 @@ class IPythonRunCellAction(Action):def __str__(self) -> str:ret = '**IPythonRunCellAction**\n'if self.thought:- ret += f'THOUGHT:{self.thought}\n'+ ret += f'THOUGHT: {self.thought}\n'ret += f'CODE:\n{self.code}'return retdiff --git a/opendevin/events/action/message.py b/opendevin/events/action/message.pyindex 1e9e4166d0..724821c243 100644--- a/opendevin/events/action/message.py+++ b/opendevin/events/action/message.py@@ -14,3 +14,8 @@ class MessageAction(Action):@propertydef message(self) -> str:return self.content++ def __str__(self) -> str:+ ret = f'**MessageAction** (source={self.source})\n'+ ret += f'CONTENT: {self.content}'+ return retdiff --git a/opendevin/events/observation/browse.py b/opendevin/events/observation/browse.pyindex 4f6eeac0c5..742dc0cc5c 100644--- a/opendevin/events/observation/browse.py+++ b/opendevin/events/observation/browse.py@@ -28,3 +28,17 @@ class BrowserOutputObservation(Observation):@propertydef message(self) -> str:return 'Visited ' + self.url++ def __str__(self) -> str:+ return (+ '**BrowserOutputObservation**\n'+ f'URL: {self.url}\n'+ f'Status code: {self.status_code}\n'+ f'Error: {self.error}\n'+ f'Open pages: {self.open_pages_urls}\n'+ f'Active page index: {self.active_page_index}\n'+ f'Last browser action: {self.last_browser_action}\n'+ f'Last browser action error: {self.last_browser_action_error}\n'+ f'Focused element bid: {self.focused_element_bid}\n'+ f'CONTENT: {self.content}\n'+ )