dazzling-truck-32153
09/20/2025, 12:41 AMtall-airline-16756
09/20/2025, 12:41 AMtall-airline-16756
09/20/2025, 12:41 AMRunContext and AgentSession? For instance, are you working on a certain API, feature, or integration? Understanding this will help me guide you more effectively.dazzling-truck-32153
09/20/2025, 8:16 AMtall-airline-16756
09/20/2025, 8:16 AMRunContext and AgentSession in LiveKit for you:
• RunContext: Think of this as a temporary context object that’s passed to a function tool while it’s running. It offers: Basically, it serves as a helpful link between one function call and the overall session.
◦ Access to the AgentSession, giving you a broader view of the session.
◦ Control over speech playout and interruptions through a SpeechHandle.
◦ Information about the current function being executed via a FunctionCall object.
◦ A userData property where you can keep session-specific data shared with external systems.
• AgentSession: This is the big picture — the full runtime environment for a voice agent. It handles: This is created once per user interaction and manages everything from start to finish during the session.
◦ Connecting to a LiveKit room and managing WebRTC media streams.
◦ Detecting turns and tracking user/agent states like "listening" or "speaking".
◦ Keeping the global conversation history with ChatContext.
◦ Maintaining a persistent userData object throughout the session.
◦ Providing methods to guide the conversation flow, such as start(), generate_reply(), and say().
To sum it up, AgentSession is like the container for the whole session, while RunContext is a temporary helper for each specific function call within that session.
Sources: Agents Core Architecture | livekit/livekit_composite | DeepWiki | tests/test_evals.py | complex-agents/vision/agent.py | agents/src/voice/index.ts