Skip to main content
System templates allow you to create dynamic, context-aware prompts for your AI agents using Jinja2 templating. This guide covers everything you need to know about creating and customizing system templates.

Overview

System templates in Julep are Jinja2 templates that define the initial system prompt for your AI agents. They allow you to:
  • Create dynamic prompts that adapt based on context
  • Include user information, session data, and other variables
  • Implement conditional logic for different scenarios
  • Maintain consistency across agent interactions
  • Inject custom metadata at the message level for dynamic behavior

Template Hierarchy

Julep uses a three-level hierarchy for system templates:
  1. Agent Default Template: Defined when creating an agent
  2. Session Template: Can override the agent’s default template for specific sessions
  3. Chat Metadata: Can inject dynamic variables at the individual message level
The session template takes precedence over the agent’s default template. Chat metadata is available in both cases.

Default System Template

When you create an agent without specifying a custom template, Julep uses this default template:

Template Variables

The following variables are available in your system templates:

Core Variables

Dynamic Variables

Creating Custom Templates

Basic Example

Here’s a simple custom template for a customer service agent:

Advanced Example with Conditional Logic

Using Chat Metadata

The metadata field in chat requests allows you to pass dynamic variables that can be used in your system templates. This enables message-level customization without modifying the agent or session.

Example: Dynamic Instructions

Session vs Agent Templates

You can override an agent’s default template at the session level:
Use session templates when you need different behavior for the same agent in different contexts (e.g., customer service vs internal support).

Jinja2 Features

System templates support the full range of Jinja2 features:

Conditionals

Loops

Filters

Comments

Best Practices

Avoid overly complex templates. If your template is becoming too large, consider breaking the logic into different agents or sessions.
When using metadata, choose clear, descriptive keys:
  • metadata.customer_tier
  • metadata.ct
Always handle cases where variables might be missing:
Test your templates with various metadata combinations to ensure they render correctly in all scenarios.

Common Patterns

Multi-language Support

Role-based Access

Context-aware Behavior

Debugging Templates

To debug template rendering issues:
  1. Check Variable Availability: Ensure all referenced variables exist
  2. Validate Jinja2 Syntax: Use a Jinja2 linter or validator
  3. Test Incrementally: Add template features one at a time
  4. Use the Render Endpoint: Test template rendering without making chat requests
  • Agents - Learn more about agent configuration
  • Sessions - Understand session management
  • Tasks - Create complex workflows with templates
  • Tool Integration - Add tools referenced in templates
System templates are rendered server-side before being sent to the language model. This ensures security and consistency across all API clients.