How to Debug Dropped or Failed Agent Runs in AutoGPT

Enable debug logging with the --debug flag to expose the run_interaction_loop internals, then monitor for InvalidAgentResponseError parsing failures, AgentTerminated exceptions, and cycle budget exhaustion in autogpt/app/main.py to pinpoint why an agent stops unexpectedly.

Debugging dropped or failed agent runs in AutoGPT requires tracing execution through the main interaction loop and error handling logic in the Significant-Gravitas/AutoGPT repository. By enabling verbose logging and inspecting specific exception types—InvalidAgentResponseError for malformed LLM outputs and AgentTerminated for intentional stops—you can identify whether a failure stems from parsing errors, exhausted cycle budgets, or command execution faults.

Enable Debug Logging

Start every debugging session by activating the debug output mode. The CLI parser in autogpt/app/cli.py exposes the --debug flag, which propagates to configure_logging(debug=debug, ...) inside autogpt/app/main.py (lines 65–99).

Run the agent with debug output visible:

autogpt --debug

This call configures the forge.logging.config module to set the logging level to DEBUG, ensuring all logger.debug statements within the interaction loop become visible. If you use the Python API directly, pass debug=True to the entry function to trigger the same configuration.

Trace the Interaction Loop

The core execution logic resides in run_interaction_loop within autogpt/app/main.py (lines 41–108). This function manages the agent’s lifecycle, decrementing the cycle budget and catching exceptions on each iteration.

Look for these debug lines in your console output:

DEBUG:run_interaction_loop:Cycle budget: 5; remaining: 5

The helper function _get_cycle_budget (lines 21–30) determines the total allowed cycles based on the continuous and continuous_limit settings. If the budget reaches zero, the loop exits cleanly. When the agent stops prematurely, verify that the initial budget matches your expectations—without the --continuous flag, the default budget is 1, causing the agent to halt after a single cycle.

Identify Thought Parsing Failures

When the LLM returns malformed JSON or an invalid ActionProposal, the code raises InvalidAgentResponseError (defined in forge/utils/exceptions.py). The handler in run_interaction_loop logs a warning and increments an internal consecutive_failures counter.

Watch for this warning pattern:

WARNING:The agent's thoughts could not be parsed: <error details>

After three consecutive failures, the loop terminates with a fatal error:

ERROR:The agent failed to output valid thoughts 3 times in a row. Terminating...

When you see these messages, inspect the preceding debug logs to view the raw LLM output that failed parsing. Often, this indicates API quota limits, model hallucinations, or prompt engineering issues that break the expected JSON schema.

Handle Agent Termination Events

The AgentTerminated exception signals an intentional stop, raised either by the user interrupt handler (graceful_agent_interrupt) or internally within autogpt/agents/agent.py. The top-level exception catcher in run_auto_gpt (lines 338–352) handles this by persisting state before exit.

Check for this info message to confirm a graceful termination:

INFO:Saving state of <agent_id>...

If the process exits without this message, the failure likely occurred outside the termination handler—check for unhandled exceptions in command execution or parsing logic instead.

Inspect Tool Execution Errors

After the agent produces a valid thought, it executes the proposed tool via await agent.execute(action_proposal). Failures at this stage generate warning logs showing the specific command and error:

WARNING:Command <tool_name> returned an error: <error_description>

Inspect the result.status and result.error fields in the debug output to distinguish between network issues, authentication failures, and invalid tool arguments. These errors do not immediately terminate the agent unless the exception propagates uncaught, but they may cause the agent to enter a loop of retrying failed commands.

Validate Continuous Mode Configuration

A common cause of "dropped" runs is misconfigured cycle limits. Ensure you understand the relationship between the CLI flags and the _get_cycle_budget logic:

  • Without --continuous: The cycle budget defaults to 1, requiring user confirmation after every step.
  • With --continuous: The agent runs until the task completes or hits the default limit.
  • With --continuous-limit N: Sets a hard cap of N cycles regardless of completion status.

If your agent stops after exactly one cycle, verify that you launched with --continuous or increased the --continuous-limit to match your expected runtime.

Summary

  • Enable --debug to activate configure_logging and expose internal loop counters in autogpt/app/main.py.
  • Monitor consecutive_failures; three InvalidAgentResponseError instances trigger an automatic AgentTerminated exception.
  • Check cycle budget lines to confirm _get_cycle_budget allocated sufficient iterations for your task.
  • Review Command … returned an error warnings to diagnose tool execution failures after agent.execute(action_proposal).
  • Look for Saving state of info messages to distinguish graceful terminations from crashes.

Frequently Asked Questions

How do I enable debug mode in AutoGPT?

Pass the --debug flag when launching from the CLI, or set debug=True when calling the Python API. This triggers configure_logging in autogpt/app/main.py (lines 65–99), setting the logging level to DEBUG and printing all internal loop messages, including cycle budgets and raw LLM responses.

Why does my agent stop after "The agent failed to output valid thoughts"?

This error appears after three consecutive InvalidAgentResponseError exceptions in run_interaction_loop (lines 15–27 of autogpt/app/main.py). It indicates the LLM returned three malformed responses that could not be parsed into an ActionProposal. Enable --debug to see the raw unparsable output, then consider switching models via --smart-llm or --fast-llm if the issue persists.

Why does the agent quit after only one cycle without asking for input?

The default cycle_budget is 1 when the --continuous flag is absent, as calculated by _get_cycle_budget (lines 21–30). The agent executes one step, then exits because the budget reaches zero. Run with --continuous or specify --continuous-limit N to allow multiple autonomous cycles.

How can I ensure the agent saves state when I interrupt it?

Press Ctrl-C twice or set --continuous-limit 1 before starting. The graceful_agent_interrupt handler catches the first SIGINT and initiates a delayed termination, logging INFO:Saving state of <agent_id>.... A second interrupt forces immediate exit. If cycles_remaining is high when the first interrupt occurs, the agent may continue briefly before saving; setting a low limit ensures rapid state preservation.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →