Skip to main content

run_autonomous

Method
This is a method of the Agent class in the agent module.
Run an autonomous task execution loop. This method executes a task autonomously, using the agent’s tools and capabilities to complete the task. It handles:
  • Progressive escalation based on task complexity
  • Doom loop detection and recovery
  • Iteration limits and timeouts
  • Completion detection (keyword-based or promise-based)
  • Optional context clearing between iterations

Signature

def run_autonomous(prompt: str, max_iterations: Optional[int], timeout_seconds: Optional[float], completion_promise: Optional[str], clear_context: bool) -> Any

Parameters

prompt
str
required
The task to execute
max_iterations
Optional
Override max iterations (default from config)
timeout_seconds
Optional
Timeout in seconds (default: no timeout)
completion_promise
Optional
Optional string that signals completion when wrapped in <promise>TEXT</promise> tags in the response
clear_context
bool
default:"False"
Whether to clear chat history between iterations (forces agent to rely on external state like files)

Returns

Returns
Any
AutonomyResult with success status, output, and metadata

Exceptions

If autonomy is not enabled

Usage

agent = Agent(instructions="...", autonomy=True)
    result = agent.run_autonomous(
        "Refactor the auth module",
        completion_promise="DONE",
        clear_context=True
    )
    if result.success:
        print(result.output)