Skip to content

Jinja2 Templates

The system (train) message is rendered through a Jinja2 template before every request. This is how you inject memory, config and dynamic context into the system prompt.

Template Context

The template receives these variables:

VariableMeaning
trainThe raw train message
memoryThe session MemoryModel (messages, etc.)
chatobjThe current ChatObject
configThe runtime AmritaConfig
jinja2_varsYour custom variables (merged in)
jinja2
You are a helpful assistant.
Today is {{ memory.metadata.today }}.
User prefers: {{ jinja2_vars.user_language }}

Pass custom variables via ChatObject(..., jinja2_vars={...}) or agent.get_chatobject(..., jinja2_vars={...}).

Variable Naming Safety

You CANNOT use keys that match built-in variable names (train, memory, chatobj, config) in jinja2_vars — Python would receive duplicate keyword arguments and raise TypeError. Pick any other name.

Best Practices

  • Keep the template small; push instructions into it, not whole conversations
  • Use the config variable to toggle behavior per deployment
  • Render-time errors surface immediately — validate templates with the workflow debugger before shipping

Next

Troubleshooting — the common failure modes and fixes.

Apache 2.0 License