1# Prompt Forge - Agentic Patterns Reference
2
3Read this file when building agentic systems with tool use, subagents, or real-world actions.
4
5## Conditional Section Assembly
6
7Production prompts are not static. Sections should be injected or omitted based on runtime state.
8
9**Tool-aware instructions.** Only include rules about a tool when that tool is available:
10```
11if "search" in available_tools:
12 sections.append("For codebase searches, use the Search tool instead of grep.")
13```
14
15**Mode-aware sections.** Skip domain-specific instructions when the agent operates in a different mode:
16```
17if mode == "code":
18 sections.append(coding_guidelines)
19elif mode == "support":
20 sections.append(support_guidelines)
21```
22
23**Feature-flagged sections.** Gate experimental instructions behind flags:
24```
25if feature_flags.get("verbose_output"):
26 sections.append(output_efficiency_section)
27```
28
29Every unnecessary token in the system prompt costs money and dilutes attention. A prompt with 20 tools that includes instructions for all 20 wastes tokens on tools the model may never use.
30
31## Mid-Conversation Context Injection
32
33Not all instructions belong in the system prompt. Some context should be injected at runtime as tagged messages within the conversation.
34
35**System-reminder pattern.** Wrap injected context in XML tags as a user message:
36```xml
37<system-reminder>
38Today's date is March 22, 2026.
39
40IMPORTANT: this context may or may not be relevant to your tasks.
41You should not respond to this context unless it is highly relevant.
42</system-reminder>
43```
44
45**When to use system-reminders vs system prompt:**
46
47| Content | Where |
48|---------|-------|
49| Static rules, identity, tool instructions | System prompt |
50| User config files, project instructions | First user message (system-reminder wrapper) |
51| Date changes, background task results | Injected mid-conversation as system-reminder |
52| Warnings about specific tool results | Appended to the tool result content |
53| Memory staleness alerts | Appended after memory content |
54
55Tell the model explicitly that these tags "bear no direct relation to the specific tool results or user messages in which they appear." Otherwise the model may attribute the reminder to the wrong context.
56
57## Tool Prompt Architecture
58
59When building agentic systems with tool use, instructions for tools live in three separate places.
60
61| Layer | What goes here | Example |
62|-------|---------------|---------|
63| **Tool `description`** | What the tool does, when to use it. Model reads this to decide whether to call it. | "Reads a file from the local filesystem." |
64| **Tool `parameter.description`** | Per-parameter guidance. Model reads this when filling in arguments. | "The absolute path to the file to read" |
65| **System prompt tool section** | Cross-tool preferences, delegation rules, parallelism instructions. | "Use Read instead of cat. Call multiple tools in parallel when independent." |
66
67**Anti-pattern:** putting usage strategy in tool descriptions. "Always prefer this tool over Bash" belongs in the system prompt, not the tool's description.
68
69**Anti-pattern:** duplicating instructions across tool descriptions and system prompt. Pick one location.
70
71## Subagent Prompt Minimalism
72
73Subagents should NOT inherit the full parent prompt. Strip everything except identity, task scope, correctness constraints, and environment info. Omit tone/style, methodology, tool preferences, action safety rules.
74
75**Subagent prompt structure:**
76```
771. Tight identity (what you are, scope of work, how to report back)
782. Operational constraints (absolute paths, no emojis, concise responses)
793. Minimal environment context (CWD, platform, model)
80```
81
82**Subagent identity pattern:**
83```
84Given the user's message, use the tools available to complete the task.
85Do what has been asked; nothing more, nothing less.
86When you complete the task, respond with a concise report covering what was done
87and any key findings.
88```
89
90This prevents subagents from over-explaining, expanding scope, or duplicating parent work.
91
92## Action Safety (Reversibility Spectrum)
93
94For agents that take real-world actions (file edits, git operations, API calls, deployments), include a reversibility framework in the system prompt.
95
96**Reversibility spectrum:**
97```
98Freely take: local, reversible actions (editing files, running tests)
99Confirm first: hard-to-reverse actions (force push, delete branch, deploy)
100Never without explicit ask: actions visible to others (push, comment on PRs, send messages)
101```
102
103**Key rules:**
104- "A user approving an action once does NOT mean they approve it in all contexts"
105- "Authorization stands for the scope specified, not beyond"
106- "Do not use destructive actions as a shortcut to make obstacles go away"
107- "If you discover unexpected state, investigate before deleting or overwriting"
108
109**Anti-pattern:** binary "ask for everything" or "do everything autonomously." The spectrum approach gives the model judgment within guardrails.
110
111## Tool Result Shrinking (Microcompaction)
112
113Large tool outputs (file contents, search results, command output) bloat context fast. Apply automatic replacement:
114
115- Set a threshold (e.g., 2000 chars). Tool results exceeding it get summarized.
116- Track replacements in state so you can restore if needed.
117- Tell the model upfront: "Write down any important information from tool results, as the original may be cleared later."
118
119This prompts the model to self-extract key facts before compaction removes the raw output.