Running AgentGPT in the cloud is convenient for five-minute experiments, but the hosted version hits a wall the moment you demand serious multi-step automation. Public cloud instances enforce aggressive execution timeouts, loop caps, and rigid token quotas designed to protect shared infrastructure. When you need an autonomous agent to crawl technical documentation, plan recursive subtasks, and persist execution logs without sudden termination, local deployment is the only path forward.
At 365Finds, our evaluation is straightforward: self-hosting AgentGPT via Docker Compose gives you complete control over agent iteration depth and memory, but it shifts the cost and loop-safety burdens directly onto your shoulders. Here is the operational playbook to set up AgentGPT locally, configure your custom OpenAI and search keys, and keep your containers from burning through API budgets in infinite loops.
System Architecture and Prerequisites
AgentGPT is not a standalone Python script. It is a multi-tier microservice architecture comprising three distinct workloads:
- Frontend (
next): A Next.js 13 web interface running on port3000, handling user interactions, agent state visualization, and runtime settings. - Platform Backend (
platform): A FastAPI Python service running on port8000, orchestrating the LangChain execution loops, task queues, and agent thought decomposition. - Database (
db): A MySQL 8.0 instance running on port3306, storing execution runs, agent configurations, and session histories managed via Prisma ORM.
Before cloning the repository, verify that your machine has the following tools installed and active:
- Docker and Docker Desktop: Ensure the Docker daemon is running with at least 4 GB of allocated RAM and 2 CPUs.
- Git: For source version control.
- Node.js (v18+): Required if you choose the interactive CLI initialization script.
- API Keys: A funded OpenAI API key (
sk-...). 365Finds strongly recommends acquiring a Serper API key as well; without live web retrieval, AgentGPT's recursive task decomposition quickly devolves into an echo chamber of model hallucinations.
Method 1: The Automated Setup Script
The maintainers at Reworkd provide a bootstrapped setup wizard for rapid deployment. If you want the fastest route from zero to a running interface, execute the platform setup script:
git clone https://github.com/reworkd/AgentGPT.git
cd AgentGPT
./setup.sh
(On Windows environments using PowerShell or CMD, run ./setup.bat instead.)
The wizard inspects your local environment, prompts you for deployment preferences, and writes the required environment variable files. When prompted:
- Choose Docker-compose (Recommended) as your runtime mode.
- Input your OpenAI API Key when prompted by the CLI.
- Enter optional keys, such as SERPER_API_KEY, to enable internet browsing capabilities.
The script provisions the Docker network, pulls container base images, runs Prisma schema migrations against the MySQL container, and starts all three services.
Method 2: Production-Grade Manual Docker Compose
At 365Finds, our engineering preference leans toward direct docker compose orchestration rather than shell wrappers. Wrapper scripts obscure environment drift and make continuous integration or headless server deployment unnecessarily opaque.
Step 1: Clone and Inspect Directory Structure
git clone https://github.com/reworkd/AgentGPT.git
cd AgentGPT
The repository separates the Next.js frontend into ./next and the FastAPI platform backend into ./platform.
Step 2: Configure Environment Variables
Create and configure your .env file in the ./next directory. Copy the provided sample template:
cp ./next/.env.example ./next/.env
Open ./next/.env and update the core service and provider definitions:
# Core API Keys
OPENAI_API_KEY=sk-your-openai-api-key-here
SERPER_API_KEY=your-serper-api-key-here
# Platform Configuration
REWORKD_PLATFORM_HOST=0.0.0.0
REWORKD_PLATFORM_PORT=8000
# NextAuth and Internal Secrets
NEXTAUTH_SECRET=generate-a-random-32-char-string
NEXTAUTH_URL=http://localhost:3000
# Database Connection (Docker Internal Network)
DATABASE_URL=mysql://reworkd_platform:reworkd_platform@db:3306/reworkd_platform
[!WARNING] Do not use
localhostor127.0.0.1insideDATABASE_URLor internal backend endpoints when running within Docker. In containerized networks,localhostresolves to the individual container itself. Always use the service identifierdborplatformdefined indocker-compose.yml.
Step 3: Build and Launch Containers
Spin up the container cluster in detached mode:
docker compose up --build -d
Monitor container initialization using Docker logs:
docker compose logs -f
Once the Next.js compilation completes and the platform container connects to MySQL, open your browser and navigate to:
http://localhost:3000
Injecting and Managing Custom API Keys
AgentGPT supports two separate methods for supplying your credentials, and understanding the architectural difference between them is vital:
| Key Method | Configuration Location | Scope and Persistence | Best Use Case |
|---|---|---|---|
| System-Level Injection | ./next/.env or Docker environment block | Server-wide; shared by all users on the instance | Dedicated local development machines; automated server runs |
| Runtime UI Injection | Web UI Settings modal (gear icon) | Stored in local browser session state; overrides system defaults | Multi-user sharing; testing temporary key tiers |
Configuring Keys via the Browser UI
If you omitted your keys during the Docker setup or wish to test alternative models without rebuilding containers:
- Navigate to
http://localhost:3000. - Click the Settings gear icon in the lower-left navigation drawer.
- Select the Model tab.
- Input your custom OpenAI API Key.
- Switch the underlying engine between
gpt-3.5-turboandgpt-4depending on task complexity and budget tolerance. - Click Save.
The UI stores your key locally in the browser session, allowing you to bypass default server settings immediately.
Database Migrations and Common Pitfalls
Self-hosting AgentGPT occasionally surfaces synchronization issues during initial startup. 365Finds tracked the three most frequent points of failure:
1. Prisma Connection Failures (P1001)
During cold starts, the next or platform container often boots faster than the MySQL database engine can initialize its internal tables. This generates a PrismaClientInitializationError: Can't reach database server at db:3306.
To resolve this race condition, verify that MySQL has completed initialization:
docker compose ps
Once the database container displays healthy status, manually run the Prisma migration command inside the Next.js container:
docker compose exec next npx prisma db push
2. Port Collisions
AgentGPT binds to standard development ports: 3000 (Next.js), 8000 (FastAPI), and 3306 (MySQL). If you already have a local MySQL server or local backend running on host ports, Docker will fail with bind: address already in use.
Modify the host mapping in docker-compose.yml:
ports:
- "3001:3000" # Frontend mapped to 3001
- "8001:8000" # Backend mapped to 8001
- "3307:3306" # Database mapped to 3307
3. Infinite Execution Loops and API Burn
AgentGPT operates by decomposing a primary goal into recursive subtasks, assessing output, and formulating follow-up actions. Unlike traditional chat interfaces, a wandering agent can run 30 consecutive iterations without user intervention.
365Finds strongly advises two defensive guardrails:
- Configure a hard spending cap directly in your OpenAI platform billing settings before executing deep tasks.
- In the AgentGPT Settings panel, restrict the maximum task execution loop limit (defaulting to 4–8 iterations) rather than setting it to unrestricted.
docker compose down
Running docker compose down halts all microservices while preserving your database volume (db_data) on disk, ensuring execution logs and session histories remain intact for your next development run.