mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-30 03:00:41 -04:00
Uncouple Copilot task execution from the REST API server. This should help performance and scalability, and allows task execution to continue regardless of the state of the user's connection. - Resolves #12023 ### Changes 🏗️ - Add `backend.copilot.executor`->`CoPilotExecutor` (setup similar to `backend.executor`->`ExecutionManager`). This executor service uses RabbitMQ-based task distribution, and sticks with the existing Redis Streams setup for task output. It uses a cluster lock mechanism to ensure a task is only executed by one pod, and the `DatabaseManager` for pooled DB access. - Add `backend.data.db_accessors` for automatic choice of direct/proxied DB access Chat requests now flow: API → RabbitMQ → CoPilot Executor → Redis Streams → SSE Client. This enables horizontal scaling of chat processing and isolates long-running LLM operations from the API service. - Move non-API Copilot stuff into `backend.copilot` (from `backend.api.features.chat`) - Updated import paths for all usages - Move `backend.executor.database` to `backend.data.db_manager` and add methods for copilot executor - Updated import paths for all usages - Make `backend.copilot.db` RPC-compatible (-> DB ops return ~~Prisma~~ Pydantic models) - Make `backend.data.workspace` RPC-compatible - Make `backend.data.graphs.get_store_listed_graphs` RPC-compatible DX: - Add `copilot_executor` service to Docker setup Config: - Add `Config.num_copilot_workers` (default 5) and `Config.copilot_executor_port` (default 8008) - Remove unused `Config.agent_server_port` > [!WARNING] > **This change adds a new microservice to the system, with entrypoint `backend.copilot.executor`.** > The `docker compose` setup has been updated, but if you run the Platform on something else, you'll have to update your deployment config to include this new service. > > When running locally, the `CoPilotExecutor` uses port 8008 by default. ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - [x] Copilot works - [x] Processes messages when triggered - [x] Can use its tools #### For configuration changes: - [x] `.env.default` is updated or already compatible with my changes - [x] `docker-compose.yml` is updated or already compatible with my changes - [x] I have included a list of my configuration changes in the PR description (under **Changes**) --------- Co-authored-by: Zamil Majdy <zamil.majdy@agpt.co>
60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
import logging
|
|
from typing import TYPE_CHECKING
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
if TYPE_CHECKING:
|
|
from backend.util.process import AppProcess
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def run_processes(*processes: "AppProcess", **kwargs):
|
|
"""
|
|
Execute all processes in the app. The last process is run in the foreground.
|
|
Includes enhanced error handling and process lifecycle management.
|
|
"""
|
|
try:
|
|
# Run all processes except the last one in the background.
|
|
for process in processes[:-1]:
|
|
process.start(background=True, **kwargs)
|
|
|
|
# Run the last process in the foreground.
|
|
processes[-1].start(background=False, **kwargs)
|
|
finally:
|
|
for process in processes:
|
|
try:
|
|
process.stop()
|
|
except Exception as e:
|
|
logger.exception(f"[{process.service_name}] unable to stop: {e}")
|
|
|
|
|
|
def main(**kwargs):
|
|
"""
|
|
Run all the processes required for the AutoGPT-server (REST and WebSocket APIs).
|
|
"""
|
|
|
|
from backend.api.rest_api import AgentServer
|
|
from backend.api.ws_api import WebsocketServer
|
|
from backend.copilot.executor.manager import CoPilotExecutor
|
|
from backend.data.db_manager import DatabaseManager
|
|
from backend.executor import ExecutionManager, Scheduler
|
|
from backend.notifications import NotificationManager
|
|
|
|
run_processes(
|
|
DatabaseManager().set_log_level("warning"),
|
|
Scheduler(),
|
|
NotificationManager(),
|
|
WebsocketServer(),
|
|
AgentServer(),
|
|
ExecutionManager(),
|
|
CoPilotExecutor(),
|
|
**kwargs,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|