Running a YAML-defined crew (the
praisonai CLI/SDK, agents.yaml) from async code? Use agenerate_crew_and_kickoff() — see Async Crew Kickoff. This page covers async with the praisonaiagents Agent/AgentTeam API.Quick Start
- Code
- No Code
Requirements
- Python 3.10 or higher
- OpenAI API key. Generate OpenAI API key here. Use Other models using this guide.
- Basic understanding of async/await in Python
Understanding Async Execution
What is Asynchronous Execution?
Async execution lets your program continue running while waiting for operations to complete. This is ideal for:
- Making multiple AI API calls
- Processing large datasets
- Handling multiple tasks simultaneously
- Maintaining responsive applications
Features
Async Tasks
Create tasks that run asynchronously with built-in error handling and retries.
Parallel Processing
Run multiple tasks in parallel using asyncio.gather().
Mixed Mode
Mix sync and async tasks in the same workflow seamlessly.
Resource Management
Built-in resource management and performance optimization.
Advanced Usage
- Code
- No Code
Best Practices
Error Handling
Error Handling
Resource Management
Resource Management
Performance Tips
Performance Tips
- Use
asyncio.gather()for parallel operations - Implement proper error handling
- Monitor memory usage
- Use timeouts for long-running operations
Sync ↔ Async Bridge
The async bridge utilities help you safely move between sync and async contexts without deadlocking the event loop:Troubleshooting
ChatCompletion Error
If you see “ChatCompletion can’t be used in await expression”:
- Use AsyncOpenAI() client
- Ensure proper async context
Event Loop Error
If you get “Event loop is closed”:
- Use asyncio.run() for main entry
- Check async context
Event Loop Running Error
RuntimeError: This event loop is already running from SDK internals:- Upgrade to the latest release with async bridge support
- Internal call sites now use run_coroutine_from_any_context()
Agent Chat Hangs
If
await agent.achat(...) never returns (sync agent.chat() works fine):- Upgrade to the release that includes PR #1704 (or newer)
- Earlier versions had a missing response-handling branch in the unified async dispatch path that caused the call to loop indefinitely
- No code change required after upgrade — the call returns on the first LLM round-trip
API Reference
Async Methods
Async version of chat method
Async tool execution method
Async task execution starter
Task Properties
Enable/disable async mode for tasks
Set sync or async callback function (async callbacks are dispatched safely even when the caller is inside a running event loop)
Next Steps
AutoAgents
Learn about automatically created and managed AI agents
Mini Agents
Explore lightweight, focused AI agents
Remember to handle errors properly, manage resources efficiently, and test thoroughly in async contexts.

