asyncio.to_thread fallback.
Quick Start
How It Works
| Method | Purpose | Async Detection |
|---|---|---|
aon_agent_start | Agent session start | Dispatches via isinstance(store, AsyncConversationStore) |
aon_user_message | User message logging | Dispatches via isinstance(store, AsyncConversationStore) |
aon_agent_message | Agent response logging | Dispatches via isinstance(store, AsyncConversationStore) |
aon_tool_call | Tool execution logging | Dispatches via isinstance(store, AsyncConversationStore) |
aon_agent_end | Agent session end | Dispatches via isinstance(store, AsyncConversationStore) |
Configuration Options
All async hooks support these signatures from the DB adapter:Common Patterns
Complete Async Lifecycle
Sync Store Compatibility
Native Async Store
Best Practices
Prefer async with for exception-safety
Prefer async with for exception-safety
Manual
aclose() is now safe and idempotent — calling it twice does nothing harmful. Prefer async with for exception-safety and readability, so cleanup runs even when an error is raised mid-block:Reusing a PraisonAIDB after close
Reusing a PraisonAIDB after close
close() and aclose() reset the internal stores, so re-entering a with db: ... block after close cleanly re-initializes instead of dispatching to closed handles:Implement async_* methods for performance
Implement async_* methods for performance
For high-throughput async applications, implement native async methods:
Handle metadata consistently
Handle metadata consistently
All hooks accept optional metadata dictionaries:
Use sync context manager for mixed environments
Use sync context manager for mixed environments
Both sync and async context managers are supported:
Related
Persistence Overview
Complete persistence system documentation
Agent Architecture
Learn about async agent patterns

