diff --git a/agenthub/codeact_agent/__init__.py b/agenthub/codeact_agent/__init__.py index b3f46005fddf..1a0a4636253f 100644 --- a/agenthub/codeact_agent/__init__.py +++ b/agenthub/codeact_agent/__init__.py @@ -79,7 +79,7 @@ def __init__( ] print(colored("===USER:===\n" + instruction, "green")) - def step(self, state: State) -> None: + def step(self, state: State) -> Action: updated_info = state.updated_info if updated_info: diff --git a/agenthub/langchains_agent/__init__.py b/agenthub/langchains_agent/__init__.py index 24804e6400f6..21c4b6e85565 100644 --- a/agenthub/langchains_agent/__init__.py +++ b/agenthub/langchains_agent/__init__.py @@ -110,19 +110,16 @@ def _initialize(self): if thought.startswith("RUN"): command = thought.split("RUN ")[1] d = {"action": "run", "args": {"command": command}} - d = CmdRunAction(command=command) next_is_output = True elif thought.startswith("RECALL"): query = thought.split("RECALL ")[1] d = {"action": "recall", "args": {"query": query}} - d = AgentRecallAction(query=query) next_is_output = True elif thought.startswith("BROWSE"): url = thought.split("BROWSE ")[1] d = {"action": "browse", "args": {"url": url}} - d = BrowseURLAction(url=url) next_is_output = True else: d = {"action": "think", "args": {"thought": thought}} @@ -142,13 +139,13 @@ def step(self, state: State) -> Action: if info.error: d = {"action": "error", "args": {"output": info.content}} else: - d = {"action": "output", "args": {"output": info.output}} + d = {"action": "output", "args": {"output": info.content}} # elif isinstance(info, UserMessageObservation): # d = {"action": "output", "args": {"output": info.message}} # elif isinstance(info, AgentMessageObservation): # d = {"action": "output", "args": {"output": info.message}} elif isinstance(info, BrowserOutputObservation): - d = {"action": "output", "args": {"output": info.output}} + d = {"action": "output", "args": {"output": info.content}} else: raise NotImplementedError(f"Unknown observation type: {info}") self._add_event(d) diff --git a/agenthub/langchains_agent/utils/llm.py b/agenthub/langchains_agent/utils/llm.py index 5deae8d58a07..7de878442824 100644 --- a/agenthub/langchains_agent/utils/llm.py +++ b/agenthub/langchains_agent/utils/llm.py @@ -107,7 +107,7 @@ def get_chain(template, model_name): assert ( "OPENAI_API_KEY" in os.environ ), "Please set the OPENAI_API_KEY environment variable to use langchains_agent." - llm = ChatOpenAI(openai_api_key=os.getenv("OPENAI_API_KEY"), model_name=model_name) + llm = ChatOpenAI(openai_api_key=os.getenv("OPENAI_API_KEY"), model_name=model_name) # type: ignore prompt = PromptTemplate.from_template(template) llm_chain = LLMChain(prompt=prompt, llm=llm) return llm_chain @@ -128,7 +128,7 @@ def request_action( task, thoughts: List[dict], model_name: str, - background_commands_obs: Mapping[int, CmdOutputObservation] = [], + background_commands_obs: List[CmdOutputObservation] = [], ): llm_chain = get_chain(ACTION_PROMPT, model_name) parser = JsonOutputParser(pydantic_object=_ActionDict) @@ -146,8 +146,8 @@ def request_action( bg_commands_message = "" if len(background_commands_obs) > 0: bg_commands_message = "The following commands are running in the background:" - for id, command_obs in background_commands_obs.items(): - bg_commands_message += f"\n`{id}`: {command_obs.command}" + for command_obs in background_commands_obs: + bg_commands_message += f"\n`{command_obs.command_id}`: {command_obs.command}" bg_commands_message += "\nYou can end any process by sending a `kill` action with the numerical `id` above." latest_thought = thoughts[-1] diff --git a/agenthub/langchains_agent/utils/memory.py b/agenthub/langchains_agent/utils/memory.py index ef519f6af4a7..7024cae84458 100644 --- a/agenthub/langchains_agent/utils/memory.py +++ b/agenthub/langchains_agent/utils/memory.py @@ -18,7 +18,7 @@ def __init__(self): def add_event(self, event): doc = Document( text=json.dumps(event), - doc_id=self.thought_idx, + doc_id=str(self.thought_idx), extra_info={ "type": event["action"], "idx": self.thought_idx, diff --git a/opendevin/action/agent.py b/opendevin/action/agent.py index 36633dc47a36..47a368781d7a 100644 --- a/opendevin/action/agent.py +++ b/opendevin/action/agent.py @@ -1,7 +1,7 @@ from dataclasses import dataclass from typing import TYPE_CHECKING -from opendevin.observation import AgentMessageObservation, Observation +from opendevin.observation import AgentRecallObservation, AgentMessageObservation, Observation from .base import ExecutableAction, NotExecutableAction if TYPE_CHECKING: from opendevin.controller import AgentController @@ -11,8 +11,11 @@ class AgentRecallAction(ExecutableAction): query: str - def run(self, controller: "AgentController") -> AgentMessageObservation: - return AgentMessageObservation(controller.agent.search_memory(self.query)) + def run(self, controller: "AgentController") -> AgentRecallObservation: + return AgentRecallObservation( + content="Recalling memories...", + memories=controller.agent.search_memory(self.query) + ) @dataclass diff --git a/opendevin/action/browse.py b/opendevin/action/browse.py index 24ee8fd85c41..71c67544d484 100644 --- a/opendevin/action/browse.py +++ b/opendevin/action/browse.py @@ -1,5 +1,6 @@ -from dataclasses import dataclass import requests + +from dataclasses import dataclass from opendevin.observation import BrowserOutputObservation from .base import ExecutableAction diff --git a/opendevin/agent.py b/opendevin/agent.py index e85f777054cd..f8de4710d974 100644 --- a/opendevin/agent.py +++ b/opendevin/agent.py @@ -63,7 +63,6 @@ def reset(self) -> None: """ self.instruction = "" self._complete = False - self._history = [] @classmethod def register(cls, name: str, agent_cls: Type["Agent"]): diff --git a/opendevin/main.py b/opendevin/main.py index 9e1b6e1ded93..b0ee3ad7d45b 100644 --- a/opendevin/main.py +++ b/opendevin/main.py @@ -1,5 +1,6 @@ import argparse +from typing import Type from opendevin.agent import Agent from opendevin.controller import AgentController @@ -44,7 +45,7 @@ print(f"Running agent {args.agent_cls} (model: {args.model_name}, directory: {args.directory}) with task: \"{args.task}\"") - AgentCls: Agent = Agent.get_cls(args.agent_cls) + AgentCls: Type[Agent] = Agent.get_cls(args.agent_cls) agent = AgentCls(instruction=args.task, model_name=args.model_name) controller = AgentController( diff --git a/opendevin/observation.py b/opendevin/observation.py index 7e24b5d3d34b..989028ecec14 100644 --- a/opendevin/observation.py +++ b/opendevin/observation.py @@ -1,3 +1,4 @@ +from typing import List from dataclasses import dataclass @dataclass @@ -50,3 +51,12 @@ class AgentMessageObservation(Observation): This data class represents a message sent by the agent. """ role: str = "assistant" + +@dataclass +class AgentRecallObservation(Observation): + """ + This data class represents a list of memories recalled by the agent. + """ + memories: List[str] + role: str = "assistant" + diff --git a/opendevin/state.py b/opendevin/state.py index 0a6b0e3a556c..4b65d0efc63c 100644 --- a/opendevin/state.py +++ b/opendevin/state.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import Mapping, List +from typing import List from opendevin.action import ( Action, @@ -12,5 +12,5 @@ @dataclass class State: - background_commands_obs: Mapping[int, CmdOutputObservation] + background_commands_obs: List[CmdOutputObservation] updated_info: List[Action | Observation]