Agent Autonomy

Control how independently agents operate – from suggestions to full automation

Autonomy controls how independently an agent operates — from requiring approval for every action to fully autonomous execution. The mode field determines whether start() uses a single chat() call ("caller") or a multi-turn loop ("iterative").

Diagram

Autonomy Levels

More control

Balanced

Hands-off

💬 Suggest
Ask before acting

✏️ Auto Edit
Edit without asking

🚀 Full Auto
Complete autonomy

👤 User

Which Mode Should I Choose?

Not sure which mode fits your task? Use this guide:

Diagram

No

Yes

Yes

No

🤔 What’s your task?

Need multiple\nback-and-forth\niterations?

✅ Caller Mode\n(default)\nautonomy=True

Need the agent to\nplan → act → verify\nrepeatedly?

🔄 Iterative Mode\nautonomy={‘mode’: ‘iterative’}

💬 Interactive Mode\nNo autonomy needed

Single turn\n1 LLM call\nFastest

Multi-turn loop\nSelf-correcting\nFor complex tasks

Human-driven\nConversational\nYou control the pace

ModeBest ForExample PromptWhat Happens
No autonomyQuestions, explanations, advice“Explain authentication patterns”Agent answers from knowledge — doesn’t touch files or run tools
Caller (default)Single-shot automation, pipelines“Search for X and save to file”Agent uses tools in one turn, returns AutonomyResult
IterativeMulti-step self-correction“Refactor auth module and verify tests”Agent loops with doom loop protection until done

Quick Start

  1. Enable Autonomy
    python
    from praisonaiagents import Agent
    
    # Caller mode (default) — single chat(), returns AutonomyResult
    agent = Agent(
        name="Autonomous Agent",
        instructions="You help with coding tasks",
        autonomy=True  # mode="caller" by default
    )
    
    result = agent.start("Refactor the authentication module")
    print(result.success)            # True
    print(result.completion_reason)  # "caller_mode"
  2. With Configuration
    python
    from praisonaiagents import Agent
    
    # Iterative mode — multi-turn autonomous loop
    agent = Agent(
        name="Full Auto Agent",
        instructions="You manage files and code",
        autonomy={
            "level": "full_auto",             # mode defaults to "iterative"
            "max_iterations": 30,
            "doom_loop_threshold": 5,
            "completion_promise": "DONE",
        }
    )
  3. Explicit Mode Override
    python
    from praisonaiagents import Agent
    
    # Force iterative loop even at suggest level
    agent = Agent(
        name="Iterative Agent",
        instructions="Work through complex tasks",
        autonomy={
            "mode": "iterative",
            "max_iterations": 15,
            "completion_promise": "COMPLETE",
        }
    )

Architecture

The autonomy system spans the Core SDK and Wrapper CLI, unified through bridging:

Diagram

Agent

Core SDK (praisonaiagents)

Wrapper CLI (praisonai)

to_sdk_level

bridge env var

set_mode

recommend_stage

auto_save

propagate

AutonomyMode
CLI Enum

AutonomyLevel
SDK Enum

AutonomyPolicy

ApprovalRegistry

AutonomyManager

AutonomyConfig
level field

AutonomyTrigger

AutonomyStage

DoomLoopTracker

run_autonomous

Memory/Session

Agent

AgentTeam

Key design decisions:

  • Single source of truth: AutonomyLevel enum lives in the SDK; CLI’s AutonomyMode derives from it
  • Bridge via env var: CLI’s FULL_AUTO mode sets PRAISONAI_AUTO_APPROVE=true for SDK approval
  • AgentTeam propagation: AgentTeam(autonomy=...) propagates config to all managed agents
  • Memory integration: run_autonomous() auto-saves sessions between iterations

Autonomy Stages

The agent automatically selects an execution stage based on task complexity:

Diagram

Stage: AUTONOMOUS

Multi-step task

Full autonomous loop

Stage: PLANNED

Edit/test intent

Plan then execute

Stage: HEURISTIC

File references

Context-aware response

Stage: DIRECT

Simple question

Immediate response

