Prompt Architecture
Part of: Effective AI Utilization — Table of Contents
Prompts are code. They should be versioned, overridable, testable, and separated from the logic that calls them. BrianBot's prompt system demonstrates a mature pattern worth studying.
BrianBot's 3-Tier Prompt Resolution
The resolvePrompts() function in BrianBot implements a clean override chain: each pipeline step defines a hardcoded default prompt, which can be overridden at the admin level (DB PromptTemplate table), which can be overridden at the show level. This means prompts can evolve without code deploys, and different shows can have entirely different personalities.
This is the right separation of concerns: engineers own the default prompts and the resolution logic, while product/content teams can iterate on prompts through the admin UI.
System Prompt vs User Prompt
Every AI call has two prompt surfaces: the system prompt (persistent instructions about behavior and format) and the user prompt (the specific task input). BrianBot embeds both inline in each pipeline step file. The system prompt defines the persona and output format; the user prompt contains the episode-specific content.
Key principle: system prompts should be stable across calls, user prompts should be unique per call. This enables prompt caching (see Token Optimization Playbook) — Anthropic's prompt caching can store system prompts across calls, dramatically reducing input tokens when your system prompt is large.
Prompt Composition Patterns
BrianBot's pipeline steps compose prompts by interpolating variables into template strings — episode title, transcript text, memory summaries, topic lists. This is simple and effective for linear pipelines. For more complex systems, consider structured prompt builders that enforce consistent formatting and prevent injection.
Separating Instruction from Content
A subtle but important pattern: in BrianBot's transcript step, the show's memory context is injected into the prompt alongside the raw audio transcript. The model must distinguish between "here's how you should behave" (instruction) and "here's what happened in this episode" (content). Clear delimiter patterns (XML tags, markdown headers, explicit labels) help the model maintain this distinction.
Related: Model Routing Strategies, Token Optimization Playbook, Temperature and Parameter Tuning, AI Pipeline Design
