> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Template System"
        S["📋 System Template"] --> A["🤖 Agent"]
        P["💬 Prompt Template"] --> A
        A --> R["📝 Response Template"]
        R --> O["✅ Output"]
    end

    classDef template fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef output fill:#10B981,stroke:#7C90A0,color:#fff

    class S,P,R template
    class A agent
    class O output
```

## Quick Start

<Steps>
  <Step title="Custom System Prompt">
    Override the default system message so the agent stays in character.

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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?")
    ```
  </Step>

  <Step title="With TemplateConfig">
    Use `TemplateConfig` for full control over system, prompt, and response templates.

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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")
    ```
  </Step>

  <Step title="YAML Template Variables">
    Define reusable workflows with `{placeholder}` variables in YAML.

    ```yaml theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    # 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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent, YAMLWorkflowParser

    parser = YAMLWorkflowParser()
    workflow = parser.parse_file("workflow.yaml", extra_vars={"topic": "renewable energy"})
    workflow.run()
    ```
  </Step>
</Steps>

***

## How It Works

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

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Template as Template Engine
    participant LLM

    User->>Agent: "Analyze sales data"
    Agent->>Template: Apply system template
    Template-->>Agent: Formatted system message
    Agent->>Template: Apply prompt template with {input}
    Template-->>Agent: Formatted user message
    Agent->>LLM: system + prompt
    LLM-->>Agent: Raw response
    Agent->>Template: Apply response template
    Template-->>Agent: Formatted output
    Agent-->>User: Final answer
```

***

## Configuration Options

<Card title="TemplateConfig API Reference" icon="code" href="/docs/sdk/praisonaiagents/config/feature-configs-module">
  Full API reference for `TemplateConfig` — system, prompt, response, use\_system\_prompt
</Card>

### TemplateConfig Fields

| Field               | Type          | Default | Description                                                   |
| ------------------- | ------------- | ------- | ------------------------------------------------------------- |
| `system`            | `str \| None` | `None`  | Override the system prompt                                    |
| `prompt`            | `str \| None` | `None`  | Template for the user message; use `{input}` as a placeholder |
| `response`          | `str \| None` | `None`  | Format template applied to the LLM response                   |
| `use_system_prompt` | `bool`        | `True`  | Whether to send a system message at all                       |

***

## Common Patterns

### Structured Output Format

Force the agent to return a consistent format every time.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

<AccordionGroup>
  <Accordion title="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.
  </Accordion>

  <Accordion title="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.
  </Accordion>

  <Accordion title="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.
  </Accordion>

  <Accordion title="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.
  </Accordion>
</AccordionGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="YAML Template Variables" icon="code" href="/docs/features/yaml-template-variables">
    Safely use `{placeholder}` in YAML alongside JSON literals
  </Card>

  <Card title="Industry Templates" icon="building-2" href="/docs/features/industry-templates/overview">
    Pre-built agent workforces for Manufacturing, Energy, Healthcare, and more
  </Card>
</CardGroup>
