> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes. # RunContext > Context object available inside tool handler functions. [agentsession]: /docs/server-sdks/reference/typescript/agents/livewire/agent-session [functiontool]: /docs/server-sdks/reference/typescript/agents/livewire/function-tool `RunContext` is passed to tool handler functions via the `context` parameter's `ctx` property. It provides access to the current [`AgentSession`][agentsession] and its user data, letting tools read and modify session state. ```typescript {7} import { tool, RunContext } from '@signalwire/sdk/livewire'; const savePreference = tool<{ color: string }>({ description: 'Save the user\'s favorite color.', parameters: { color: { type: 'string' } }, execute: (params, { ctx }) => { const data = ctx.userData as Record; data.favoriteColor = params.color; return `Got it, your favorite color is ${params.color}.`; }, }); ``` ## **Constructor** ```typescript {1} new RunContext(session: AgentSession) ``` The `RunContext` is constructed internally by `AgentSession` when dispatching tool calls. You do not need to create it manually. ## **Properties** **`session`** `AgentSession` The [`AgentSession`][agentsession] that owns this context. --- **`userData`** `UserData` Shortcut for `session.userData`. Returns the user data attached to the session. --- ## **Example** ```typescript {13} import { Agent, AgentSession, tool, RunContext, defineAgent, runApp, JobContext, } from '@signalwire/sdk/livewire'; interface SessionData { notes: string[]; } const addNote = tool<{ note: string }>({ description: 'Add a note to the session.', parameters: { note: { type: 'string' } }, execute: (params, { ctx }) => { const data = ctx.userData as SessionData; data.notes.push(params.note); return `Note saved. You have ${data.notes.length} note(s).`; }, }); const agentDef = defineAgent({ entry: async (ctx: JobContext) => { const agent = new Agent({ instructions: 'You are a note-taking assistant.', tools: { addNote }, }); const session = new AgentSession({ userData: { notes: [] }, }); await session.start({ agent }); }, }); runApp(agentDef); ``` > Context object available inside tool handler functions.