Run Autonomous Async • AI Agent SDK
run_autonomous_async: Async variant of run_autonomous() for concurrent agent execution.
run_autonomous_async
Async
Method
</div>
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) -> AnyParameters
strThe task to execute
Optional[int]Override max iterations (default from config)
Optional[float]Timeout in seconds (default: no timeout)
Optional[str]Optional string that signals completion when wrapped in <promise>TEXT</promise> tags in the response
boolWhether to clear chat history between iterations (forces agent to rely on external state like files)
Returns
AnyAutonomyResult with success status, output, and metadata
Exceptions
ValueError
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
ValueErrortime_module.timeisoformatdatetime.nowget_recommended_stageis_setAutonomyResultachatrecord_responsehash
Source
View on GitHubpraisonaiagents/agent/agent.py at line 5215