Skip to main content
Variables allow you to inject dynamic values into your agent prompts. You can provide session-level variables once and have them persist across multiple requests, or request-level variables that must be provided fresh on each execution.

Overview

When executing a message in a session, you can pass variable values using the inputs field in your request body. Variables are substituted into your agent’s system prompts and used throughout the execution.

Request Body Structure

The 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.

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.

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

Response:

Second Request: Continue Conversation

What happens:
  • user_id and user_email load from checkpoint (not provided in request)
  • current_message is 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:

Automatic Type Coercion

String values in JSON are automatically converted to match your variable’s declared type:
If max_retries is typed as int, it becomes the integer 5. Type conversions:
  • "42"42 (for int type)
  • "true" or "1"True (for bool type)
  • "[1,2,3]"[1, 2, 3] (for list[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:
Configuration variables persist; you only provide fresh queries each time.

Error Handling

Required Variable Missing

Solution: Ensure all required: true variables are provided on first execution.

Variable Not Defined

If you provide a variable name that isn’t defined in your configuration:
It’s silently ignored. Only variables defined in your agent configuration are used.

Type Mismatch

If type coercion fails:

Best Practices

Use Descriptive Names

Provide Descriptions

Set Sensible Defaults

Enable Persistent State

Troubleshooting

Solution: Ensure persistent_state: true is set in your configuration.
Solution: If you want a fresh value on every request, use require_every_execution: true:
Solution: Check that:
  1. Variable is defined in variables section
  2. Variable name in prompt uses correct syntax: {{ variables.name }}
  3. Variable is provided in inputs on first execution (for required variables)