For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
GuidesReference
GuidesReference
    • Core
      • Overview
    • Agents
      • Overview
      • AgentBase
      • AgentServer
      • Configuration
      • ContextBuilder
      • DataMap
      • FunctionResult
      • Helper Functions & Utilities
      • LiveWire
        • Agent
        • AgentSession
        • Infrastructure
        • Plugins
        • runApp
        • RunContext
        • Signals
        • tool / FunctionTool
      • PomBuilder
      • Prefabs
      • SkillBase
      • SkillManager
      • SkillRegistry
      • Skills
      • SwaigFunction
      • SwmlBuilder
      • SWMLService
    • RELAY
      • Overview
      • Actions
      • Call
      • Constants
      • Events
      • Message
      • RelayClient
      • RelayError
    • REST Client
      • Overview
      • Addresses
      • Calling
      • ChatResource
      • Compat
      • Datasphere
      • Fabric
      • ImportedNumbersResource
      • Logs
      • LookupResource
      • MFA
      • Number Groups
      • Phone Numbers
      • Project
      • PubSubResource
      • Queues
      • Recordings
      • Registry
      • RestClient
      • RestError
      • Short Codes
      • SIP Profile
      • Verified Callers
      • Video
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • Constructor
  • Properties
  • Example
AgentsLiveWire

RunContext

|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

Signals

Next
Built with

RunContext<UserData> is passed to tool handler functions via the context parameter’s ctx property. It provides access to the current AgentSession and its user data, letting tools read and modify session state.

1import { tool, RunContext } from '@signalwire/sdk/livewire';
2
3const savePreference = tool<{ color: string }>({
4 description: 'Save the user\'s favorite color.',
5 parameters: { color: { type: 'string' } },
6 execute: (params, { ctx }) => {
7 const data = ctx.userData as Record<string, string>;
8 data.favoriteColor = params.color;
9 return `Got it, your favorite color is ${params.color}.`;
10 },
11});

Constructor

1new RunContext<UserData>(session: AgentSession<UserData>)

The RunContext is constructed internally by AgentSession when dispatching tool calls. You do not need to create it manually.

Properties

session
AgentSession<UserData>

The AgentSession that owns this context.

userData
UserData

Shortcut for session.userData. Returns the user data attached to the session.

Example

1import {
2 Agent, AgentSession, tool, RunContext, defineAgent, runApp, JobContext,
3} from '@signalwire/sdk/livewire';
4
5interface SessionData {
6 notes: string[];
7}
8
9const addNote = tool<{ note: string }>({
10 description: 'Add a note to the session.',
11 parameters: { note: { type: 'string' } },
12 execute: (params, { ctx }) => {
13 const data = ctx.userData as SessionData;
14 data.notes.push(params.note);
15 return `Note saved. You have ${data.notes.length} note(s).`;
16 },
17});
18
19const agentDef = defineAgent({
20 entry: async (ctx: JobContext) => {
21 const agent = new Agent({
22 instructions: 'You are a note-taking assistant.',
23 tools: { addNote },
24 });
25
26 const session = new AgentSession<SessionData>({
27 userData: { notes: [] },
28 });
29
30 await session.start({ agent });
31 },
32});
33
34runApp(agentDef);