Prompts#
Each agent in the AI-Q blueprint uses Jinja2 templates to define its system prompt. These templates control the agent’s persona, instructions, output format, and behavior. By editing these templates you can customize how agents reason, what they prioritize, and how they format responses – all without modifying Python code.
Prompt Template Inventory#
Template |
Consumer |
Purpose |
|---|---|---|
|
Intent Classifier |
Classifies queries as meta or research, determines depth (shallow/deep), generates meta responses |
|
Shallow Researcher |
Defines the research persona, tool usage strategy, source hierarchy, and citation rules |
|
Deep Research Orchestrator |
Coordinates ordered routing, planning, batched research, and writer delegation; it does not call source tools directly |
|
Source Router |
Selects an advisory route from the request-allowed source catalog before planning |
|
Deep Research Planner |
Grounds and returns a structured |
|
Researcher Worker |
Executes one |
|
Report Writer |
Synthesizes the plan, research notes, and captured sources into |
|
Source Registry Middleware |
Renders the captured source list exposed to the writer |
|
Clarifier |
Determines whether a request needs clarification and asks focused follow-up questions; it does not create or approve a plan |
Template Directory Structure#
Each agent stores its prompts in a prompts/ subdirectory co-located with the agent code:
src/aiq_agent/agents/
shallow_researcher/
prompts/
researcher.j2 # Single system prompt
deep_researcher/
prompts/
orchestrator.j2 # Orchestrator prompt
source_router.j2 # Advisory source-routing prompt
planner.j2 # Research planner prompt
researcher.j2 # Researcher-worker prompt
writer.j2 # Final synthesis prompt
source_registry.j2 # Captured-source list fragment
clarifier/
prompts/
research_clarification.j2 # Clarification prompt
chat_researcher/
prompts/
intent_classification.j2 # Routing prompt
The naming convention follows each runtime role. source_registry.j2 is a middleware-rendered fragment rather than an agent system prompt.
How Templates Are Loaded#
At runtime, templates flow through two utility functions in src/aiq_agent/common/prompt_utils.py:
prompts/researcher.j2 (Jinja2 source)
│
▼
load_prompt() (reads file from disk)
│
▼
render_prompt_template() (renders with variables)
│
▼
SystemMessage(content=...) (sent to LLM)
load_prompt(path, name)#
Loads a raw template file from the agent’s prompts/ directory. Automatically appends .j2 if the file is not found by exact name.
from aiq_agent.common import load_prompt
# Load the template file as a string
template = load_prompt(Path(__file__).parent / "prompts", "researcher")
render_prompt_template(template, **kwargs)#
Renders a Jinja2 template string with the provided variables. Uses jinja2.StrictUndefined so that missing variables raise errors rather than producing silent empty strings.
from aiq_agent.common import render_prompt_template
rendered = render_prompt_template(
template,
current_datetime="2026-02-16 10:30:00",
tools=tools,
user_info={"name": "Alice", "email": "alice@example.com"},
)
Template Variables#
Each template receives different variables depending on the agent context.
Intent Classification#
Variable |
Type |
Description |
|---|---|---|
|
|
Current date and time string |
|
|
User context with |
|
|
Available tools (each has |
|
|
The user’s query text |
|
|
Whether the conversation has a report that can be edited or extended |
Shallow Researcher#
Variable |
Type |
Description |
|---|---|---|
|
|
Current date and time string |
|
|
User context with |
|
|
Available tools (each has |
|
|
Uploaded documents with |
Deep Research Orchestrator#
Variable |
Type |
Description |
|---|---|---|
|
|
Current date and time string |
|
|
Clarification context from the clarifier agent |
|
|
Uploaded documents with |
|
|
Authenticated user context |
|
|
Orchestrator-callable helper tools and |
|
|
Whether to run the advisory source-router stage |
|
|
Maximum |
|
|
Whether mounted parent-report files are available, enabling delta planning and revision instructions |
|
|
Whether a sandbox exposes execution tools |
|
|
Per-job sandbox paths used when execution is enabled |
Deep Research Source Router#
Variable |
Type |
Description |
|---|---|---|
|
|
Current date and time string |
|
|
Authenticated user context |
|
|
Clarification context used to choose an advisory route |
|
|
Uploaded documents available as routing context |
Deep Research Planner#
Variable |
Type |
Description |
|---|---|---|
|
|
Current date and time string |
|
|
Authenticated user context |
|
|
Request-filtered source tools available for plan grounding |
|
|
Uploaded documents with |
|
|
Whether |
|
|
Preferred upper bound for independent queries in one batch |
Deep Research Researcher#
Variable |
Type |
Description |
|---|---|---|
|
|
Current date and time string |
|
|
Authenticated user context |
|
|
Full request-filtered source-tool set available to each worker; plan preferences do not narrow this set |
|
|
Uploaded documents with |
|
|
Per-job sandbox paths available to skills when configured |
Deep Research Writer#
Variable |
Type |
Description |
|---|---|---|
|
|
Current date and time string |
|
|
Authenticated user context |
|
|
Whether mounted parent-report files are available for standalone revision synthesis with delta evidence |
|
|
Per-job sandbox paths for generated report artifacts |
The writer reads the persisted plan and research notes from /shared/ and retrieves captured sources through get_verified_sources; those inputs are runtime files and tools rather than Jinja variables. The separate source_registry.j2 fragment receives a sources list from SourceRegistryMiddleware.
Research Clarification#
Variable |
Type |
Description |
|---|---|---|
|
|
Previous clarification context (for multi-turn clarification) |
|
|
Uploaded documents with |
|
|
Connected data sources that the later research phase can access |
|
|
Available tools (each has |
|
|
List of tool name strings extracted from |
Modifying Prompts#
Editing Existing Templates#
The most common customization is editing the .j2 files directly. Since templates are loaded from disk at startup, changes take effect on the next application restart.
Example: Making the shallow researcher more concise
Open src/aiq_agent/agents/shallow_researcher/prompts/researcher.j2 and modify the citation rules section:
{#- 5. CITATION & FORMATTING -#}
## Citation Rules (STRICT)
Every claim must end with [1]. You MUST include a `**References:**` section.
- **Format**: `- [N] Title/Filename - URL/Citation`
- **Brevity**: Keep answers under 500 words unless the query explicitly asks for detail.
Key Sections to Customize#
Each template has well-defined sections you can target:
Intent Classifier (
intent_classification.j2) — Classification rules, depth determination, meta response style, output JSON schemaShallow Researcher (
researcher.j2) — Source hierarchy, research rules, citation format, response formattingDeep Research Orchestrator (
orchestrator.j2) — Ordered stage handoffs, bounded batch dispatch, retry rules, and writer delegationSource Router (
source_router.j2) — Advisory source-domain selection and planner guidanceDeep Research Planner (
planner.j2) — Answer-shape analysis, plan grounding, and structured query generationResearcher Worker (
researcher.j2) — Single-query research protocol, source preferences, tool-call batching, and structured notesReport Writer (
writer.j2) — Final synthesis, source use, citation format, and/shared/output.mdcontractSource Registry (
source_registry.j2) — Formatting for the captured-source list injected by middlewareClarifier (
research_clarification.j2) — What counts as “sufficiently specified”, question style, multi-turn policy
Creating a New Template#
To create a new prompt template for a custom or modified agent:
Step 1: Create the file
touch src/aiq_agent/agents/my_agent/prompts/system.j2
Step 2: Write the template
A well-structured prompt template has clearly defined sections:
{#- 1. CONTEXT -#}
Current date and time: {{ current_datetime }}
You are a specialized research agent.
{#- 2. TOOLS -#}
## Available Tools
{% if tools %}
{% for tool in tools %}- **{{ tool.name }}**: {{ tool.description }}
{% endfor %}
{% else %}
**No tools available.**
{% endif %}
{#- 3. INSTRUCTIONS -#}
## Instructions
- Research the user's question thoroughly using the available tools.
- Always cite your sources with numbered references.
- If no results are found, state this clearly.
{#- 4. OUTPUT FORMAT -#}
## Response Format
Provide your answer with inline citations [1], [2], etc.
End with a **References:** section listing all sources.
Step 3: Load it in your agent
class MyAgent:
def __init__(self, ...):
self.system_prompt = load_prompt(AGENT_DIR / "prompts", "system")
async def run(self, query: str) -> str:
rendered = render_prompt_template(
self.system_prompt,
tools=self._build_tools_info(),
current_datetime=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
)
# Use rendered as SystemMessage content
Multi-Prompt Agents#
Some agents use multiple prompts for different roles. The deep researcher loads five agent templates:
prompt_names = ["planner", "researcher", "orchestrator", "writer", "source_router"]
prompts = {name: load_prompt(AGENT_DIR / "prompts", name) for name in prompt_names}
source_registry.j2 is loaded separately by source-registry middleware. Each prompt is rendered with role-specific context, enabling independent model configuration and bounded tool access.
Jinja2 Patterns#
The templates use several Jinja2 patterns worth understanding before editing:
Tool Detection#
Templates detect available tool categories using namespace variables. The namespace() pattern is necessary because Jinja2’s scoping rules prevent setting variables inside for loops that persist outside the loop.
{% set ns = namespace(has_web=false, has_paper=false) %}
{% for tool in tools %}
{% set t_name = tool.name.lower() %}
{% if 'web' in t_name or 'tavily' in t_name %}
{% set ns.has_web = true %}
{% endif %}
{% endfor %}
Conditional Rendering#
Templates adapt based on which tools are available:
{% if ns.has_web %}
4. **Web Search**: Use for general facts, news, or when other sources are unavailable.
{% endif %}
For advanced Jinja2 patterns (source hierarchy, default values, whitespace control), refer to the existing templates in src/aiq_agent/agents/*/prompts/.
Testing Templates#
Set the DEBUG_PROMPTS environment variable to log rendered prompts:
DEBUG_PROMPTS=1 .venv/bin/nat run --config_file configs/my_config.yml --input "test query"
This logs the fully rendered system prompt before each LLM call, letting you verify variable substitution and conditional rendering.
Best Practices#
Test changes incrementally. Modify one section at a time and verify the output before changing more. Run the application with
--input "your test query"for quick iteration.Preserve the output format. Many agents parse the LLM response as JSON (intent classifier, planner, clarifier). If you modify the output schema section, update the corresponding Python parser.
Keep tool detection logic intact. The
{% set ns = namespace(...) %}blocks enable templates to adapt to different tool configurations. Removing them can cause incorrect instructions when tools are added or removed.Use Jinja2 comments for documentation. Add
{#- ... -#}comments to explain non-obvious prompt engineering decisions for future maintainers.Watch token budgets. Longer system prompts consume tokens from the model’s context window. This matters most for the deep research orchestrator, which needs context space for sub-agent reports.
Match the existing style. The templates use a consistent Markdown structure with headers, bold text, and numbered lists. Following this pattern helps the LLM parse instructions reliably.
Test with multiple models. Different LLMs interpret prompt instructions differently. If you switch models (refer to Swapping Models), verify that the prompts still produce the expected behavior.