From caabfab7e24ffb2e08ed9979c10b72266ae4e32a Mon Sep 17 00:00:00 2001 From: Engel Nyst Date: Thu, 18 Apr 2024 12:51:07 +0200 Subject: [PATCH] Property 'message' sent to llm (#1198) * Add action with content, no message, to history * fix to_memory(), add it to serialization tests * Actions without 'message' in completion too --- agenthub/monologue_agent/agent.py | 4 ++-- agenthub/planner_agent/prompt.py | 2 +- opendevin/action/base.py | 9 +++++++-- tests/test_action_serialization.py | 2 ++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/agenthub/monologue_agent/agent.py b/agenthub/monologue_agent/agent.py index 85ba772a14..7b9b73e87f 100644 --- a/agenthub/monologue_agent/agent.py +++ b/agenthub/monologue_agent/agent.py @@ -188,7 +188,7 @@ class MonologueAgent(Agent): output_type = ActionType.BROWSE else: action = AgentThinkAction(thought=thought) - self._add_event(action.to_dict()) + self._add_event(action.to_memory()) self._initialized = True def step(self, state: State) -> Action: @@ -203,7 +203,7 @@ class MonologueAgent(Agent): """ self._initialize(state.plan.main_goal) for prev_action, obs in state.updated_info: - self._add_event(prev_action.to_dict()) + self._add_event(prev_action.to_memory()) self._add_event(obs.to_dict()) state.updated_info = [] diff --git a/agenthub/planner_agent/prompt.py b/agenthub/planner_agent/prompt.py index 7088ccac5f..9ead741d6a 100644 --- a/agenthub/planner_agent/prompt.py +++ b/agenthub/planner_agent/prompt.py @@ -149,7 +149,7 @@ def get_prompt(plan: Plan, history: List[Tuple[Action, Observation]]) -> str: latest_action: Action = NullAction() for action, observation in sub_history: if not isinstance(action, NullAction): - history_dicts.append(action.to_dict()) + history_dicts.append(action.to_memory()) latest_action = action if not isinstance(observation, NullObservation): observation_dict = observation.to_dict() diff --git a/opendevin/action/base.py b/opendevin/action/base.py index bfc8d93bc8..e80b4a7cca 100644 --- a/opendevin/action/base.py +++ b/opendevin/action/base.py @@ -12,13 +12,18 @@ class Action: async def run(self, controller: 'AgentController') -> 'Observation': raise NotImplementedError - def to_dict(self): + def to_memory(self): d = asdict(self) try: v = d.pop('action') except KeyError: raise NotImplementedError(f'{self=} does not have action attribute set') - return {'action': v, 'args': d, 'message': self.message} + return {'action': v, 'args': d} + + def to_dict(self): + d = self.to_memory() + d['message'] = self.message + return d @property def executable(self) -> bool: diff --git a/tests/test_action_serialization.py b/tests/test_action_serialization.py index 4b864f1282..1cf3746bf2 100644 --- a/tests/test_action_serialization.py +++ b/tests/test_action_serialization.py @@ -21,8 +21,10 @@ def serialization_deserialization(original_action_dict, cls): assert isinstance( action_instance, cls), f'The action instance should be an instance of {cls.__name__}.' serialized_action_dict = action_instance.to_dict() + serialized_action_memory = action_instance.to_memory() serialized_action_dict.pop('message') assert serialized_action_dict == original_action_dict, 'The serialized action should match the original action dict.' + assert serialized_action_memory == original_action_dict, 'The serialized action in memory should match the original action dict.' def test_agent_think_action_serialization_deserialization():