StageTriggersBehavior
directSimple questions, explanationsSingle response
heuristicFile references, code blocksContext-aware
plannedEdit/test intentPlan before acting
autonomousMulti-step, refactoringFull iteration loop

How Completion Works

Understanding how the agent knows when it’s “done” is key to choosing the right mode.

Diagram
ToolsLLM (GPT-4o etc.)Inner Tool LoopAgent.start()Your AppToolsLLM (GPT-4o etc.)Inner Tool LoopAgent.start()Your Apploop[Model calls tools until done]Model stopped calling tools = DONEagent.start(“Do 3 things…”)chat(prompt)Send prompt + available tools“Call internet_search(…)”Execute internet_searchSearch resultsHere are the results“Call get_system_info()”Execute get_system_infoSystem infoHere are the results“Here’s your summary…” (no more tools)Final response textAutonomyResult(success=True)

The model decides when to stop by not requesting more tools. This is the same protocol used by ChatGPT, Claude, and all major LLM APIs.

Completion SignalHow It WorksReliability
Tool completionModel used tools, then stopped requesting more⭐⭐⭐ Most reliable
Promise tagModel outputs <promise>DONE</promise>⭐⭐⭐ Explicit signal
Keyword detectionModel says “task completed”⭐⭐ Can be inconsistent
No-tool turnsModel produces text without tools for 2+ turns⭐⭐ Safety fallback
Max iterationsReached the iteration limit⭐ Last resort

Configuration Options

python
from praisonaiagents import Agent

# Using dict config
agent = Agent(
    instructions="You help with coding tasks",
    autonomy={
        "max_iterations": 30,
        "doom_loop_threshold": 5,
        "auto_escalate": True,
    }
)
OptionTypeDefaultDescription
enabledboolTrueWhether autonomy is enabled
levelstr"suggest"Autonomy level: suggest, auto_edit, full_auto
modestrSmart default"caller" (single chat) or "iterative" (loop). Defaults: suggest/auto_edit → "caller", full_auto → "iterative"
max_iterationsint20Maximum iterations (iterative mode only)
doom_loop_thresholdint3Repeated actions to trigger doom loop
auto_escalateboolTrueAutomatically escalate complexity
observeboolFalseEmit observability events

Doom Loop Detection

Prevents agents from getting stuck in repetitive failure patterns:

Diagram
UserDetectorAgentUserDetectorAgentloop[Attempt 1-3]Try actionLog failureDetect patternStop loopRequest help
python
agent = Agent(
    instructions="You fix bugs",
    autonomy={
        "doom_loop_threshold": 3,  # Stop after 3 similar failures
    }
)

Escalation Pipeline

When an agent can’t complete a task, it escalates:

Diagram

Escalation Flow

Fail

Fail

🔄 Try

🔄 Retry

⬆️ Escalate

👤 Human

🧠 Stronger Model

python
agent = Agent(
    instructions="You solve complex problems",
    autonomy={
        "auto_escalate": True,  # Enable escalation
        "max_iterations": 20,   # Max attempts before escalating
    }
)

Signal Detection

Autonomy uses heuristics to detect task complexity:

python
# Signals detected from prompts
SIMPLE_KEYWORDS = {"what is", "explain", "describe"}
COMPLEX_KEYWORDS = {"refactor", "implement", "debug", "fix"}
EDIT_KEYWORDS = {"edit", "modify", "change", "update"}
Diagram

Yes

No

Yes

No

📝 Prompt

🔍 Analyze

Simple?

⚡ Direct Response

Complex?

📋 Plan First

🎯 Heuristic


Use Cases


Best Practices

Start with caller mode (default)

Most tasks complete in a single turn. The model calls all needed tools and summarizes — no iteration loop needed. Only switch to iterative when you need multi-turn self-correction.

Use completion promises for iterative mode

Set completion_promise for reliable termination in iterative mode. The agent outputs <promise>DONE</promise> when finished.

Keep doom loop threshold low

Keep doom_loop_threshold at 3-5 to prevent runaway agents and wasted resources.

Monitor with observe mode

Set observe=True during development to track agent behavior and stage escalation.


Related