steep-balloon-41261
11/15/2025, 8:07 PMtall-airline-16756
11/15/2025, 8:08 PMtall-airline-16756
11/15/2025, 8:08 PMAudioStream or RecognizeStream in the LiveKit Python SDK.
Here are some friendly tips to help you resolve this:
• Make sure to cancel any tasks that are consuming the stream (such as async for loops) before you call aclose(). Using asyncio.Task can help you manage and properly cancel these tasks.
• Consider wrapping your stream usage inside async with blocks or creating custom context managers—this can make managing the lifecycle much smoother.
• Follow a clear cleanup order by canceling any dependent tasks before closing your resources, similar to how it’s handled in agent components like AvatarRunner.
• To avoid calling aclose() multiple times or concurrently, add a guard that prevents re-entry.
If any of this feels tricky or you'd like me to walk you through the implementation, please don’t hesitate to reach out—I’m here to help!
Sources: examples/agent_dispatch.py | livekit-agents/livekit/agents/voice/agent_session.py | Agent Session Management & Turn Detection | livekit/livekit_composite | Dee...