Overview
When executing a message in a session, you can pass variable values using theinputs field in your request body. Variables are substituted into your agent’s system prompts and used throughout the execution.
Request Body Structure
inputs object contains key-value pairs where:
- Key: Variable name (must match a variable defined in your agent configuration)
- Value: The value for that variable (string, number, boolean, array, or object)
Variable Types: Session vs Request Level
Session-Level Variables
Session-level variables are provided once on the first execution and automatically persist across subsequent requests using checkpoints. When to use: User ID, session context, configuration that doesn’t change.- Configuration
- First Request
- Second Request
Request-Level Variables
Request-level variables must be provided on every execution. Checkpoint values are ignored. When to use: User messages, search queries, form submissions—anything that changes per request.- Configuration
- Every Request
Complete Example: Conversational Support Agent
This example shows a support agent that uses both session-level and request-level variables.Configuration
First Request: Initialize Session
Second Request: Continue Conversation
user_idanduser_emailload from checkpoint (not provided in request)current_messageis fresh: “How long will the refund take?”- Agent has full context from first message + new query
- Response is personalized to this customer
Supported Data Types
Variables use BAML type notation. You can pass:| Type | Example | Use Case |
|---|---|---|
str | "hello" | Text values |
int | 42 | Numbers without decimals |
float | 3.14 | Decimal values |
bool | true | Yes/no flags |
list[str] | ["item1", "item2"] | Multiple tags or selections |
list[int] | [1, 2, 3] | Multiple numeric values |
dict[str, int] | {"key": 1, "key2": 2} | Key-value data |
str | None | "value" or null | Optional text |
Automatic Type Coercion
String values in JSON are automatically converted to match your variable’s declared type:max_retries is typed as int, it becomes the integer 5.
Type conversions:
"42"→42(forinttype)"true"or"1"→True(forbooltype)"[1,2,3]"→[1, 2, 3](forlist[int]type)
Common Patterns
Pattern 1: Conversational Loop
Use request-level variables for user messages in a multi-turn conversation:Pattern 2: Configuration + Queries
Store configuration once, run many queries:Error Handling
Required Variable Missing
required: true variables are provided on first execution.
Variable Not Defined
If you provide a variable name that isn’t defined in your configuration:Type Mismatch
If type coercion fails:Best Practices
Use Descriptive Names
Provide Descriptions
Set Sensible Defaults
Enable Persistent State
Troubleshooting
Variables not persisting between requests
Variables not persisting between requests
Solution: Ensure
persistent_state: true is set in your configuration.Getting stale variable values
Getting stale variable values
Solution: If you want a fresh value on every request, use
require_every_execution: true:Variables not appearing in agent prompts
Variables not appearing in agent prompts
Solution: Check that:
- Variable is defined in
variablessection - Variable name in prompt uses correct syntax:
{{ variables.name }} - Variable is provided in
inputson first execution (for required variables)
Related Documentation
- Agent Configuration Guide - Define variables in your config
- Execute Endpoint - API reference for execute
- REST API Tutorial - Full integration guide