log user actions

This commit is contained in:
மனோஜ்குமார் பழனிச்சாமி
2024-06-20 03:33:53 +05:30
parent 5e67e74652
commit 4697c0fb4c
5 changed files with 12 additions and 8 deletions

View File

@@ -16,6 +16,7 @@ from opendevin.events.action import (
IPythonRunCellAction,
MessageAction,
)
from opendevin.events.event import EventSource
from opendevin.events.observation import (
AgentDelegateObservation,
BrowserOutputObservation,
@@ -233,7 +234,9 @@ class CodeActAgent(Agent):
state.num_of_chars += sum(
len(message['content']) for message in messages
) + len(response.choices[0].message.content)
return self.action_parser.parse(response)
action = self.action_parser.parse(response)
action._source = EventSource.AGENT # type: ignore[attr-defined]
return action
def search_memory(self, query: str) -> list[str]:
raise NotImplementedError('Implement this abstract method')

View File

@@ -155,14 +155,11 @@ 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:
logger.info(event, extra={'msg_type': 'ACTION'})
if event.wait_for_response:
await self.set_agent_state_to(AgentState.AWAITING_USER_INPUT)
elif event.source == EventSource.AGENT and event.wait_for_response:
await self.set_agent_state_to(AgentState.AWAITING_USER_INPUT)
elif isinstance(event, AgentDelegateAction):
await self.start_delegate(event)
elif isinstance(event, AddTaskAction):

View File

@@ -51,7 +51,7 @@ class ColoredFormatter(logging.Formatter):
)
name_str = colored(record.name, LOG_COLORS[msg_type])
level_str = colored(record.levelname, LOG_COLORS[msg_type])
if msg_type in ['ERROR']:
if msg_type in ['ERROR'] or config.debug:
return f'{time_str} - {name_str}:{level_str}: {record.filename}:{record.lineno}\n{msg_type_color}\n{msg}'
return f'{time_str} - {msg_type_color}\n{msg}'
elif msg_type == 'STEP':

View File

@@ -19,7 +19,7 @@ class CmdRunAction(Action):
return f'Running command: {self.command}'
def __str__(self) -> str:
ret = '**CmdRunAction**\n'
ret = f'**CmdRunAction (source={self.source})**\n'
if self.thought:
ret += f'THOUGHT: {self.thought}\n'
ret += f'COMMAND:\n{self.command}'

View File

@@ -1,4 +1,5 @@
from opendevin.core.exceptions import LLMMalformedActionError
from opendevin.core.logger import opendevin_logger as logger
from opendevin.events.action.action import Action
from opendevin.events.action.agent import (
AgentDelegateAction,
@@ -17,6 +18,7 @@ from opendevin.events.action.empty import NullAction
from opendevin.events.action.files import FileReadAction, FileWriteAction
from opendevin.events.action.message import MessageAction
from opendevin.events.action.tasks import AddTaskAction, ModifyTaskAction
from opendevin.events.event import EventSource
actions = (
NullAction,
@@ -58,6 +60,8 @@ def action_from_dict(action: dict) -> Action:
args = action.get('args', {})
try:
decoded_action = action_class(**args)
decoded_action._source = action.get('source', EventSource.USER)
logger.info(decoded_action, extra={'msg_type': 'ACTION'})
except TypeError:
raise LLMMalformedActionError(f'action={action} has the wrong arguments')
return decoded_action