var
Sets one or more variables. Each key names the variable to set, and each value is the new value. The values are evaluated in the order written, so a later value can use an earlier variable.
Keys
A key is one of:
name: a local variable, visible in this function only.agent.name: an agent variable, kept for the whole conversation and visible to every function of this agent.conv.name: a conversation variable, kept for the whole conversation and shared by every agent that runs in the conversation.
Any key may be followed by an index to set one element of an existing list or dict: totals['q3'], rows[0], agent.cache['user']. The base variable must already exist.
A name starts with a letter, ends with a letter or a digit, contains only letters, digits and underscores, and is at least two characters long. Python keywords and the names sys, command, result, exc, agent, conv, const and onError cannot be used. See Variables.
Values
A value is any JSON value. A string in braces is evaluated as a Python expression, and the variable receives the result, whatever its type. Agent and conversation variables are saved with the conversation, so their values must be JSON serializable. Local variables may hold anything.
Example
"var": {
"city": "Reston",
"now": "{ datetime.now().isoformat() }",
"greeting": "{ f'Hello from {city}' }",
"agent.calls": "{ (agent.calls if sys.exists('agent', 'calls') else 0) + 1 }",
"conv.lastCity": "{ city }"
}Rules
- Assignments run top to bottom. In the example,
greetingcan usecitybecausecityis set earlier in the same command. - Reading an agent or conversation variable that has never been set raises an error. Seed it first, as the example does for
agent.callswithsys.exists. - The loop variables of an enclosing
forare ordinary locals and can be read here. Aforcommand may not reuse a name that an enclosingforalready binds.

