AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How to Run AgentGPT Locally with Docker and Custom API Keys

Betsy Paoletta · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

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:

  1. Frontend (next): A Next.js 13 web interface running on port 3000, handling user interactions, agent state visualization, and runtime settings.
  2. Platform Backend (platform): A FastAPI Python service running on port 8000, orchestrating the LangChain execution loops, task queues, and agent thought decomposition.
  3. Database (db): A MySQL 8.0 instance running on port 3306, 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:

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:

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 localhost or 127.0.0.1 inside DATABASE_URL or internal backend endpoints when running within Docker. In containerized networks, localhost resolves to the individual container itself. Always use the service identifier db or platform defined in docker-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 MethodConfiguration LocationScope and PersistenceBest Use Case
System-Level Injection./next/.env or Docker environment blockServer-wide; shared by all users on the instanceDedicated local development machines; automated server runs
Runtime UI InjectionWeb UI Settings modal (gear icon)Stored in local browser session state; overrides system defaultsMulti-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:

  1. Navigate to http://localhost:3000.
  2. Click the Settings gear icon in the lower-left navigation drawer.
  3. Select the Model tab.
  4. Input your custom OpenAI API Key.
  5. Switch the underlying engine between gpt-3.5-turbo and gpt-4 depending on task complexity and budget tolerance.
  6. 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:

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.

References