Templates

Customize agent behavior with system, prompt, and response templates

Templates let you control exactly what an agent says, how it says it, and how it formats its response โ€” all in a few lines.

python
from praisonaiagents import Agent, TemplateConfig

agent = Agent(
    name="Support Bot",
    templates=TemplateConfig(
        system="You are a friendly support agent for Acme Corp.",
        use_system_prompt=True,
    ),
)
agent.start("How do I reset my password?")

The user sends a message; system, prompt, and response templates shape what the agent sees and how it replies.

Diagram

Template System

๐Ÿ“‹ System Template

๐Ÿค– Agent

๐Ÿ’ฌ Prompt Template

๐Ÿ“ Response Template

โœ… Output

Quick Start

  1. Custom System Prompt

    Override the default system message so the agent stays in character.

    python
    from praisonaiagents import Agent
    
    agent = Agent(
        name="Support Bot",
        system_prompt="You are a friendly customer support agent for Acme Corp. Always be concise and helpful.",
    )
    
    agent.start("How do I reset my password?")
  2. With TemplateConfig

    Use TemplateConfig for full control over system, prompt, and response templates.

    python
    from praisonaiagents import Agent, TemplateConfig
    
    agent = Agent(
        name="Analyst",
        instructions="Analyze the data provided.",
        templates=TemplateConfig(
            system="You are a data analyst. Return only structured insights.",
            prompt="Analyze this: {input}",
            response="Summary:\n{response}\n\nKey Points:\n- {points}",
            use_system_prompt=True,
        )
    )
    
    agent.start("Sales grew 20% in Q3")
  3. YAML Template Variables

    Define reusable workflows with {placeholder} variables in YAML.

    yaml
    # workflow.yaml
    variables:
      topic: climate change
    
    agents:
      researcher:
        name: Researcher
        instructions: "Research {topic} thoroughly"
    
    steps:
      - agent: researcher
        action: "Find the latest data on {topic}"
    python
    from praisonaiagents import Agent, YAMLWorkflowParser
    
    parser = YAMLWorkflowParser()
    workflow = parser.parse_file("workflow.yaml", extra_vars={"topic": "renewable energy"})
    workflow.run()

How It Works

Templates are applied in a specific order before the LLM sees your request.

Diagram
LLMTemplate EngineAgentUserLLMTemplate EngineAgentUser“Analyze sales data”Apply system templateFormatted system messageApply prompt template with {input}Formatted user messagesystem + promptRaw responseApply response templateFormatted outputFinal answer

Configuration Options

TemplateConfig API Reference

Full API reference for TemplateConfig โ€” system, prompt, response, use_system_prompt

TemplateConfig Fields

FieldTypeDefaultDescription
system`str \None`NoneOverride the system prompt
prompt`str \None`NoneTemplate for the user message; use {input} as a placeholder
response`str \None`NoneFormat template applied to the LLM response
use_system_promptboolTrueWhether to send a system message at all

Common Patterns

Structured Output Format

Force the agent to return a consistent format every time.

python
from praisonaiagents import Agent, TemplateConfig

agent = Agent(
    name="Reporter",
    instructions="Summarize news articles.",
    templates=TemplateConfig(
        system="You are a news summarizer. Always output valid JSON.",
        response='{"headline": "...", "summary": "...", "sentiment": "positive|negative|neutral"}',
        use_system_prompt=True,
    )
)

result = agent.start("OpenAI released a new model today with improved reasoning.")
print(result)

Persona Agent

Lock the agent into a role with a strong system template.

python
from praisonaiagents import Agent, TemplateConfig

agent = Agent(
    name="Pirate Guide",
    instructions="Help users navigate the Caribbean.",
    templates=TemplateConfig(
        system="You are a 17th century Caribbean pirate. Speak in pirate dialect. Never break character.",
        use_system_prompt=True,
    )
)

agent.start("How do I get to Tortuga?")

YAML Variable Substitution

Run the same workflow against different inputs without editing the YAML.

python
from praisonaiagents import YAMLWorkflowParser

parser = YAMLWorkflowParser()

# Same workflow, different topics
for topic in ["AI safety", "quantum computing", "space exploration"]:
    workflow = parser.parse_file("research_workflow.yaml", extra_vars={"topic": topic})
    workflow.run()

Best Practices

Keep system templates focused

A system template that tries to do everything usually does nothing well. One clear role per template โ€” “You are a customer support agent for Acme Corp” โ€” produces better results than a long list of unrelated instructions.

Use {input} placeholder in prompt templates

When your prompt template includes {input}, PraisonAI substitutes the user’s actual request at runtime. This keeps your template generic and reusable across many different queries.

Test response templates with diverse outputs

Response templates are applied as a format instruction to the LLM. Test with edge-case inputs (short answers, long answers, refusals) to make sure the template doesn’t corrupt valid responses.

Prefer YAML templates for team workflows

When multiple people run the same workflow, store templates in a YAML file rather than hardcoding them in Python. YAML files are easier to version, review, and swap without touching code.


Related