diff --git a/agenthub/SWE_agent/__init__.py b/agenthub/SWE_agent/__init__.py index 8f0f418a7240..58e5f7203802 100644 --- a/agenthub/SWE_agent/__init__.py +++ b/agenthub/SWE_agent/__init__.py @@ -1,4 +1,5 @@ from opendevin.agent import Agent + from .agent import SWEAgent Agent.register('SWEAgent', SWEAgent) diff --git a/agenthub/SWE_agent/agent.py b/agenthub/SWE_agent/agent.py index 80e443f98bbd..808063eaff7f 100644 --- a/agenthub/SWE_agent/agent.py +++ b/agenthub/SWE_agent/agent.py @@ -1,23 +1,23 @@ from typing import List -from opendevin.agent import Agent -from opendevin.llm.llm import LLM -from opendevin.state import State + from opendevin.action import ( Action, AgentThinkAction, FileReadAction, FileWriteAction, ) +from opendevin.agent import Agent +from opendevin.llm.llm import LLM from opendevin.observation import Observation +from opendevin.state import State from .parser import parse_command - from .prompts import ( - SYSTEM_MESSAGE, - STEP_PROMPT, + CONTEXT_PROMPT, MEMORY_FORMAT, NO_ACTION, - CONTEXT_PROMPT + STEP_PROMPT, + SYSTEM_MESSAGE, ) diff --git a/agenthub/SWE_agent/parser.py b/agenthub/SWE_agent/parser.py index 3a8ca180b505..d4600291ef40 100644 --- a/agenthub/SWE_agent/parser.py +++ b/agenthub/SWE_agent/parser.py @@ -1,17 +1,17 @@ +import re + from opendevin.action import ( Action, + AgentEchoAction, AgentFinishAction, + AgentThinkAction, + BrowseURLAction, CmdRunAction, FileReadAction, FileWriteAction, - BrowseURLAction, - AgentEchoAction, - AgentThinkAction, ) -import re - -from .prompts import CUSTOM_DOCS, COMMAND_USAGE +from .prompts import COMMAND_USAGE, CUSTOM_DOCS # commands: exit, read, write, browse, kill, search_file, search_dir diff --git a/agenthub/__init__.py b/agenthub/__init__.py index c39cfa3b6ff9..74b457793d49 100644 --- a/agenthub/__init__.py +++ b/agenthub/__init__.py @@ -1,17 +1,21 @@ -from .micro.registry import all_microagents -from .micro.agent import MicroAgent +from dotenv import load_dotenv + from opendevin.agent import Agent -from dotenv import load_dotenv +from .micro.agent import MicroAgent +from .micro.registry import all_microagents + load_dotenv() # Import agents after environment variables are loaded -from . import monologue_agent # noqa: E402 -from . import codeact_agent # noqa: E402 -from . import planner_agent # noqa: E402 -from . import SWE_agent # noqa: E402 -from . import delegator_agent # noqa: E402 +from . import ( # noqa: E402 + SWE_agent, + codeact_agent, + delegator_agent, + monologue_agent, + planner_agent, +) __all__ = ['monologue_agent', 'codeact_agent', 'planner_agent', 'SWE_agent', 'delegator_agent'] diff --git a/agenthub/codeact_agent/__init__.py b/agenthub/codeact_agent/__init__.py index a07c920950d9..c8d08d364dc3 100644 --- a/agenthub/codeact_agent/__init__.py +++ b/agenthub/codeact_agent/__init__.py @@ -1,4 +1,5 @@ from opendevin.agent import Agent + from .codeact_agent import CodeActAgent Agent.register('CodeActAgent', CodeActAgent) diff --git a/agenthub/codeact_agent/codeact_agent.py b/agenthub/codeact_agent/codeact_agent.py index 9ff503f3bd67..576e060bfa0f 100644 --- a/agenthub/codeact_agent/codeact_agent.py +++ b/agenthub/codeact_agent/codeact_agent.py @@ -13,8 +13,8 @@ AgentMessageObservation, CmdOutputObservation, ) +from opendevin.sandbox.plugins import JupyterRequirement, PluginRequirement from opendevin.state import State -from opendevin.sandbox.plugins import PluginRequirement, JupyterRequirement SYSTEM_MESSAGE = """You are a helpful assistant. You will be provided access (as root) to a bash shell to complete user-provided tasks. You will be able to execute commands in the bash shell, interact with the file system, install packages, and receive the output of your commands. diff --git a/agenthub/delegator_agent/__init__.py b/agenthub/delegator_agent/__init__.py index ffc2af8b247b..d25d295e3a77 100644 --- a/agenthub/delegator_agent/__init__.py +++ b/agenthub/delegator_agent/__init__.py @@ -1,4 +1,5 @@ from opendevin.agent import Agent + from .agent import DelegatorAgent Agent.register('DelegatorAgent', DelegatorAgent) diff --git a/agenthub/delegator_agent/agent.py b/agenthub/delegator_agent/agent.py index 8481d17d31b2..57ecd7bcd487 100644 --- a/agenthub/delegator_agent/agent.py +++ b/agenthub/delegator_agent/agent.py @@ -1,11 +1,10 @@ from typing import List +from opendevin.action import Action, AgentDelegateAction, AgentFinishAction from opendevin.agent import Agent -from opendevin.action import AgentFinishAction, AgentDelegateAction -from opendevin.observation import AgentDelegateObservation from opendevin.llm.llm import LLM +from opendevin.observation import AgentDelegateObservation from opendevin.state import State -from opendevin.action import Action class DelegatorAgent(Agent): diff --git a/agenthub/dummy_agent/agent.py b/agenthub/dummy_agent/agent.py index f1cd85cb3c63..c0908ddeb3b8 100644 --- a/agenthub/dummy_agent/agent.py +++ b/agenthub/dummy_agent/agent.py @@ -1,12 +1,14 @@ """Module for a Dummy agent.""" -from opendevin.action.base import NullAction -from opendevin.state import State -from opendevin.action import Action from typing import List + +from opendevin.action import Action +from opendevin.action.base import NullAction from opendevin.agent import Agent from opendevin.controller.agent_controller import AgentController from opendevin.observation.base import NullObservation, Observation +from opendevin.state import State + class DummyAgent(Agent): """A dummy agent that does nothing but can be used in testing.""" diff --git a/agenthub/micro/agent.py b/agenthub/micro/agent.py index 4445221d2579..a0f6de37955f 100644 --- a/agenthub/micro/agent.py +++ b/agenthub/micro/agent.py @@ -1,13 +1,13 @@ import json -from typing import List, Dict +from typing import Dict, List -from jinja2 import Environment, BaseLoader +from jinja2 import BaseLoader, Environment +from opendevin.action import Action, action_from_dict from opendevin.agent import Agent +from opendevin.exceptions import LLMOutputError from opendevin.llm.llm import LLM from opendevin.state import State -from opendevin.action import Action, action_from_dict -from opendevin.exceptions import LLMOutputError from .instructions import instructions from .registry import all_microagents diff --git a/agenthub/micro/instructions.py b/agenthub/micro/instructions.py index 856c78024a2b..022e08511bac 100644 --- a/agenthub/micro/instructions.py +++ b/agenthub/micro/instructions.py @@ -1,5 +1,5 @@ -from typing import Dict import os +from typing import Dict instructions: Dict = {} diff --git a/agenthub/micro/registry.py b/agenthub/micro/registry.py index fd52cc8a7a50..2fc4060dc466 100644 --- a/agenthub/micro/registry.py +++ b/agenthub/micro/registry.py @@ -1,4 +1,5 @@ import os + import yaml all_microagents = {} diff --git a/agenthub/monologue_agent/__init__.py b/agenthub/monologue_agent/__init__.py index 1cfef46f1188..b60cb48bb550 100644 --- a/agenthub/monologue_agent/__init__.py +++ b/agenthub/monologue_agent/__init__.py @@ -1,4 +1,5 @@ from opendevin.agent import Agent + from .agent import MonologueAgent Agent.register('MonologueAgent', MonologueAgent) diff --git a/agenthub/monologue_agent/agent.py b/agenthub/monologue_agent/agent.py index 2be6c260395f..7f7d8dd4eb8e 100644 --- a/agenthub/monologue_agent/agent.py +++ b/agenthub/monologue_agent/agent.py @@ -1,35 +1,34 @@ from typing import List -from opendevin.agent import Agent -from opendevin.state import State -from opendevin.llm.llm import LLM -from opendevin.schema import ActionType -from opendevin.exceptions import AgentNoInstructionError -from opendevin.schema.config import ConfigType -from opendevin import config +import agenthub.monologue_agent.utils.prompts as prompts +from agenthub.monologue_agent.utils.monologue import Monologue +from opendevin import config from opendevin.action import ( Action, - NullAction, - CmdRunAction, - FileWriteAction, - FileReadAction, AgentRecallAction, + AgentThinkAction, BrowseURLAction, + CmdRunAction, + FileReadAction, + FileWriteAction, GitHubPushAction, - AgentThinkAction, + NullAction, ) - +from opendevin.agent import Agent +from opendevin.exceptions import AgentNoInstructionError +from opendevin.llm.llm import LLM from opendevin.observation import ( - Observation, - NullObservation, - CmdOutputObservation, - FileReadObservation, AgentRecallObservation, BrowserOutputObservation, + CmdOutputObservation, + FileReadObservation, + NullObservation, + Observation, ) +from opendevin.schema import ActionType +from opendevin.schema.config import ConfigType +from opendevin.state import State -import agenthub.monologue_agent.utils.prompts as prompts -from agenthub.monologue_agent.utils.monologue import Monologue if config.get(ConfigType.AGENT_MEMORY_ENABLED): from agenthub.monologue_agent.utils.memory import LongTermMemory diff --git a/agenthub/monologue_agent/utils/json.py b/agenthub/monologue_agent/utils/json.py index 455a42ee0bf8..13b7416086a3 100644 --- a/agenthub/monologue_agent/utils/json.py +++ b/agenthub/monologue_agent/utils/json.py @@ -1,4 +1,5 @@ import json + from json_repair import repair_json diff --git a/agenthub/monologue_agent/utils/memory.py b/agenthub/monologue_agent/utils/memory.py index 9500d7828706..30cff89bd798 100644 --- a/agenthub/monologue_agent/utils/memory.py +++ b/agenthub/monologue_agent/utils/memory.py @@ -1,17 +1,22 @@ -import llama_index.embeddings.openai.base as llama_openai import threading import chromadb -from llama_index.core import Document +import llama_index.embeddings.openai.base as llama_openai +from llama_index.core import Document, VectorStoreIndex from llama_index.core.retrievers import VectorIndexRetriever -from llama_index.core import VectorStoreIndex from llama_index.vector_stores.chroma import ChromaVectorStore -from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_random_exponential -from openai._exceptions import APIConnectionError, RateLimitError, InternalServerError +from openai._exceptions import APIConnectionError, InternalServerError, RateLimitError +from tenacity import ( + retry, + retry_if_exception_type, + stop_after_attempt, + wait_random_exponential, +) from opendevin import config from opendevin.logger import opendevin_logger as logger from opendevin.schema.config import ConfigType + from . import json num_retries = config.get(ConfigType.LLM_NUM_RETRIES) diff --git a/agenthub/monologue_agent/utils/monologue.py b/agenthub/monologue_agent/utils/monologue.py index 410b49c17ad5..545498d7b51b 100644 --- a/agenthub/monologue_agent/utils/monologue.py +++ b/agenthub/monologue_agent/utils/monologue.py @@ -1,8 +1,8 @@ -from opendevin.llm.llm import LLM -from opendevin.exceptions import AgentEventTypeError import agenthub.monologue_agent.utils.json as json import agenthub.monologue_agent.utils.prompts as prompts +from opendevin.exceptions import AgentEventTypeError +from opendevin.llm.llm import LLM from opendevin.logger import opendevin_logger as logger diff --git a/agenthub/monologue_agent/utils/prompts.py b/agenthub/monologue_agent/utils/prompts.py index 4bf0e78931d0..8767aecaa3cd 100644 --- a/agenthub/monologue_agent/utils/prompts.py +++ b/agenthub/monologue_agent/utils/prompts.py @@ -1,21 +1,20 @@ -from typing import List - -from . import json -from json import JSONDecodeError - import re +from json import JSONDecodeError +from typing import List +from opendevin import config from opendevin.action import ( - action_from_dict, Action, + action_from_dict, ) +from opendevin.exceptions import LLMOutputError from opendevin.observation import ( CmdOutputObservation, ) -from opendevin.exceptions import LLMOutputError -from opendevin import config from opendevin.schema.config import ConfigType +from . import json + ACTION_PROMPT = """ You're a thoughtful robot. Your main task is this: %(task)s diff --git a/agenthub/planner_agent/__init__.py b/agenthub/planner_agent/__init__.py index 77bed3e68673..d81ba6cc2612 100644 --- a/agenthub/planner_agent/__init__.py +++ b/agenthub/planner_agent/__init__.py @@ -1,4 +1,5 @@ from opendevin.agent import Agent + from .agent import PlannerAgent Agent.register('PlannerAgent', PlannerAgent) diff --git a/agenthub/planner_agent/agent.py b/agenthub/planner_agent/agent.py index de0672ef5747..44413dfeeaef 100644 --- a/agenthub/planner_agent/agent.py +++ b/agenthub/planner_agent/agent.py @@ -1,11 +1,11 @@ from typing import List -from .prompt import get_prompt, parse_response +from opendevin.action import Action, AgentFinishAction from opendevin.agent import Agent -from opendevin.action import AgentFinishAction from opendevin.llm.llm import LLM from opendevin.state import State -from opendevin.action import Action + +from .prompt import get_prompt, parse_response class PlannerAgent(Agent): diff --git a/agenthub/planner_agent/prompt.py b/agenthub/planner_agent/prompt.py index 2b97b88348f1..234b958590c0 100644 --- a/agenthub/planner_agent/prompt.py +++ b/agenthub/planner_agent/prompt.py @@ -1,29 +1,29 @@ import json -from typing import List, Tuple, Dict, Type -from opendevin.plan import Plan -from opendevin.action import Action, action_from_dict -from opendevin.observation import Observation -from opendevin.schema import ActionType -from opendevin.logger import opendevin_logger as logger +from typing import Dict, List, Tuple, Type from opendevin.action import ( - NullAction, - CmdRunAction, - CmdKillAction, + Action, + AddTaskAction, + AgentFinishAction, + AgentRecallAction, + AgentSummarizeAction, + AgentThinkAction, BrowseURLAction, + CmdKillAction, + CmdRunAction, FileReadAction, FileWriteAction, - AgentRecallAction, - AgentThinkAction, - AgentFinishAction, - AgentSummarizeAction, - AddTaskAction, ModifyTaskAction, + NullAction, + action_from_dict, ) - +from opendevin.logger import opendevin_logger as logger from opendevin.observation import ( NullObservation, + Observation, ) +from opendevin.plan import Plan +from opendevin.schema import ActionType ACTION_TYPE_TO_CLASS: Dict[str, Type[Action]] = { ActionType.RUN: CmdRunAction, diff --git a/dev_config/python/ruff.toml b/dev_config/python/ruff.toml index 06ba2d3aceee..4efe096a3065 100644 --- a/dev_config/python/ruff.toml +++ b/dev_config/python/ruff.toml @@ -7,6 +7,7 @@ select = [ "E", "W", "F", + "I", "Q", ] diff --git a/evaluation/SWE-bench/notebooks/devin_eval_analysis.ipynb b/evaluation/SWE-bench/notebooks/devin_eval_analysis.ipynb index b6633aac7c23..3cc21c912a15 100644 --- a/evaluation/SWE-bench/notebooks/devin_eval_analysis.ipynb +++ b/evaluation/SWE-bench/notebooks/devin_eval_analysis.ipynb @@ -11,12 +11,12 @@ }, "outputs": [], "source": [ - "import requests\n", + "import matplotlib.pyplot as plt\n", "import pandas as pd\n", - "from tqdm import tqdm\n", - "from datasets import load_dataset\n", + "import requests\n", "import seaborn as sns\n", - "import matplotlib.pyplot as plt" + "from datasets import load_dataset\n", + "from tqdm import tqdm" ] }, { diff --git a/evaluation/SWE-bench/scripts/prepare_devin_outputs_for_evaluation.py b/evaluation/SWE-bench/scripts/prepare_devin_outputs_for_evaluation.py index 829e25faf211..428f1061cad7 100644 --- a/evaluation/SWE-bench/scripts/prepare_devin_outputs_for_evaluation.py +++ b/evaluation/SWE-bench/scripts/prepare_devin_outputs_for_evaluation.py @@ -11,9 +11,10 @@ ''' # fetch devin's outputs into a json file for evaluation +import json import os import sys -import json + import requests from tqdm import tqdm diff --git a/evaluation/regression/cases/hello-world/test_hello_world.py b/evaluation/regression/cases/hello-world/test_hello_world.py index ed33cb45f153..bb6110f9349e 100644 --- a/evaluation/regression/cases/hello-world/test_hello_world.py +++ b/evaluation/regression/cases/hello-world/test_hello_world.py @@ -1,4 +1,5 @@ import os + import pytest from conftest import agents diff --git a/evaluation/regression/conftest.py b/evaluation/regression/conftest.py index f1bf1f6443be..977fc7f55963 100644 --- a/evaluation/regression/conftest.py +++ b/evaluation/regression/conftest.py @@ -1,9 +1,10 @@ -import os -import pytest -import subprocess +import datetime import logging +import os import shutil -import datetime +import subprocess + +import pytest SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) CASES_DIR = os.path.join(SCRIPT_DIR, 'cases') diff --git a/evaluation/regression/run_tests.py b/evaluation/regression/run_tests.py index bfb7185ed353..2887b44507a7 100644 --- a/evaluation/regression/run_tests.py +++ b/evaluation/regression/run_tests.py @@ -1,4 +1,5 @@ import argparse + import pytest from opendevin import config diff --git a/opendevin/action/__init__.py b/opendevin/action/__init__.py index 782400319fbb..be79bbfe8273 100644 --- a/opendevin/action/__init__.py +++ b/opendevin/action/__init__.py @@ -1,18 +1,18 @@ -from .base import Action, NullAction -from .bash import CmdRunAction, CmdKillAction -from .browse import BrowseURLAction -from .fileop import FileReadAction, FileWriteAction -from .github import GitHubPushAction +from ..exceptions import AgentMalformedActionError from .agent import ( - AgentRecallAction, - AgentThinkAction, - AgentFinishAction, + AgentDelegateAction, AgentEchoAction, + AgentFinishAction, + AgentRecallAction, AgentSummarizeAction, - AgentDelegateAction, + AgentThinkAction, ) +from .base import Action, NullAction +from .bash import CmdKillAction, CmdRunAction +from .browse import BrowseURLAction +from .fileop import FileReadAction, FileWriteAction +from .github import GitHubPushAction from .tasks import AddTaskAction, ModifyTaskAction -from ..exceptions import AgentMalformedActionError actions = ( CmdKillAction, diff --git a/opendevin/action/agent.py b/opendevin/action/agent.py index 1cb0b8cdf2a3..11461f6f82f0 100644 --- a/opendevin/action/agent.py +++ b/opendevin/action/agent.py @@ -2,12 +2,13 @@ from typing import TYPE_CHECKING, Dict from opendevin.observation import ( - AgentRecallObservation, AgentMessageObservation, + AgentRecallObservation, NullObservation, Observation, ) from opendevin.schema import ActionType + from .base import ExecutableAction, NotExecutableAction if TYPE_CHECKING: diff --git a/opendevin/action/base.py b/opendevin/action/base.py index f3273011aa7b..d459713f3f03 100644 --- a/opendevin/action/base.py +++ b/opendevin/action/base.py @@ -1,5 +1,6 @@ -from dataclasses import dataclass, asdict +from dataclasses import asdict, dataclass from typing import TYPE_CHECKING + from opendevin.schema import ActionType if TYPE_CHECKING: diff --git a/opendevin/action/bash.py b/opendevin/action/bash.py index 1757c7ea3c4f..7dc2c4ff27aa 100644 --- a/opendevin/action/bash.py +++ b/opendevin/action/bash.py @@ -1,9 +1,10 @@ from dataclasses import dataclass from typing import TYPE_CHECKING -from .base import ExecutableAction from opendevin.schema import ActionType +from .base import ExecutableAction + if TYPE_CHECKING: from opendevin.controller import AgentController from opendevin.observation import CmdOutputObservation, Observation diff --git a/opendevin/action/browse.py b/opendevin/action/browse.py index 58639e984e47..3c24e04bf258 100644 --- a/opendevin/action/browse.py +++ b/opendevin/action/browse.py @@ -1,11 +1,13 @@ -import os import base64 +import os from dataclasses import dataclass -from opendevin.observation import BrowserOutputObservation -from opendevin.schema import ActionType from typing import TYPE_CHECKING + from playwright.async_api import async_playwright +from opendevin.observation import BrowserOutputObservation +from opendevin.schema import ActionType + from .base import ExecutableAction if TYPE_CHECKING: diff --git a/opendevin/action/fileop.py b/opendevin/action/fileop.py index b1da4b240b6b..343a154e9f8a 100644 --- a/opendevin/action/fileop.py +++ b/opendevin/action/fileop.py @@ -1,18 +1,16 @@ import os - from dataclasses import dataclass from pathlib import Path +from opendevin import config from opendevin.observation import ( - Observation, + AgentErrorObservation, FileReadObservation, FileWriteObservation, - AgentErrorObservation, + Observation, ) - -from opendevin.schema import ActionType from opendevin.sandbox import E2BBox -from opendevin import config +from opendevin.schema import ActionType from opendevin.schema.config import ConfigType from .base import ExecutableAction diff --git a/opendevin/action/github.py b/opendevin/action/github.py index 738adb068052..78dd81fba2dc 100644 --- a/opendevin/action/github.py +++ b/opendevin/action/github.py @@ -1,14 +1,15 @@ +import random +import string from dataclasses import dataclass -from opendevin.observation import Observation, AgentErrorObservation -from opendevin.observation.message import AgentMessageObservation -from opendevin.observation.run import CmdOutputObservation -from opendevin.schema import ActionType -from opendevin import config from typing import TYPE_CHECKING + import requests -import random -import string +from opendevin import config +from opendevin.observation import AgentErrorObservation, Observation +from opendevin.observation.message import AgentMessageObservation +from opendevin.observation.run import CmdOutputObservation +from opendevin.schema import ActionType from opendevin.schema.config import ConfigType from .base import ExecutableAction diff --git a/opendevin/action/tasks.py b/opendevin/action/tasks.py index 96c6fb8f538f..f10234030095 100644 --- a/opendevin/action/tasks.py +++ b/opendevin/action/tasks.py @@ -1,10 +1,11 @@ from dataclasses import dataclass, field +from typing import TYPE_CHECKING -from .base import ExecutableAction, NotExecutableAction -from opendevin.schema import ActionType from opendevin.observation import NullObservation +from opendevin.schema import ActionType + +from .base import ExecutableAction, NotExecutableAction -from typing import TYPE_CHECKING if TYPE_CHECKING: from opendevin.controller import AgentController diff --git a/opendevin/agent.py b/opendevin/agent.py index 855d50ff7ff6..a51a214bd55c 100644 --- a/opendevin/agent.py +++ b/opendevin/agent.py @@ -1,11 +1,11 @@ from abc import ABC, abstractmethod -from typing import List, Dict, Type, TYPE_CHECKING +from typing import TYPE_CHECKING, Dict, List, Type if TYPE_CHECKING: from opendevin.action import Action from opendevin.state import State -from opendevin.llm.llm import LLM from opendevin.exceptions import AgentAlreadyRegisteredError, AgentNotRegisteredError +from opendevin.llm.llm import LLM from opendevin.sandbox.plugins import PluginRequirement diff --git a/opendevin/config.py b/opendevin/config.py index 4f7482cac564..ec095561b883 100644 --- a/opendevin/config.py +++ b/opendevin/config.py @@ -1,12 +1,13 @@ -import os import argparse -import toml +import logging +import os import pathlib import platform + +import toml from dotenv import load_dotenv from opendevin.schema import ConfigType -import logging logger = logging.getLogger(__name__) diff --git a/opendevin/controller/__init__.py b/opendevin/controller/__init__.py index 2f6d436e01d2..005df25448f2 100644 --- a/opendevin/controller/__init__.py +++ b/opendevin/controller/__init__.py @@ -1,5 +1,5 @@ -from .agent_controller import AgentController from .action_manager import ActionManager +from .agent_controller import AgentController __all__ = [ 'AgentController', diff --git a/opendevin/controller/action_manager.py b/opendevin/controller/action_manager.py index d9c91a2c76f4..ea5e0404f9fc 100644 --- a/opendevin/controller/action_manager.py +++ b/opendevin/controller/action_manager.py @@ -1,17 +1,18 @@ from typing import List from opendevin import config -from opendevin.observation import CmdOutputObservation, AgentErrorObservation -from opendevin.sandbox import DockerExecBox, DockerSSHBox, Sandbox, LocalBox, E2BBox -from opendevin.schema import ConfigType from opendevin.action import ( Action, ) from opendevin.observation import ( - Observation, + AgentErrorObservation, + CmdOutputObservation, NullObservation, + Observation, ) +from opendevin.sandbox import DockerExecBox, DockerSSHBox, E2BBox, LocalBox, Sandbox from opendevin.sandbox.plugins import PluginRequirement +from opendevin.schema import ConfigType class ActionManager: diff --git a/opendevin/controller/agent_controller.py b/opendevin/controller/agent_controller.py index 7e1da1e246d6..dff0eb0d502e 100644 --- a/opendevin/controller/agent_controller.py +++ b/opendevin/controller/agent_controller.py @@ -1,30 +1,33 @@ import asyncio from typing import Callable, List, Type - from opendevin import config -from opendevin.schema.config import ConfigType from opendevin.action import ( Action, - AgentFinishAction, AgentDelegateAction, + AgentFinishAction, NullAction, ) +from opendevin.action.tasks import TaskStateChangedAction +from opendevin.agent import Agent +from opendevin.controller.action_manager import ActionManager +from opendevin.exceptions import ( + AgentMalformedActionError, + AgentNoActionError, + LLMOutputError, + MaxCharsExceedError, +) +from opendevin.logger import opendevin_logger as logger from opendevin.observation import ( - Observation, - AgentErrorObservation, AgentDelegateObservation, + AgentErrorObservation, NullObservation, + Observation, ) -from opendevin.agent import Agent -from opendevin.exceptions import AgentMalformedActionError, AgentNoActionError, MaxCharsExceedError, LLMOutputError -from opendevin.logger import opendevin_logger as logger from opendevin.plan import Plan -from opendevin.state import State - -from opendevin.action.tasks import TaskStateChangedAction from opendevin.schema import TaskState -from opendevin.controller.action_manager import ActionManager +from opendevin.schema.config import ConfigType +from opendevin.state import State MAX_ITERATIONS = config.get(ConfigType.MAX_ITERATIONS) MAX_CHARS = config.get(ConfigType.MAX_CHARS) diff --git a/opendevin/logger.py b/opendevin/logger.py index 1e90f1457795..709dcd2dc02a 100644 --- a/opendevin/logger.py +++ b/opendevin/logger.py @@ -3,10 +3,11 @@ import sys import traceback from datetime import datetime -from opendevin import config from typing import Literal, Mapping + from termcolor import colored +from opendevin import config from opendevin.schema.config import ConfigType DISABLE_COLOR_PRINTING = ( diff --git a/opendevin/main.py b/opendevin/main.py index 686174e5754f..a97ab1447751 100644 --- a/opendevin/main.py +++ b/opendevin/main.py @@ -3,8 +3,8 @@ from typing import Type import agenthub # noqa F401 (we import this to get the agents registered) -from opendevin.config import args from opendevin.agent import Agent +from opendevin.config import args from opendevin.controller import AgentController from opendevin.llm.llm import LLM diff --git a/opendevin/observation/__init__.py b/opendevin/observation/__init__.py index 2c4c29e5a9e3..2a4dc83dca82 100644 --- a/opendevin/observation/__init__.py +++ b/opendevin/observation/__init__.py @@ -1,11 +1,11 @@ -from .base import Observation, NullObservation -from .run import CmdOutputObservation +from .base import NullObservation, Observation from .browse import BrowserOutputObservation -from .files import FileReadObservation, FileWriteObservation -from .message import UserMessageObservation, AgentMessageObservation -from .recall import AgentRecallObservation from .delegate import AgentDelegateObservation from .error import AgentErrorObservation +from .files import FileReadObservation, FileWriteObservation +from .message import AgentMessageObservation, UserMessageObservation +from .recall import AgentRecallObservation +from .run import CmdOutputObservation observations = ( CmdOutputObservation, diff --git a/opendevin/observation/base.py b/opendevin/observation/base.py index b1622848cf4c..078f5b289d4a 100644 --- a/opendevin/observation/base.py +++ b/opendevin/observation/base.py @@ -1,5 +1,6 @@ import copy from dataclasses import dataclass + from opendevin.schema import ObservationType diff --git a/opendevin/observation/browse.py b/opendevin/observation/browse.py index 81e7010e4fc2..4c7c21ec252d 100644 --- a/opendevin/observation/browse.py +++ b/opendevin/observation/browse.py @@ -1,8 +1,9 @@ from dataclasses import dataclass -from .base import Observation from opendevin.schema import ObservationType +from .base import Observation + @dataclass class BrowserOutputObservation(Observation): diff --git a/opendevin/observation/delegate.py b/opendevin/observation/delegate.py index 5465fb5e2cba..3b7b586320a6 100644 --- a/opendevin/observation/delegate.py +++ b/opendevin/observation/delegate.py @@ -1,8 +1,9 @@ from dataclasses import dataclass -from .base import Observation from opendevin.schema import ObservationType +from .base import Observation + @dataclass class AgentDelegateObservation(Observation): diff --git a/opendevin/observation/error.py b/opendevin/observation/error.py index 1b500dd8f33e..ac47b4eafd68 100644 --- a/opendevin/observation/error.py +++ b/opendevin/observation/error.py @@ -1,8 +1,9 @@ from dataclasses import dataclass -from .base import Observation from opendevin.schema import ObservationType +from .base import Observation + @dataclass class AgentErrorObservation(Observation): diff --git a/opendevin/observation/files.py b/opendevin/observation/files.py index c15ad5f08c34..60112b8ef854 100644 --- a/opendevin/observation/files.py +++ b/opendevin/observation/files.py @@ -1,8 +1,9 @@ from dataclasses import dataclass -from .base import Observation from opendevin.schema import ObservationType +from .base import Observation + @dataclass class FileReadObservation(Observation): diff --git a/opendevin/observation/message.py b/opendevin/observation/message.py index 2848affbcc78..3d82166caa15 100644 --- a/opendevin/observation/message.py +++ b/opendevin/observation/message.py @@ -1,8 +1,9 @@ from dataclasses import dataclass -from .base import Observation from opendevin.schema import ObservationType +from .base import Observation + @dataclass class UserMessageObservation(Observation): diff --git a/opendevin/observation/recall.py b/opendevin/observation/recall.py index 126aee82e7db..7fffbcdffc2d 100644 --- a/opendevin/observation/recall.py +++ b/opendevin/observation/recall.py @@ -1,9 +1,10 @@ from dataclasses import dataclass from typing import List -from .base import Observation from opendevin.schema import ObservationType +from .base import Observation + @dataclass class AgentRecallObservation(Observation): diff --git a/opendevin/observation/run.py b/opendevin/observation/run.py index 09293b848f4f..aaf5476e8759 100644 --- a/opendevin/observation/run.py +++ b/opendevin/observation/run.py @@ -1,8 +1,9 @@ from dataclasses import dataclass -from .base import Observation from opendevin.schema import ObservationType +from .base import Observation + @dataclass class CmdOutputObservation(Observation): diff --git a/opendevin/plan.py b/opendevin/plan.py index efdd3566c080..7c722a8acdb1 100644 --- a/opendevin/plan.py +++ b/opendevin/plan.py @@ -1,7 +1,7 @@ from typing import List -from opendevin.logger import opendevin_logger as logger from opendevin.exceptions import PlanInvalidStateError +from opendevin.logger import opendevin_logger as logger OPEN_STATE = 'open' COMPLETED_STATE = 'completed' diff --git a/opendevin/sandbox/__init__.py b/opendevin/sandbox/__init__.py index 41611bb7e44c..feedc6436df2 100644 --- a/opendevin/sandbox/__init__.py +++ b/opendevin/sandbox/__init__.py @@ -1,8 +1,8 @@ -from .sandbox import Sandbox -from .docker.ssh_box import DockerSSHBox from .docker.exec_box import DockerExecBox from .docker.local_box import LocalBox +from .docker.ssh_box import DockerSSHBox from .e2b.sandbox import E2BBox +from .sandbox import Sandbox __all__ = [ 'Sandbox', diff --git a/opendevin/sandbox/docker/exec_box.py b/opendevin/sandbox/docker/exec_box.py index fa48071a3d49..c53c7d76dbe3 100644 --- a/opendevin/sandbox/docker/exec_box.py +++ b/opendevin/sandbox/docker/exec_box.py @@ -2,22 +2,22 @@ import concurrent.futures import os import sys +import tarfile import time import uuid -import tarfile -from glob import glob from collections import namedtuple +from glob import glob from typing import Dict, List, Tuple import docker from opendevin import config +from opendevin.exceptions import SandboxInvalidBackgroundCommandError from opendevin.logger import opendevin_logger as logger -from opendevin.sandbox.sandbox import Sandbox -from opendevin.sandbox.process import Process from opendevin.sandbox.docker.process import DockerProcess +from opendevin.sandbox.process import Process +from opendevin.sandbox.sandbox import Sandbox from opendevin.schema import ConfigType -from opendevin.exceptions import SandboxInvalidBackgroundCommandError InputType = namedtuple('InputType', ['content']) OutputType = namedtuple('OutputType', ['content']) diff --git a/opendevin/sandbox/docker/local_box.py b/opendevin/sandbox/docker/local_box.py index 44fa3e2b6ff0..2dcf1e923c78 100644 --- a/opendevin/sandbox/docker/local_box.py +++ b/opendevin/sandbox/docker/local_box.py @@ -1,13 +1,14 @@ -import subprocess import atexit import os +import subprocess import sys -from typing import Tuple, Dict -from opendevin.sandbox.sandbox import Sandbox -from opendevin.sandbox.process import Process -from opendevin.sandbox.docker.process import DockerProcess -from opendevin.logger import opendevin_logger as logger +from typing import Dict, Tuple + from opendevin import config +from opendevin.logger import opendevin_logger as logger +from opendevin.sandbox.docker.process import DockerProcess +from opendevin.sandbox.process import Process +from opendevin.sandbox.sandbox import Sandbox from opendevin.schema.config import ConfigType # =============================================================================== diff --git a/opendevin/sandbox/docker/ssh_box.py b/opendevin/sandbox/docker/ssh_box.py index 8a6063cd4001..7982c12844ea 100644 --- a/opendevin/sandbox/docker/ssh_box.py +++ b/opendevin/sandbox/docker/ssh_box.py @@ -1,25 +1,25 @@ import atexit import os import sys +import tarfile import time import uuid -import tarfile -from glob import glob from collections import namedtuple +from glob import glob from typing import Dict, List, Tuple, Union import docker from pexpect import pxssh from opendevin import config +from opendevin.exceptions import SandboxInvalidBackgroundCommandError from opendevin.logger import opendevin_logger as logger -from opendevin.sandbox.sandbox import Sandbox -from opendevin.sandbox.process import Process from opendevin.sandbox.docker.process import DockerProcess from opendevin.sandbox.plugins import JupyterRequirement, SWEAgentCommandsRequirement +from opendevin.sandbox.process import Process +from opendevin.sandbox.sandbox import Sandbox from opendevin.schema import ConfigType from opendevin.utils import find_available_tcp_port -from opendevin.exceptions import SandboxInvalidBackgroundCommandError InputType = namedtuple('InputType', ['content']) OutputType = namedtuple('OutputType', ['content']) diff --git a/opendevin/sandbox/e2b/sandbox.py b/opendevin/sandbox/e2b/sandbox.py index ef7d53beb2bf..d95e1f6548ec 100644 --- a/opendevin/sandbox/e2b/sandbox.py +++ b/opendevin/sandbox/e2b/sandbox.py @@ -2,17 +2,18 @@ import tarfile from glob import glob from typing import Dict, Tuple + from e2b import Sandbox as E2BSandbox from e2b.sandbox.exception import ( TimeoutException, ) from opendevin import config -from opendevin.schema.config import ConfigType from opendevin.logger import opendevin_logger as logger -from opendevin.sandbox.sandbox import Sandbox from opendevin.sandbox.e2b.process import E2BProcess from opendevin.sandbox.process import Process +from opendevin.sandbox.sandbox import Sandbox +from opendevin.schema.config import ConfigType class E2BBox(Sandbox): diff --git a/opendevin/sandbox/plugins/__init__.py b/opendevin/sandbox/plugins/__init__.py index 15053253a5b6..5ea90bd9ffe4 100644 --- a/opendevin/sandbox/plugins/__init__.py +++ b/opendevin/sandbox/plugins/__init__.py @@ -1,8 +1,7 @@ -from .mixin import PluginMixin -from .requirement import PluginRequirement - # Requirements from .jupyter import JupyterRequirement +from .mixin import PluginMixin +from .requirement import PluginRequirement from .swe_agent_commands import SWEAgentCommandsRequirement __all__ = ['PluginMixin', 'PluginRequirement', 'JupyterRequirement', 'SWEAgentCommandsRequirement'] diff --git a/opendevin/sandbox/plugins/jupyter/__init__.py b/opendevin/sandbox/plugins/jupyter/__init__.py index a9c3214cf20b..abedf467fe23 100644 --- a/opendevin/sandbox/plugins/jupyter/__init__.py +++ b/opendevin/sandbox/plugins/jupyter/__init__.py @@ -1,5 +1,6 @@ import os from dataclasses import dataclass + from opendevin.sandbox.plugins.requirement import PluginRequirement diff --git a/opendevin/sandbox/plugins/jupyter/execute_cli b/opendevin/sandbox/plugins/jupyter/execute_cli index 3fca4c534f84..0d697c1100cd 100755 --- a/opendevin/sandbox/plugins/jupyter/execute_cli +++ b/opendevin/sandbox/plugins/jupyter/execute_cli @@ -2,6 +2,7 @@ import os import sys import time + import requests # Read the Python code from STDIN diff --git a/opendevin/sandbox/plugins/jupyter/execute_server b/opendevin/sandbox/plugins/jupyter/execute_server index e5af086ea7fb..3362b9cc02db 100755 --- a/opendevin/sandbox/plugins/jupyter/execute_server +++ b/opendevin/sandbox/plugins/jupyter/execute_server @@ -1,16 +1,16 @@ #!/usr/bin/env python3 -import os -import re import asyncio -import tornado import logging +import os +import re +from uuid import uuid4 -from tornado.escape import json_encode, json_decode, url_escape -from tornado.websocket import websocket_connect -from tornado.ioloop import PeriodicCallback +import tornado +from tornado.escape import json_decode, json_encode, url_escape from tornado.httpclient import AsyncHTTPClient, HTTPRequest -from uuid import uuid4 +from tornado.ioloop import PeriodicCallback +from tornado.websocket import websocket_connect logging.basicConfig(level=logging.INFO) diff --git a/opendevin/sandbox/plugins/mixin.py b/opendevin/sandbox/plugins/mixin.py index af9f26972712..9ca0b467dfa7 100644 --- a/opendevin/sandbox/plugins/mixin.py +++ b/opendevin/sandbox/plugins/mixin.py @@ -1,5 +1,6 @@ import os from typing import List, Protocol, Tuple + from opendevin.logger import opendevin_logger as logger from opendevin.sandbox.plugins.requirement import PluginRequirement diff --git a/opendevin/sandbox/plugins/swe_agent_commands/__init__.py b/opendevin/sandbox/plugins/swe_agent_commands/__init__.py index 7bf41173841b..465edf636a2a 100644 --- a/opendevin/sandbox/plugins/swe_agent_commands/__init__.py +++ b/opendevin/sandbox/plugins/swe_agent_commands/__init__.py @@ -1,8 +1,11 @@ import os -from typing import List from dataclasses import dataclass, field +from typing import List + from opendevin.sandbox.plugins.requirement import PluginRequirement -from opendevin.sandbox.plugins.swe_agent_commands.parse_commands import parse_command_file +from opendevin.sandbox.plugins.swe_agent_commands.parse_commands import ( + parse_command_file, +) def _resolve_to_cur_dir(filename): diff --git a/opendevin/sandbox/sandbox.py b/opendevin/sandbox/sandbox.py index fcbcfc5ab2af..cf5e56432a08 100644 --- a/opendevin/sandbox/sandbox.py +++ b/opendevin/sandbox/sandbox.py @@ -1,9 +1,8 @@ from abc import ABC, abstractmethod -from typing import Dict -from typing import Tuple +from typing import Dict, Tuple -from opendevin.sandbox.process import Process from opendevin.sandbox.plugins.mixin import PluginMixin +from opendevin.sandbox.process import Process class Sandbox(ABC, PluginMixin): diff --git a/opendevin/server/agent/manager.py b/opendevin/server/agent/manager.py index 55840355873b..5ae0fd6e216d 100644 --- a/opendevin/server/agent/manager.py +++ b/opendevin/server/agent/manager.py @@ -1,7 +1,8 @@ import atexit -from opendevin.server.session import session_manager from opendevin.logger import opendevin_logger as logger +from opendevin.server.session import session_manager + from .agent import AgentUnit diff --git a/opendevin/server/auth/auth.py b/opendevin/server/auth/auth.py index 81b73cec1f93..6429743be7b0 100644 --- a/opendevin/server/auth/auth.py +++ b/opendevin/server/auth/auth.py @@ -1,9 +1,11 @@ import os -import jwt from typing import Dict -from opendevin.logger import opendevin_logger as logger + +import jwt from jwt.exceptions import InvalidTokenError +from opendevin.logger import opendevin_logger as logger + JWT_SECRET = os.getenv('JWT_SECRET', '5ecRe7') diff --git a/opendevin/server/listen.py b/opendevin/server/listen.py index 68d831138e3e..7a0cee9e4731 100644 --- a/opendevin/server/listen.py +++ b/opendevin/server/listen.py @@ -11,9 +11,9 @@ import agenthub # noqa F401 (we import this to get the agents registered) from opendevin import config, files -from opendevin.schema.config import ConfigType from opendevin.agent import Agent from opendevin.logger import opendevin_logger as logger +from opendevin.schema.config import ConfigType from opendevin.server.agent import agent_manager from opendevin.server.auth import get_sid_from_token, sign_token from opendevin.server.session import message_stack, session_manager diff --git a/opendevin/server/session/manager.py b/opendevin/server/session/manager.py index 1301cc0e9432..09525edbd458 100644 --- a/opendevin/server/session/manager.py +++ b/opendevin/server/session/manager.py @@ -1,11 +1,12 @@ import atexit import json import os -from typing import Dict, Callable +from typing import Callable, Dict from fastapi import WebSocket from opendevin.logger import opendevin_logger as logger + from .msg_stack import message_stack from .session import Session diff --git a/opendevin/server/session/msg_stack.py b/opendevin/server/session/msg_stack.py index 22d2c6e45d59..d362022a5e75 100644 --- a/opendevin/server/session/msg_stack.py +++ b/opendevin/server/session/msg_stack.py @@ -1,12 +1,11 @@ -import os -import json import atexit +import json +import os import uuid from typing import Dict, List -from opendevin.schema.action import ActionType from opendevin.logger import opendevin_logger as logger - +from opendevin.schema.action import ActionType CACHE_DIR = os.getenv('CACHE_DIR', 'cache') MSG_CACHE_FILE = os.path.join(CACHE_DIR, 'messages.json') diff --git a/opendevin/server/session/session.py b/opendevin/server/session/session.py index 3f880dc063bc..19130e781507 100644 --- a/opendevin/server/session/session.py +++ b/opendevin/server/session/session.py @@ -1,9 +1,10 @@ import time -from typing import Dict, Callable +from typing import Callable, Dict from fastapi import WebSocket, WebSocketDisconnect from opendevin.logger import opendevin_logger as logger + from .msg_stack import message_stack DEL_DELT_SEC = 60 * 60 * 5 diff --git a/opendevin/state.py b/opendevin/state.py index 7aa1e834cd3a..c3d02c9c726a 100644 --- a/opendevin/state.py +++ b/opendevin/state.py @@ -1,15 +1,14 @@ from dataclasses import dataclass, field -from typing import List, Tuple, Dict - -from opendevin.plan import Plan +from typing import Dict, List, Tuple from opendevin.action import ( Action, ) from opendevin.observation import ( - Observation, CmdOutputObservation, + Observation, ) +from opendevin.plan import Plan @dataclass diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 228b421e081f..92042f27fbe9 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -1,5 +1,5 @@ -import re import os +import re from functools import partial import pytest diff --git a/tests/integration/test_agent.py b/tests/integration/test_agent.py index 137425f18e24..d1f55e9eaaee 100644 --- a/tests/integration/test_agent.py +++ b/tests/integration/test_agent.py @@ -1,5 +1,5 @@ -import os import asyncio +import os import subprocess import pytest diff --git a/tests/test_fileops.py b/tests/test_fileops.py index e657ac7dc841..3f22422a6658 100644 --- a/tests/test_fileops.py +++ b/tests/test_fileops.py @@ -1,9 +1,10 @@ -from opendevin import config -from opendevin.schema import ConfigType -from opendevin.action import fileop from pathlib import Path + import pytest +from opendevin import config +from opendevin.action import fileop +from opendevin.schema import ConfigType def test_resolve_path(): diff --git a/tests/unit/test_action_github.py b/tests/unit/test_action_github.py index 570613ec51cf..bb26f5d66070 100644 --- a/tests/unit/test_action_github.py +++ b/tests/unit/test_action_github.py @@ -1,16 +1,17 @@ -from opendevin import config +from unittest.mock import MagicMock, call, patch + +import pytest + from agenthub.dummy_agent.agent import DummyAgent +from opendevin import config from opendevin.action.github import GitHubPushAction, GitHubSendPRAction from opendevin.controller.agent_controller import AgentController from opendevin.llm.llm import LLM from opendevin.observation.error import AgentErrorObservation from opendevin.observation.message import AgentMessageObservation from opendevin.observation.run import CmdOutputObservation - from opendevin.schema.config import ConfigType -import pytest -from unittest.mock import MagicMock, call, patch @pytest.fixture diff --git a/tests/unit/test_action_serialization.py b/tests/unit/test_action_serialization.py index 05d383a39977..4f7f733ca529 100644 --- a/tests/unit/test_action_serialization.py +++ b/tests/unit/test_action_serialization.py @@ -1,17 +1,17 @@ from opendevin.action import ( - action_from_dict, Action, + AddTaskAction, + AgentFinishAction, + AgentRecallAction, AgentThinkAction, + BrowseURLAction, CmdKillAction, CmdRunAction, - BrowseURLAction, - GitHubPushAction, FileReadAction, FileWriteAction, - AgentRecallAction, - AgentFinishAction, - AddTaskAction, + GitHubPushAction, ModifyTaskAction, + action_from_dict, ) diff --git a/tests/unit/test_arg_parser.py b/tests/unit/test_arg_parser.py index 6c140f795ae8..73e8e811b69e 100644 --- a/tests/unit/test_arg_parser.py +++ b/tests/unit/test_arg_parser.py @@ -1,7 +1,7 @@ -from opendevin.config import get_parser - import pytest +from opendevin.config import get_parser + def test_help_message(capsys): parser = get_parser() diff --git a/tests/unit/test_observation_serialization.py b/tests/unit/test_observation_serialization.py index e75efc0a14c6..e7870f88bf0a 100644 --- a/tests/unit/test_observation_serialization.py +++ b/tests/unit/test_observation_serialization.py @@ -1,4 +1,8 @@ -from opendevin.observation import observation_from_dict, Observation, CmdOutputObservation +from opendevin.observation import ( + CmdOutputObservation, + Observation, + observation_from_dict, +) def test_observation_serialization_deserialization():