RunContext
RunContext is passed to tool handler functions that declare a parameter with a
RunContext type annotation. It provides access to the current
AgentSession and its
user data, letting tools read and modify session state.
The RunContext parameter is automatically detected by
@function_tool via its
type annotation and excluded from the tool’s JSON schema. You do not need to pass it
when the tool is called by the LLM.
Properties
session
The AgentSession
that owns this context. May be None if the tool is invoked outside a session.
userdata
Shortcut for session.userdata. Returns an empty dict if no session is bound.
speech_handle
Handle to the current speech output. Accepted for API compatibility.
function_call
Metadata about the function call that triggered this context. Accepted for API compatibility.