Run Autonomous Async • AI Agent SDK

run_autonomous_async: Async variant of run_autonomous() for concurrent agent execution.

run_autonomous_async

Async

Method

</div>

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

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

Parameters

ParamField str

The task to execute

ParamField Optional[int]

Override max iterations (default from config)

ParamField Optional[float]

Timeout in seconds (default: no timeout)

ParamField Optional[str]

Optional string that signals completion when wrapped in &lt;promise&gt;TEXT&lt;/promise&gt; tags in the response

ParamField bool

Whether to clear chat history between iterations (forces agent to rely on external state like files)

Returns

ResponseField Any

AutonomyResult with success status, output, and metadata

Exceptions

ValueError

If autonomy is not enabled

Usage

python
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
  • is_set
  • AutonomyResult
  • achat
  • record_response
  • hash

Source

View on GitHub

praisonaiagents/agent/agent.py at line 5215


Related Documentation