The Agentic Layer
Prompt Templates
A prompt template is a structured instruction set that defines how an agent behaves within a workflow phase. It is the single most important artifact in your agentic layer.
What is a prompt template
A prompt template is not a one-off chat message. It is a reusable, versioned, parameterized document that turns a generic AI model into a specialist with a specific role, bounded scope, and predictable output format. It sits in your repo alongside your code.
Think of prompt templates as job descriptions for agents. A job description defines the role, the context the employee needs, what they are and are not allowed to do, and what deliverables they must produce. Prompt templates do the same thing.
Anatomy of a prompt template
Every template needs four sections. Miss one and the agent drifts.
Role
Who the agent is. A persona assignment that sets behavioral expectations. "You are a Software Architect" produces very different behavior than "You are a QA Engineer." The role determines what the agent prioritizes, how it communicates, and what it considers important.
You are a Senior Software Engineer specializing in test-driven development.
Context
What the agent knows. Template variables inject dynamic information at runtime: the issue description, branch name, prior phase artifacts, relevant files. Without context, agents hallucinate. With too much, they lose focus.
Issue: ${issue_description}
Plan: ${plan_artifact}
Constraints
What the agent can and cannot do. Tool permissions, scope boundaries, anti-patterns to avoid. Constraints are the guardrails that prevent scope creep, unauthorized file modifications, and architectural drift.
- Read-only. Do not modify any files.
Output Format
What the agent produces. A JSON schema, markdown template, or specific structure that downstream phases can parse. Structured outputs make artifact chaining possible (the workflow's memory).
Produce a JSON object with keys: summary, files_modified, files_created, test_strategy
Template variables
Variables are how the workflow injects runtime data into templates.
| Category | Variables | Description |
|---|---|---|
| Static | ${raw_request} ${issue_type} ${branch_name} ${issue_description} ${project_name} |
Set once when the workflow starts. Come from the issue tracker or user input. |
| Artifact | ${intent_artifact} ${plan_artifact} ${build_artifact} ${test_results} ${review_results} |
Output from a previous phase. This is artifact chaining in action. |
| Context | ${codebase_summary} ${relevant_files} ${test_commands} ${dependency_graph} |
Dynamically gathered from the codebase at runtime. Context providers populate these. |
How variables get substituted
Before a template is sent to the agent, the workflow engine performs variable substitution. Every ${variable_name} is replaced with its runtime value. If a variable is undefined, the workflow should either use a default or fail loudly. Never send raw ${...} to an agent.
# BEFORE substitution (template on disk)
Issue: ${issue_description}
Type: ${issue_type}
Prior plan: ${plan_artifact}
# AFTER substitution (what the agent receives)
Issue: Add pagination to the /users API endpoint
Type: feature
Prior plan: ## Implementation Plan
1. Add `page` and `limit` query params to GET /users
2. Update UserRepository.findAll() to accept pagination
3. Add tests for boundary conditions (page 0, negative limit)
Template gallery
Complete, annotated templates for four phases. Copy, adapt, use.
# Intent Phase -- Requirements Analyst
## Role
You are a Requirements Analyst. Your job is to take a raw
request and produce a well-defined intent specification
that a Software Architect (Plan phase) can act on.
You do NOT write code. You do NOT create plans. You do NOT
modify files. You clarify requirements and produce a
normalized specification.
## Context
Request: ${raw_request}
Repository: ${project_name}
### Codebase Context
${codebase_summary}
## Methodology
1. Research the codebase to understand the affected area
2. Identify what is missing, ambiguous, or assumed
3. Ask clarifying questions grounded in codebase evidence
4. Classify the issue type: feature | bug | task | patch
5. Produce the intent specification
## Constraints
- READ-ONLY. Do not create, modify, or delete any files.
- Research before asking. Never ask questions the codebase
can answer.
- Ask only what changes the specification. Skip style and
preference questions.
- Do NOT plan solutions. Your job ends at the specification.
- Do NOT expand scope beyond what the request describes.
- If the request is already well-defined (has acceptance
criteria, clear scope), produce the spec directly without
asking questions.
## Output Format
Produce an intent specification with these sections:
### 1. Problem / Goal
What needs to happen and why (2-3 sentences).
### 2. Issue Type
feature | bug | task | patch
### 3. User Stories or Reproduction Steps
EARS format for features: "When [stimulus], the system shall [response]."
Step-by-step reproduction for bugs.
### 4. Acceptance Criteria
| # | Criterion | Testable? |
|---|-----------|-----------|
| 1 | Description | yes/no |
### 5. Scope
**In scope:** bullet list of what is included.
**Out of scope:** bullet list of what is explicitly excluded.
### 6. Codebase Context
Relevant files, patterns, and constraints found during research.
### 7. Assumptions
Verified and unverified assumptions, flagged for Plan.
The Intent template introduces two patterns not seen in other phases: Interactive Clarification (the agent pauses for user input) and Quality Normalization (the agent ensures consistent output regardless of input quality). The Already-Well-Defined Shortcut prevents Intent from becoming a bottleneck on well-structured tickets.
Versioning templates
Templates are code. Treat them like code.
Store in version control
Templates live in agentic-layer/prompts/ alongside your codebase. Every change is tracked, diffable, and revertable.
Review template changes like code changes
A changed prompt can alter agent behavior across every workflow run. PR reviews for templates are essential.
Test template changes against sample inputs
Before merging a template change, run it against 2-3 representative issues. Compare output quality before/after.
Maintain a changelog per template
Add a comment block at the top of each template with version history.
<!-- Changelog
v3 - 2026-03-08 - Added anti-scope-creep section after agents kept expanding scope
v2 - 2026-02-15 - Added risk assessment output section
v1 - 2026-01-20 - Initial template
-->
Template evolution
Start simple. Add constraints as you discover edge cases.
Role + Context + Output
10 lines. Your first template. Just enough to get structured output.
+ Constraints section
15 lines. After agents drifted off-scope or modified files they should not touch.
+ Anti-scope-creep
20 lines. After agents added unrequested features. The explicit "what we are NOT doing" section.
+ Anti-patterns list
30 lines. After agents used bad patterns like @ts-ignore or swallowed errors.
Issue-type routing (4 templates)
After one template could not handle all issue types. Split into feature, bug, task, and patch variants.
When to split a template
When your constraints section has multiple conditional blocks ("if this is a bug, do X; if this is a feature, do Y"), it is time to split. plan.md becomes plan-feature.md, plan-bug.md, plan-task.md, plan-patch.md. The workflow config routes to the correct template based on ${issue_type}.
# workflow.yaml -- issue-type routing
templates:
plan:
feature: prompts/plan-feature.md
bug: prompts/plan-bug.md
task: prompts/plan-task.md
patch: prompts/plan-patch.md
default: prompts/plan.md # fallback