Skip to main content
Templates let you customize how agents construct their prompts - system instructions, user prompts, and response formats.

Quick Start

1

Basic Templates

from praisonaiagents import Agent, TemplateConfig

agent = Agent(
    name="Custom Agent",
    instructions="You are a helpful assistant",
    templates=TemplateConfig(
        system="You are {role}. {instructions}",
        prompt="User request: {input}",
    )
)
2

Response Format

agent = Agent(
    name="Structured Agent",
    instructions="You provide structured answers",
    templates=TemplateConfig(
        response="""Format your response as:
## Summary
[Brief summary]

## Details
[Detailed explanation]

## Next Steps
[Recommendations]"""
    )
)

Template Types

TemplatePurposeWhen Applied
systemAgent identity, rules, contextStart of conversation
promptFormat user inputEach request
responseStructure output formatEach response

Configuration Options

from praisonaiagents import TemplateConfig

config = TemplateConfig(
    system="You are {role}...",      # System prompt template
    prompt="Query: {input}",          # User prompt template
    response="Format: ...",           # Response format
    use_system_prompt=True,           # Include system prompt
)
OptionTypeDefaultDescription
systemstrNoneSystem prompt template
promptstrNoneUser prompt template
responsestrNoneResponse format template
use_system_promptboolTrueWhether to use system prompt

Template Variables

Templates support variable substitution:
agent = Agent(
    name="Support Agent",
    role="Customer Support Specialist",
    instructions="Help customers with their issues",
    templates=TemplateConfig(
        system="""You are {role}.
Your goal: {goal}
Background: {backstory}

{instructions}"""
    )
)

Available Variables

VariableSource
{name}Agent name
{role}Agent role
{goal}Agent goal
{backstory}Agent backstory
{instructions}Agent instructions
{input}User input

Common Patterns

Structured Output

agent = Agent(
    instructions="You analyze data",
    templates=TemplateConfig(
        response="""Provide your analysis in this format:

**Finding**: [Main finding]
**Evidence**: [Supporting data]
**Confidence**: [High/Medium/Low]
**Recommendation**: [Action to take]"""
    )
)

Role-Based System

agent = Agent(
    name="Expert",
    role="Senior Software Engineer",
    backstory="10 years of experience in Python",
    templates=TemplateConfig(
        system="""# Role
You are {role} with the following background:
{backstory}

# Guidelines
{instructions}

# Constraints
- Always explain your reasoning
- Provide code examples when relevant
- Cite best practices"""
    )
)

Chain-of-Thought

agent = Agent(
    instructions="You solve problems step by step",
    templates=TemplateConfig(
        response="""Think through this step by step:

1. **Understanding**: What is being asked?
2. **Analysis**: What are the key factors?
3. **Solution**: What is the answer?
4. **Verification**: Is this correct?

Final Answer: [Your answer]"""
    )
)

Disabling System Prompt

For some use cases, you may want to skip the system prompt:
agent = Agent(
    instructions="...",
    templates=TemplateConfig(
        use_system_prompt=False  # No system prompt
    )
)

Template Inheritance

Templates combine with agent properties:
# Agent properties
agent = Agent(
    name="Helper",
    role="Assistant",
    instructions="Be helpful and concise",
    templates=TemplateConfig(
        system="{role}: {instructions}"
    )
)

# Results in: "Assistant: Be helpful and concise"

Best Practices

Each template should have a clear purpose. Don’t overload the system template.
Define response formats to get predictable, structured outputs.
Variables are substituted at runtime - test with different agent configurations.
If using custom templates, document what variables are expected.