- Deliver values to the run by using a JWT token, an API payload, or an embedded-chat event.
- Declare which variables an agent can access in its definition.
- Reference those variables in the agent’s instructions, descriptions, or guidelines so the runtime injects their values into the model prompt.
- Persist values across turns by resending them in each subsequent call.
- Context variables in the embedded chat
- Providing access to context variables in native agents
- Providing access to context variables in external agents
- Using context variables in Python tools
Types of context variables
Context variables are either system variables, which the platform populates automatically, or custom variables, which your application supplies.System variables
System variables are predefined variables whose values the platform populates automatically. By default, agents cannot access any system variable. You must explicitly list each one in the agent’scontext_variables field to expose it.
Custom variables
Custom variables are values that your application defines and passes to a run. Use them to carry any data that the agent or a tool needs, such asclientID, role, locale, or selected_product.
To make a custom variable available to an agent, declare it in the context_variables field of the agent definition:
Naming rules
Follow these rules when you name custom context variables. Violations are not always reported as errors and can cause silent collisions or parsing failures:- Do not use the
wxo_prefix. It is reserved for system variables. Using it can cause collisions with platform-managed values. - Do not use hyphens (
-). They can cause parsing errors. Use underscores (_) instead. - Use distinct names for JWT-supplied and API-payload-supplied variables. If the same name appears in both, the JWT value takes precedence. For more information, see Precedence.
Delivering context variables to a run
You can deliver context to a run in the following ways. The right method depends on how stable the value is and where it originates.JWT token
Embed context in the signed JWT that authenticates the embedded chat. Because the JWT is signed server-side, clients cannot tamper with its values, and neither a tool, an agentic workflow, nor the API payload can overwrite a variable that is delivered in the JWT. If you need to update a value during a session, omit it from the JWT and pass it in the API payload instead. Use this method when:- The value is tied to user identity, such as user ID, role, organization, tenant identifier, or permission level.
- The value does not change during the session.
API payload
Pass context as a dictionary in thecontext field of the request body when you call one of these endpoints:
Use this method when:
- The value changes between turns or is not available at JWT-signing time.
- The client must update a value without reissuing a JWT.
Embedded chat pre:send event
When you embed the chat, the host page can inject or modify context per message by using the pre:send event handler, before the message is sent to the runtime.
- The value changes per message or varies during the session.
- The host page resolves the value at send time, such as current page, form state, or selected profile.
Configuring an agent to use context variables
By default, agents invoked during a run cannot access context variables. You must explicitly enable access at the agent level and list each variable individually. A variable that exists in the run but is not listed is not available to the agent.context_access_enabled
Set context_access_enabled: true in the agent definition to allow the agent to read context variables. When this field is false (the default), context variables are present in the run but the agent cannot read them.
context_variables
After you enable access, use the context_variables field to specify exactly which variables the agent can read. This field acts as an allowlist: only the variables listed here are available to the agent during execution.
Variables declared in context_variables can be system variables or custom variables.
Referencing variables in the agent definition
After you declare a variable incontext_variables, reference it anywhere in the agent’s instructions, description, or guidelines by wrapping its name in curly braces: {variable_name}. The runtime substitutes the live value at execution time.
Injection is opt-in per variable. A variable that is present in the run but not listed in
context_variables, or not referenced with {...} in the instructions, descriptions, or guidelines, is not injected into the model prompt.Example: exposing system and custom variables
The following agent definition makeswxo_email_id and four custom variables available. The platform supplies the value of wxo_email_id, and your application supplies the rest.
wxo_email_idis a system variable. Because it is listed incontext_variables, the platform injects its value. The agent can reference it as{wxo_email_id}in the instructions.name,role,user_name, andemail_idare custom variables that your application passes in the run payload or JWT.wxo_user_name,wxo_tenant_id,wxo_thread_id, andwxo_run_idare not listed, so they are not available to this agent.
Precedence
When the same variable name appears in both the JWT and the API payload (orpre:send injection), the JWT value takes precedence.
context field: the Runs API, the Chat Completions API, and the Streaming Chat Completions API.
To avoid conflicts, use distinct variable names for stable JWT context and dynamic payload context, or omit a variable from the JWT if you intend to update it from the client.
Persisting context across turns
Context is scoped to a single run. Values, including any updates that a tool writes during that run, are available only within that one invocation. The runtime does not carry them forward to the next message automatically. Context does not persist across a thread. The platform does not retain context values between runs. If your use case requires values to survive across multiple turns in a conversation, your client application must carry them forward explicitly.Embedded chat event handlers
Use thepre:receive event to read the context that is returned in the agent response and hold it in client-side state. Then reinject it on the next pre:send.
Re-send by using the API payload
Include the context values again in each API request. Every run response returns the current context state, so your application can read the values and pass them back in the next call. The context is returned in the following locations:- Streaming responses: in the
message.createdandrun.completedevents. - Non-streaming responses: in the message that is associated with the run.
Tool support
Only Python tools and agentic workflows can read and update context variables. All other tool types cannot access the run context. Updates that a tool writes are visible to all tools that are called later in the same run but are not persisted after the run ends. If subsequent runs need those values, your client must resend them. See Persisting context across turns. Tools interact with context variables in the following ways:- Read: A tool can read any context variable that is present in the run, including system variables such as
wxo_email_id. This lets tools act on user identity, session data, or any custom value that the client passes. - Update: A tool can write new values or overwrite existing custom variables during a run. Updates are visible to all tools that are called later in the same run. Tools cannot update system variables (
wxo_*).
Channel support
The mechanisms described in this topic for delivering, updating, and persisting context are not available through channel integrations. For channels such as Slack or Teams, context support is limited to a fixed set of read-only values that the platform supplies from the channel session, such as the sender identifier or channel type. Custom context variables, tool updates, and cross-turn persistence are not supported. For more information, see Channel-specific context variables. If your use case requires custom context variables through a channel, you might need a custom implementation.These limitations for channels do not apply to embedded chat. The full context-variable capabilities described in this topic are available through the embedded chat integration.

