Skip to main content

Overview

The autonomous agent mode (max_loops="auto") lets an agent plan, execute, and summarize complex multi‑step tasks without you having to manually specify the number of loops. When max_loops="auto", the agent:
  • Plans the work as a set of structured subtasks
  • Executes each subtask using tools (search, file I/O, etc.)
  • Summarizes the results into a clear final answer
This page walks through a fully autonomous medical diagnosis agent that analyzes blood work results using the Swarms Python client.

How Autonomous Mode Works

Phase 1: Planning

  • The agent analyzes the main task and calls an internal planning tool (e.g., create_plan)
  • It produces a list of subtasks with:
    • step_id: unique identifier
    • description: what to do
    • priority: critical, high, medium, or low
    • dependencies: other steps that must complete first

Phase 2: Execution

For each subtask, the agent loops through:
  1. Think: Optional short reasoning step (e.g., with a think tool)
  2. Act: Calls tools (search, file, APIs, etc.)
  3. Observe: Reads tool outputs and updates its plan state
  4. Complete: Marks the subtask done when satisfied (e.g., via subtask_done)
Dependencies are respected — subtasks only run when their prerequisites are complete.

Phase 3: Summary

Once all subtasks are complete, the agent:
  • Generates a final structured summary
  • Optionally calls a completion tool (e.g., complete_task)
  • Returns the final result to your application

Tool Selection

By default, autonomous agents have access to all safe built-in tools. You can restrict which tools are available using the selected_tools parameter in agent_config:
Available tools: create_plan, think, subtask_done, complete_task, respond_to_user, create_file, update_file, read_file, list_directory, delete_file, create_sub_agent, assign_task.
run_bash is not available via the API for security reasons.

Complete Example: Autonomous Medical Diagnosis Agent

This example shows an autonomous agent that:
  • Uses the Swarms Python client to call the Agent Completions API
  • Analyzes blood work results as an expert doctor
  • Runs until it decides the task is complete using max_loops="auto"

Environment Setup

Create a .env file:
Install dependencies:

Code Example

Best Practices

  • Clear tasks: Give specific, outcome‑oriented instructions (what to produce, how many steps)
  • Tooling: Provide tools that match the work (search, scraping, file I/O, custom APIs)
  • Bounded scope: Ask for a concrete deliverable (e.g., “single markdown report”, “CSV summary”)

Key Takeaways

  • Set max_loops="auto" to let the agent decide how many reasoning/action loops are required
  • Combine planning, tools, and file operations to tackle complex research and analysis workflows
  • Prefer clear, structured tasks so the planner can create good subtasks and dependencies
For a minimal REST‑only example using /v1/agent/completions, see “Single Agent Completion (REST)” in the examples section.