What are the benefits passing RunContext vs AgentS...
# ask-ai
d
What are the benefits passing RunContext vs AgentSession
t
Thanks for reaching out, Billy. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd love to help you better! Could you share a bit more about the specific situation where you're choosing between passing
RunContext
and
AgentSession
? For instance, are you working on a certain API, feature, or integration? Understanding this will help me guide you more effectively.
d
just tell me the difference and what they both do
t
Let me help clarify the difference between
RunContext
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