Quick Start
From an async tool
Use
run_sync_in_executor to call blocking code from an async tool without blocking the event loop:How It Works
The bridge probes for a running event loop usingasyncio.get_running_loop(). If no loop exists, it safely creates one with asyncio.run(). If a loop is already running, it raises RuntimeError to prevent deadlocks.
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
timeout | float | 300 | Maximum seconds to wait for coroutine completion |
Common Patterns
Reusing async SDKs from sync tools
Offloading blocking calls from async tools
Context-aware dual-mode helper
Best Practices
Prefer await when you're already async
Prefer await when you're already async
Calling
run_coroutine_from_any_context inside an async def raises RuntimeError by design. If you’re in a coroutine, use await instead:Don't wrap everything
Don't wrap everything
Only wrap at the true sync/async boundary. Avoid creating unnecessary bridge calls in the middle of your call stack:
Set a sensible timeout
Set a sensible timeout
The default 300 seconds is large for most use cases. Tighten for latency-critical tools:
Check is_async_context() for dual-mode helpers
Check is_async_context() for dual-mode helpers
When building utilities that work in both sync and async contexts, check the context first:
Troubleshooting
RuntimeError: run_coroutine_from_any_context() cannot be called from async context
You’re trying to use the bridge inside a coroutine. Useawait instead:
asyncio.run() cannot be called from a running event loop
This error used to leak from SDK internals before the async bridge was implemented. If you see this on current versions, upgrade to the latest release.PermissionError in approval system
The approval system now fails fast in async contexts. Configure a non-console backend:Related
Async Agents Guide
Thread Safety & Concurrency

