fix bad observation check (#184)

* fix bad observation check

* fix add_history call
This commit is contained in:
Robert Brennan
2024-03-26 08:35:06 -04:00
committed by GitHub
parent 5d75e23fa0
commit 0758db202c
3 changed files with 13 additions and 6 deletions

View File

@@ -136,7 +136,7 @@ class LangchainsAgent(Agent):
else:
d = {"action": "output", "args": {"output": obs.content}}
else:
raise ValueError(f"Unknown observation type: {obs}")
d = {"action": "output", "args": {"output": obs.content}}
if d is not None:
self._add_event(d)

View File

@@ -1,5 +1,6 @@
import asyncio
from typing import List, Callable, Tuple
import traceback
from opendevin.state import State
from opendevin.agent import Agent
@@ -45,8 +46,12 @@ class AgentController:
self.state_updated_info = []
return state
def add_observation(self, observation: Observation):
self.state_updated_info.append((NullAction(), observation))
def add_history(self, action: Action, observation: Observation):
if not isinstance(action, Action):
raise ValueError("action must be an instance of Action")
if not isinstance(observation, Observation):
raise ValueError("observation must be an instance of Observation")
self.state_updated_info.append((action, observation))
async def start_loop(self, task_instruction: str):
finished = False
@@ -56,6 +61,7 @@ class AgentController:
finished = await self.step(i)
except Exception as e:
print("Error in loop", e, flush=True)
traceback.print_exc()
break
if finished:
break
@@ -67,7 +73,7 @@ class AgentController:
print("STEP", i, flush=True)
log_obs = self.command_manager.get_background_obs()
for obs in log_obs:
self.add_observation(obs)
self.add_history(NullAction(), obs)
await self._run_callbacks(obs)
print_with_indent("\nBACKGROUND LOG:\n%s" % obs)
@@ -91,7 +97,7 @@ class AgentController:
else:
observation = NullObservation("")
print_with_indent("\nOBSERVATION:\n%s" % observation)
self.state_updated_info.append((action, observation))
self.add_history(action, observation)
await self._run_callbacks(observation)

View File

@@ -6,6 +6,7 @@ from fastapi import WebSocketDisconnect
from opendevin.action import (
Action,
NullAction,
CmdRunAction,
CmdKillAction,
BrowseURLAction,
@@ -99,7 +100,7 @@ class Session:
await self.send_error("No agent started. Please wait a second...")
elif event["action"] == "chat":
self.controller.add_observation(UserMessageObservation(event["message"]))
self.controller.add_history(NullAction(), UserMessageObservation(event["message"]))
else:
# TODO: we only need to implement user message for now
# since even Devin does not support having the user taking other