AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(agent server): Updated function names and type checking (#7185)
Swiftye3a5663a0592
diff --git a/rnd/autogpt_server/autogpt_server/agent_api/__init__.py b/rnd/autogpt_server/autogpt_server/agent_api/__init__.pydeleted file mode 100644index 1ea8dc278e..0000000000--- a/rnd/autogpt_server/autogpt_server/agent_api/__init__.py+++ /dev/null@@ -1 +0,0 @@-from .server import start_server # noqadiff --git a/rnd/autogpt_server/autogpt_server/agent_executor/__init__.py b/rnd/autogpt_server/autogpt_server/agent_executor/__init__.pydeleted file mode 100644index e79245e20f..0000000000--- a/rnd/autogpt_server/autogpt_server/agent_executor/__init__.py+++ /dev/null@@ -1 +0,0 @@-from .executor import start_executors # noqadiff --git a/rnd/autogpt_server/autogpt_server/agent_executor/executor.py b/rnd/autogpt_server/autogpt_server/agent_executor/executor.pydeleted file mode 100644index d5daed5ee7..0000000000--- a/rnd/autogpt_server/autogpt_server/agent_executor/executor.py+++ /dev/null@@ -1,42 +0,0 @@-import logging-import time-from concurrent.futures import ThreadPoolExecutor-from multiprocessing import Process--from autogpt_server.data import ExecutionQueue--logger = logging.getLogger(__name__)---class AgentExecutor:- # TODO: Replace this by an actual Agent Execution.- def __execute(id: str, data: str) -> None:- logger.warning(f"Executor processing started, execution_id: {id}, data: {data}")- for i in range(5):- logger.warning(- f"Executor processing step {i}, execution_id: {id}, data: {data}"- )- time.sleep(1)- logger.warning(- f"Executor processing completed, execution_id: {id}, data: {data}"- )-- def start_executor(pool_size: int, queue: ExecutionQueue) -> None:- with ThreadPoolExecutor(max_workers=pool_size) as executor:- while True:- execution = queue.get()- if not execution:- time.sleep(1)- continue- executor.submit(- AgentExecutor.__execute,- execution.execution_id,- execution.data,- )---def start_executors(pool_size: int, queue: ExecutionQueue) -> None:- executor_process = Process(- target=AgentExecutor.start_executor, args=(pool_size, queue)- )- executor_process.start()diff --git a/rnd/autogpt_server/autogpt_server/app.py b/rnd/autogpt_server/autogpt_server/app.pyindex 5b8bf81d7b..51598bb3a2 100644--- a/rnd/autogpt_server/autogpt_server/app.py+++ b/rnd/autogpt_server/autogpt_server/app.py@@ -1,11 +1,11 @@-from autogpt_server.agent_api import start_server-from autogpt_server.agent_executor import start_executors+from autogpt_server.server import start_server+from autogpt_server.executor import start_executor_managerfrom autogpt_server.data import ExecutionQueuedef main() -> None:queue = ExecutionQueue()- start_executors(5, queue)+ start_executor_manager(5, queue)start_server(queue)diff --git a/rnd/autogpt_server/autogpt_server/data.py b/rnd/autogpt_server/autogpt_server/data.pyindex 5fbc184c09..87d332451e 100644--- a/rnd/autogpt_server/autogpt_server/data.py+++ b/rnd/autogpt_server/autogpt_server/data.py@@ -22,7 +22,7 @@ class ExecutionQueue:"""def __init__(self):- self.queue = Queue()+ self.queue: Queue[Execution] = Queue()def add(self, data: str) -> str:execution_id = uuid.uuid4()diff --git a/rnd/autogpt_server/autogpt_server/executor/__init__.py b/rnd/autogpt_server/autogpt_server/executor/__init__.pynew file mode 100644index 0000000000..15c23958a9--- /dev/null+++ b/rnd/autogpt_server/autogpt_server/executor/__init__.py@@ -0,0 +1 @@+from .executor import start_executor_manager # type: ignore # noqadiff --git a/rnd/autogpt_server/autogpt_server/executor/executor.py b/rnd/autogpt_server/autogpt_server/executor/executor.pynew file mode 100644index 0000000000..c64ff2cb9c--- /dev/null+++ b/rnd/autogpt_server/autogpt_server/executor/executor.py@@ -0,0 +1,38 @@+import logging+import time+from concurrent.futures import ThreadPoolExecutor+from multiprocessing import Process++from autogpt_server.data import Execution, ExecutionQueue++logger = logging.getLogger(__name__)+++# TODO: Replace this by an actual Agent Execution.+def execute_node(id: str, data: str) -> None:+ logger.warning(f"Executor processing started, execution_id: {id}, data: {data}")+ for i in range(5):+ logger.warning(+ f"Executor processing step {i}, execution_id: {id}, data: {data}"+ )+ time.sleep(1)+ logger.warning(f"Executor processing completed, execution_id: {id}, data: {data}")+++def start_executor(pool_size: int, queue: ExecutionQueue) -> None:+ with ThreadPoolExecutor(max_workers=pool_size) as executor:+ while True:+ execution: Execution | None = queue.get()+ if not execution:+ time.sleep(1)+ continue+ executor.submit(+ execute_node,+ execution.execution_id,+ execution.data,+ ) # type: ignore+++def start_executor_manager(pool_size: int, queue: ExecutionQueue) -> None:+ executor_process = Process(target=start_executor, args=(pool_size, queue))+ executor_process.start()diff --git a/rnd/autogpt_server/autogpt_server/server/__init__.py b/rnd/autogpt_server/autogpt_server/server/__init__.pynew file mode 100644index 0000000000..cc9d9bb566--- /dev/null+++ b/rnd/autogpt_server/autogpt_server/server/__init__.py@@ -0,0 +1 @@+from .server import start_server # type: ignore # noqadiff --git a/rnd/autogpt_server/autogpt_server/agent_api/server.py b/rnd/autogpt_server/autogpt_server/server/server.pysimilarity index 99%rename from rnd/autogpt_server/autogpt_server/agent_api/server.pyrename to rnd/autogpt_server/autogpt_server/server/server.pyindex cbbdb018cd..adc827a29d 100644--- a/rnd/autogpt_server/autogpt_server/agent_api/server.py+++ b/rnd/autogpt_server/autogpt_server/server/server.py@@ -5,7 +5,6 @@ from autogpt_server.data import ExecutionQueueclass AgentServer:-def __init__(self, queue: ExecutionQueue):self.app = FastAPI(title="AutoGPT Agent Server",diff --git a/rnd/autogpt_server/test/test_app.py b/rnd/autogpt_server/test/test_app.pyindex 2707d07668..5040c3bd76 100644--- a/rnd/autogpt_server/test/test_app.py+++ b/rnd/autogpt_server/test/test_app.py@@ -1,19 +1,19 @@import pytest+from fastapi.testclient import TestClient+from autogpt_server.server import start_server+from autogpt_server.executor import start_executor_managerfrom autogpt_server.data import ExecutionQueue-from autogpt_server.agent_api import start_server-from autogpt_server.agent_executor import start_executors-from fastapi.testclient import TestClient@pytest.fixturedef client():execution_queue = ExecutionQueue()- start_executors(5, execution_queue)+ start_executor_manager(5, execution_queue)return TestClient(start_server(execution_queue, use_uvicorn=False))-def test_execute_agent(client):+def test_execute_agent(client: TestClient):# Assert API is workingresponse = client.post("/agents/dummy_agent_1/execute")assert response.status_code == 200