Skip to main content
Dynamic variables inject user-specific context into the agent’s initial message and system prompt at runtime. Prompt validation checks that Jinja templates are syntactically correct before you save or test an agent.

Path

Manage Agent → Customize tab → Dynamic Variables

What Dynamic Variables Do

Dynamic Variables allow your AI agent to personalize its Initial Message and **System Prompt **using runtime data fetched from an external API. They replace placeholder text like:
…with real values like:
  • Rahul
  • premium
  • pending
All before the request is sent to the LLM.

Why Use Dynamic Variables?

  • Personalizes the agent’s tone, message, and instructions
  • Ensures responses are relevant to the current user context
  • Allows the same agent to adapt dynamically for different users and use cases
  • Integrates with your backend systems for context-aware conversations

Where They’re Used

Dynamic Variables can be embedded in:
  • Initial Message – The very first thing the agent says
  • System Prompt – The underlying instruction set that guides the LLM

Placeholder Syntax

  • Always wrap variable names in double curly brackets
  • Use lowercase with underscores for clarity
Examples:

How It Works

  1. Agent Invoked User starts a chat or API-triggered interaction.
  2. Variables Detected The system scans templates for {{variable_name}} placeholders.
  3. API Call Made If variables exist, the agent calls your configured Dynamic Message API.
  4. Values Returned API responds with a JSON object, e.g.:
  1. Template Compiled
Placeholders are replaced with actual values.
  1. LLM Receives Context
The prompt sent to the LLM is fully contextualized.

Example

System Prompt Template:
API Response:
Final Prompt Sent to LLM:

Best Practices

Your system prompt is treated as a Jinja2 template. That supports conditionals and loops, but requires validation before you save or test an agent.

What validation checks

  • Syntax correctness for variables, if blocks, and for loops
  • Undeclared variables referenced in the prompt
  • Proper block closures (every opening tag has a matching closing tag)

Invalid syntax behavior

If syntax errors are found:
  • Save and Test are disabled
  • A clear error message is shown
Common errors:

Validation rules

Agent behavior

  • Existing agents keep working until the system prompt is edited and saved again.
  • New and updated agents must follow Jinja formatting rules.

Valid example

Invalid example

Unclosed curly braces disable Save and Test until corrected.

Tip

If variables appear in the system prompt, declare them in pre-call variables or return them from the Dynamic Message API. Otherwise calls may fail at runtime.

Summary