Skip to main content

run_autonomous_async

AsyncMethod
This is a method of the Agent class in the agent module.
Async variant of run_autonomous() for concurrent agent execution. This method executes a task autonomously using async I/O, enabling multiple agents to run concurrently without blocking. 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

async def run_autonomous_async(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

import asyncio

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

    asyncio.run(main())

Uses

  • ValueError
  • time_module.time
  • isoformat
  • datetime.now
  • get_recommended_stage
  • AutonomyResult
  • achat
  • clear_history
  • asyncio.sleep

Source

View on GitHub

praisonaiagents/agent/agent.py at line 2114