Skip to main content

Variables System

The AMAS Variables System provides a powerful way to define, populate, and use dynamic values throughout your agent configurations. Variables can be populated from user inputs, agent structured outputs, or defined with static defaults.

Overview

Variables enable:
  • Dynamic prompts - Inject context into agent system prompts using {{ variables.name }}
  • Input overrides - User-provided inputs override variable defaults at runtime
  • Automatic population - Extract data from agent structured outputs via variable_assignments
  • Persistence - Variables persist across executions when using checkpoints

Defining Variables

Variables are defined in the variables section of your configuration:

Variable Properties

If required is false and no default is set, validation will fail with: “Variable must either be required=True or have a default value set”.

Variable Lifecycle

Understanding when variables are required is crucial for proper configuration:

Session-Level Variables

These are required on the first execution only and persist via checkpoints:
When the user provides inputs: {"current_user_id": "user_123"}, this value is stored in the variable and persists across subsequent executions.
  • Set once at session start
  • Persist across all subsequent executions in the session
  • Ideal for: user identity, session context, preferences

Request-Level Variables

These must be provided on every execution:
  • Fresh value required for each request
  • Checkpoint values are ignored for these variables
  • Ideal for: user messages, request-specific data

Providing Inputs

Inputs are values provided at runtime that override variable defaults. The input key must match the variable name.

Via REST API

Send inputs in the request body:
The inputs object keys correspond directly to variable names defined in your configuration.

Via Playground UI

Use the Variable Inputs panel to provide values:
  1. Click the input field next to each variable
  2. Enter the value
  3. Variables with required: true must be filled before execution
  4. Variables with defaults show the default value as placeholder
Variable Inputs Panel
The Variable Inputs panel shows all defined variables with their descriptions and current values.

Using Variables in Prompts

Reference variables in agent prompts using Jinja2 syntax:

Template Syntax

Variables are accessed in system_prompt using {{ variables.name }} syntax. The substitution engine also supports other template variables — see Prompt Configuration for the full list.
The substitution engine uses regex-based {{ ... }} matching, not Jinja2 filters. Expressions like {{ variables.name | default('x') }} are not supported. Unknown variables resolve to an empty string.

Reserved Variable Names

The following names cannot be used for custom variables: user_input, history, full_history, prompts, variables. Using a reserved name causes a validation error.

Variable Assignments

The most powerful feature: automatically populate variables from agent structured outputs.

How It Works

  1. Agent generates structured output using structured_output configuration
  2. Variable assignments map output fields to variables
  3. Downstream agents receive populated variables in their prompts

Configuration

Assignment Patterns

Variable assignments support three patterns:

1. Structured output field (most common)

  • variable_name — The variable to populate (must be defined in variables)
  • agent_name — The agent that produces the output
  • output — Fixed keyword
  • field_name — The field from the structured output schema

2. Non-structured agent output

Assigns the text content of the agent’s last message. Useful for agents without structured output.

3. Static value assignment

Assigns a constant value directly. Type is validated against the variable’s declared type.

Nested Fields

For nested structured output data, use dot-separated paths:

Type Coercion

During variable assignment, values are automatically coerced to match the type specified in your variable definition. This means you can assign strings from user input or non-structured agent output, and the system will intelligently convert them:
  • Numbers: Strings like "42" become 42 (int), "3.14" becomes 3.14 (float)
  • Booleans: Strings like "true" or "1" become true; "false" or "0" become false
  • Collections: Valid JSON strings are parsed into dict or list types (e.g., list[str])
If type coercion fails, the system safely falls back to the original raw value. This coercion applies seamlessly to dynamic outputs, static values, and the final combined string when using concat mode.

Concat Mode Example

Build a progressive story where each agent adds a sentence:
Execution flow:
  • Initial: "Once upon a time"
  • After run 1: "Once upon a time there was a brave knight."
  • After run 2: "Once upon a time there was a brave knight. He embarked on a quest."
  • After run 3: "Once upon a time there was a brave knight. He embarked on a quest. The journey was perilous."

Best Practices

1. Use Descriptive Names

2. Provide Helpful Descriptions

Descriptions appear in the UI and help users understand what to provide:

3. Set Sensible Defaults

4. Separate Session vs Request Variables

Clearly distinguish between persistent and per-request variables:

5. Validate Required Variables

Use required: true for critical session variables:

Troubleshooting

Variable Not Populated

Symptom: Variable shows empty or default value in prompt Causes:
  1. Agent didn’t produce structured output
  2. Assignment path is incorrect
  3. Field name doesn’t match schema
Solution: Check the agent’s structured output schema matches the assignment path:

Required Variable Error

Symptom: “Required variable ‘X’ not provided” Cause: Variable with required: true wasn’t provided in inputs Solution: Provide the variable in your API request or UI:

Variables Not Persisting

Symptom: Variables reset between executions Cause: persistent_state not enabled or using new session Solution: Enable checkpoints in configuration:

API Reference

Variable Definition Schema

Variable Assignment Schema

Execution Request

Supported Types

All types supported by the BAML type parser: