AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

Configuring Loop Limits and Exporting Task Outputs in AgentGPT

365Finds Editorial
Indexed 11,430 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

Autonomous AI agents excel at decomposing high-level objectives into iterative subtasks, but recursive execution without boundaries is one of the quickest ways to drain API token balances. When an agent enters a circular reasoning loop, repeatedly attempts to parse broken web pages, or spawns infinite subtask branches, token costs can spiral within minutes. In AgentGPT (developed by Reworkd), developers and power users manage this risk through two core operational controls: hard execution loop limits and multi-format task output exports.

By establishing strict loop thresholds and token quotas before launching an agent—and extracting structured execution logs before terminating a run—teams can prototype autonomous workflows safely and predictably.


1. How AgentGPT's Recursive Loop Consumes Tokens

To understand why loop limits are critical, consider AgentGPT's core execution flow:

  1. Goal Ingestion: The agent takes a top-level goal and generates an initial array of subtasks.
  2. Task Analysis & Execution: The agent selects the first pending subtask, invokes the language model (such as GPT-3.5-Turbo or GPT-4) or external tools, and records the intermediate result.
  3. Task Creation & Refinement: Based on the result, the agent evaluates whether new subtasks must be added to the queue.
  4. Recursive Cycle: Steps 2 and 3 repeat continuously until either all subtasks are finished or a hard stop is encountered.

Each pass through this cycle constitutes an execution loop. In a standard run, each loop triggers multiple LLM calls (task analysis, tool execution, and subtask generation), each sending context history that grows with every step. Without explicit safeguards, complex or ambiguous goals can quickly exhaust thousands of tokens per minute.


2. Configuring Execution Loop Limits in the User Interface

AgentGPT provides built-in client-side governance controls located within its settings drawer and configuration pages.

Accessing Advanced Settings

  1. Open the AgentGPT web interface or your local instance.
  2. Click the Settings (⚙️) button in the left sidebar or navigate directly to /settings.
  3. Ensure you are signed in (via GitHub, Google, or Discord) or running a self-hosted instance. In the hosted version, the Advanced Settings section is disabled for unauthenticated guest sessions to protect shared infrastructure.

Configuring the Loop Slider (customMaxLoops)

Under Advanced Settings, locate the Loop configuration parameter:

When the agent reaches this configured cap, execution halts immediately, and the console displays the safety message:

The maximum number of loops have been reached, this agent is shutting down.

(In earlier releases, this was presented as: "To save your wallet, and our infrastructure costs, this agent is shutting down.")

Recommended Loop Budgets by Task Type

Complementary Cost Controls in Settings

Loop limits work best when paired with adjacent parameters in the same settings panel:


3. Real-Time Execution Lifecycle Controls

In addition to static pre-run configuration, AgentGPT provides real-time lifecycle controls directly on the console window:

Using manual pausing during early testing allows you to verify that the agent's task decomposition makes sense before letting it run autonomously.


4. Self-Hosted Backend and Environment Configuration

For developers hosting AgentGPT locally via Docker or deploying the platform on internal infrastructure, loop limits can be enforced at the backend and source levels.

Backend Environment Variable

AgentGPT's Python backend (reworkd_platform) defines application-wide settings using Pydantic. The platform exposes a dedicated environment variable for the global loop cap:

# In your .env file
REWORKD_PLATFORM_MAX_LOOPS=20

This sets the maximum execution cycles on the server side (settings.max_loops), preventing API clients from exceeding specified limits even if client settings are bypassed.

Modifying Frontend Bounds

Developers who need to expand or tighten the loop slider range can adjust the frontend source files directly:


5. Exporting Task Outputs in AgentGPT

Once an agent finishes executing—or when you pause or stop an ongoing run—you need to capture its research results and task logs. AgentGPT offers several export pathways ranging from quick client-side downloads to programmatic data access.

Console Window Export Dropdown

At the top-right corner of the agent console window (MacWindowHeader), click the Export icon (CgExport). This reveals three native export options:

  1. Copy (Clipboard):
    • Extracts the full text content of the active execution list (element.innerText), including the overarching goal, subtasks created, execution steps, and task responses.
    • Copies the structured plain text directly into the system clipboard with automatic fallback for older browsers.
  2. Image (PNG):
    • Uses the client-side html-to-image rendering engine to capture the full scrollable conversation element (element.scrollHeight).
    • Generates a high-resolution screenshot and downloads it as agent-gpt-output.png.
    • Ideal for visual reports, team presentations, or archiving execution history without formatting discrepancies.
  3. PDF Document:
    • Uses @react-pdf/renderer via the built-in PDFButton component.
    • Parses the message stream into discrete sections:
      • Agent Goal: [goal text]
      • Adding Task: [task name]
      • Executing: "[task name]": [task output and findings]
    • Automatically formats and downloads the document as my-document.pdf, providing a clean, printable summary of the completed work.

Platform Bulk & API Exports

For enterprise and scraping-oriented workflows built around the Reworkd platform:


6. Summary and Best Practices

To maintain budget predictability while leveraging AgentGPT:

  1. Set Loop Limits First: Always review the Loop slider under Settings before deploying a goal. Keep the threshold between 5 and 15 loops for exploratory tasks.
  2. Cap Max Tokens: Restrict maxTokens per call to between 1,000 and 2,000 to prevent verbosity from multiplying total costs across iterative loops.
  3. Monitor Early Iterations: Use the pause and stop controls during the initial 2–3 subtasks to ensure the agent is heading in the desired direction.
  4. Export Promptly: Download a PDF or copy execution text as soon as the agent reaches its goal or hits the loop cap, ensuring no task outputs are lost when refreshing the session.

(Note: The reworkd/AgentGPT repository was archived in January 2026. Developers running production autonomous workflows on self-hosted forks should maintain their own environment variable safeguards and export pipelines based on these established architectural patterns.)


References