AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How to Configure Custom API Keys and Execution Loop Limits in AgentGPT

Imani Barnett · 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

To stop AgentGPT from burning through your OpenAI credits or getting stuck in recursive task hallucinations, you must configure two critical safety controls: plug in your custom API key and clamp down on maximum execution loops. In the hosted AgentGPT web interface, click the Settings gear icon in the lower-left sidebar, enter your OpenAI API key in the key field, and adjust the execution loop slider down to a sensible limit (3 to 10 iterations for initial trials). If you self-host the open-source platform via Docker, enforce hard system-level boundaries in your .env configuration using OPENAI_API_KEY and NEXT_PUBLIC_MAX_LOOPS.

At 365Finds, our primary recommendation is clear: never run an autonomous agent task without a double-layer safety net. Client-side sliders alone are insufficient protection against recursive execution runaway.


Why Unbounded Agent Loops Are Dangerous

Autonomous agents like AgentGPT operate on a continuous loop: task decomposition, tool execution, output evaluation, and subsequent task creation. When an agent hits an ambiguous goal or an unparseable response, it often creates repetitive subtasks to fix its own errors.

Every subsequent iteration resends previous conversation context, task histories, and system instructions back into the model. Token consumption does not grow linearly—it compounds. Running GPT-4 over 50 recursive loops can exhaust an entire month's API budget in twenty minutes. Setting a strict loop ceiling is the only mechanical guarantee against unbounded cost spikes.


Step 1: Configure Custom API Keys

AgentGPT provides two primary operating environments: the hosted web client at agentgpt.reworkd.ai and a self-hosted Docker deployment.

In the Hosted Web Interface

  1. Launch AgentGPT in your browser.
  2. Locate the left navigation sidebar and click Settings (the gear icon).
  3. In the Settings modal, locate the OpenAI API Key field.
  4. Paste your secret key (sk-...).
  5. Under model selection, choose gpt-4o or gpt-4 for complex multi-step reasoning, or gpt-3.5-turbo for quick and inexpensive task parsing.
  6. Save your settings. The key is stored locally in your browser's localStorage and sent with requests during active sessions.

In a Self-Hosted Docker Deployment

If you run AgentGPT locally to maintain complete data privacy and bypass hosted rate limits:

  1. Open the project root folder of the cloned reworkd/AgentGPT repository.
  2. Open your .env file (copied from .env.example).
  3. Set your primary LLM and search credentials:
    OPENAI_API_KEY=sk-your-openai-api-key
    SERPER_API_KEY=your-optional-serper-key
    
  4. Rebuild and launch the containers:
    docker compose up -d --build
    

Step 2: Set Execution Loop Limits (maxLoops)

By default, demo accounts on the hosted platform are artificially throttled to 4–5 loops. When you bring your own key or run self-hosted instances, that ceiling can jump to 100 or higher—posing serious financial risk.

Web Interface Slider

  1. Open the Settings or Advanced Settings tab within the agent creation dialog.
  2. Locate the Loop Limit or Max Loops parameter.
  3. 365Finds recommends restricting this slider based on task complexity:
    • Quick lookups & outlines: 3 to 5 loops.
    • Multi-step research & synthesis: 8 to 15 loops.
    • Complex automated workflows: 20 to 25 loops maximum.
  4. Avoid setting the slider to 50+ iterations unless you actively monitor the live execution terminal.

Self-Hosted Environment Hard Caps

In self-hosted instances, users can bypass frontend sliders if environment defaults are unchecked. Lock this down directly in .env:

# Maximum loops an agent is allowed to execute
NEXT_PUBLIC_MAX_LOOPS=15
REWORKD_PLATFORM_MAX_LOOPS=15

Setting NEXT_PUBLIC_MAX_LOOPS restricts what the frontend UI can request, while REWORKD_PLATFORM_MAX_LOOPS ensures the backend FastAPI service forcibly terminates task generation once 15 turns are completed.


The Mandatory 365Finds Safety Rule: Provider-Side Hard Caps

Application-level guards can fail if local storage corrupts or browser sessions reset. 365Finds advises establishing an immutable hard ceiling directly in your OpenAI platform dashboard before entering keys into third-party tools:

  1. Navigate to platform.openai.com and open Settings > Billing > Usage limits.
  2. Set a Monthly budget limit (e.g., $20 or $50) that stops all API calls once exceeded.
  3. Set an Email notification threshold (e.g., at 50% and 75% of your cap) to catch runaway loops early.

References