Context variables
A context variable is a named fact the agent keeps while it performs tasks for a customer, such as an order number or a delivery postcode, so it doesn’t have to ask twice.
Where: Agent → Context variables.
Declare a variable
Section titled “Declare a variable”- In a sandbox, open Agent → Context variables and select Declare variable.
- Fill in the form:
| Field | Choices | Choose |
|---|---|---|
| Name | Lowercase letters, digits and underscores | Something obvious, like order_number |
| Type | string, number, boolean | string for codes, even all-digit ones; number for amounts |
| Lasts for | The conversation, or one turn | Almost always the conversation. One turn is forgotten once the reply is sent |
| When set again | Keep the latest non-empty value, or always take the latest | Keep the latest non-empty, unless an empty value should clear it |
| Where the value comes from | Extracted from the conversation, or a tool | See below |
- Save it, then try it in the test chat.
Check it worked: in Conversations, the conversation’s side panel shows the variable with its value.
Variables reach Live through a release, like instructions.
From the conversation
Section titled “From the conversation”The agent picks the value out of what the customer writes.
- What to look for: a plain description, such as “The parcel tracking number from the dispatch email, for example KP123456789”.
- Pattern (optional): a regular expression the value must match, such as
^KP[0-9]{9}$. Values that don’t match are ignored. A pattern only applies to text variables. Check the pattern is a valid regular expression before you save it.
From a tool
Section titled “From a tool”The value is copied from a tool’s result whenever that tool succeeds.
- Tool: the tool’s exact name, such as
kaya_get_order. - Path in its result: where the value is, such as
id,order.id, oritems[0].skufor the first item. Write it without$..
The path reads the result the agent sees, which is the fields the tool’s manifest keeps in its
projection. A field the manifest drops can’t be read.
Use a variable
Section titled “Use a variable”- In the instructions: write
{{order_number}}, and the agent sees the current value. - In a specialist agent: a specialist agent is told only the
variables it’s set up to read, when work is handed to it. The console doesn’t set this yet. A
specialist agent from a manifest lists them under
context.readsin itsagent:block.
A variable lasts one conversation at most. Nothing carries over to the customer’s next conversation.
Never use a variable to decide whose data a tool may read or change. A customer can type anything, including someone else’s email address; that check belongs in your system.
If a variable stays empty, see A context variable stays empty.