mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-10 07:18:10 -05:00
Improve action and observation logging for the CLI interface (#2035)
* properly log user messages; format browser action/obs, summarize action, messages properly for logging * add source to message * add spaces for printing
This commit is contained in:
@@ -128,10 +128,12 @@ class AgentController:
|
||||
await self.set_agent_state_to(event.agent_state) # type: ignore
|
||||
elif 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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@dataclass
|
||||
class AgentFinishAction(Action):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@dataclass
|
||||
class BrowseInteractiveAction(Action):
|
||||
@@ -28,3 +35,10 @@ class BrowseInteractiveAction(Action):
|
||||
@property
|
||||
def 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 ret
|
||||
|
||||
@@ -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 ret
|
||||
|
||||
|
||||
@@ -14,3 +14,8 @@ class MessageAction(Action):
|
||||
@property
|
||||
def message(self) -> str:
|
||||
return self.content
|
||||
|
||||
def __str__(self) -> str:
|
||||
ret = f'**MessageAction** (source={self.source})\n'
|
||||
ret += f'CONTENT: {self.content}'
|
||||
return ret
|
||||
|
||||
@@ -28,3 +28,17 @@ class BrowserOutputObservation(Observation):
|
||||
@property
|
||||
def 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'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user