Prompts as the new source code
Prompt engineering operates at the semantic level, not the procedural one — a shift from algorithmic specification to what the chapter calls cognitive programming. The model supplies raw capability; the prompt is the configuration layer that turns one base model into a legal researcher, a support agent, or a code reviewer. For an agent, a prompt is its constitutional bedrock.
Key concept · Why prompting matters for agents
- Behavior customization — one model, many personas via prompt variation
- Agent coordination — prompts drive workflows and hand-offs across agents
- Accuracy & relevance — precise prompts cut ambiguity and hallucination
- Real-time adaptation — behavior changes mid-execution, no redeployment
- Cost efficiency — no expensive retraining; ~99% cheaper than fine-tuning
The economic case: fine-tuning frontier models can cost millions per run, while a complex prompt project costs a few thousand dollars in expert time. Prompting and fine-tuning aren't exclusive, though — RAG adds live knowledge, and parameter-efficient adapters (LoRA, QLoRA) tune behavior cheaply when prompt-only performance plateaus.
System prompt & user prompt
A foundational pattern separates an agent's persistent identity from its immediate task — a “diplomat” whose country and code of conduct (system prompt) stay fixed while each negotiation (user prompt) varies. Together they form the agent's prompt contract.
System prompt
HOW the agent behaves
The cognitive & ethical constitution — loaded once, active all session. Defines identity, rules/guardrails, capabilities, output format, and context hierarchy (how to resolve conflicts). The “semantic source code.”
User prompt
WHAT the agent should do
The immediate stimulus — a command, question, or (in multi-agent systems) a machine-generated task payload from an orchestrator. Interpreted within the frame the system prompt sets.
System prompts consume a fixed slice of the context window on every call, so prompt budget management is a first-class design constraint — compress verbose sections and point to external stores rather than inlining everything.
Four pillars of principled prompt design
PTCF decomposes the system prompt into four functional pillars — the agent's “cognitive contract.” It beats alternatives like CRISPE on clarity and modularity: each component can be authored, audited, and iterated independently. As object-oriented programming brought structure to code, PTCF brings structure to cognition.
Persona
Who the agent is
Identity, tone, reasoning style. A weak persona (“You are a helpful assistant”) causes identity collapse — the agent complies with anything.
Task
What it must do
Primary mission and boundaries. Prevents feature creep; anchors decision-making to the core function.
Context
Where/how it operates
Situational awareness — SLAs, regulations, access controls. In regulated domains it functions as a compliance guardrail, not background.
Format
How it responds
Output structure — JSON, Markdown, numbered lists. Enables interoperability and agent-to-agent composability.
Anti-pattern to avoid · Conflicting components
A persona that's “creative and experimental” paired with a task of “troubleshoot enterprise billing” and a rigid numbered-list format will oscillate between whimsical and procedural. Each PTCF component must reinforce the others to form a coherent behavioral contract.
Cognitive patterns: scaling how agents reason
A core principle: prompt complexity must scale with cognitive complexity. The agent capability spectrum runs from Level 1 reactive (unambiguous commands) through Level 2 tool-using, Level 3 planning (“think step by step” decomposition), to Level 4 learning (metacognitive prompts that reason about their own reasoning).
Task decomposition
Users speak in vague terms (“Plan my business trip”). Decomposition — embedded in the task and format components — turns ambiguous goals into ordered, dependency-aware sub-tasks, so the agent behaves like an executive assistant rather than a script-runner.
Chain-of-thought vs. tree-of-thought
Chain-of-thought — the methodical analyst
Linear, sequential step-by-step reasoning. Best for ordered problems (arithmetic, root-cause diagnosis). Weakness: rigidity — a flawed early assumption dooms the chain (premature commitment). PTCF home: Format.
Tree-of-thought — the virtual strategy team
Explores multiple reasoning branches in parallel (virtual experts) that debate and synthesize. Best for ambiguous, multi-path problems (launch strategy). Weakness: branch explosion, high compute. PTCF home: Task + Context.
Few-shot learning
Embedding a handful of examples (in-context learning, which rose to prominence with GPT-3) teaches by analogy — no retraining. It lives in the context component. The term is literal: zero-shot (none), one-shot (one), few-shot (typically 2–5, up to ~10). Quality of examples matters far more than quantity.
| Dimension | Few-shot learning | RAG |
|---|---|---|
| Data freshness | Static (baked in) | Dynamic (retrieved) |
| Context cost | High (examples inline) | Lower (chunks only) |
| Setup complexity | Low | Medium–high (vector DB) |
| Best fit | Pattern-rich, bounded tasks | Large/changing corpora |
| Key failure mode | Context overflow | Retrieval hallucination |
Key concept · Pattern → PTCF mapping
Every cognitive pattern is an elaboration of a PTCF component, not an add-on: capability alignment & CoT → Format; task decomposition → Task; few-shot → Context; role persona → Persona; ToT → Task + Context.
Multi-agent protocols & evaluating prompts
The same PTCF discipline scales outward to govern how agents talk to each other. Each pillar maps to a communication requirement: Persona → verifiable identity/authority (“who is speaking?”), Task → message intent (a message_type field), Context → shared metadata (timestamps, references, priority), Format → a universal machine-readable schema (usually JSON) that lets one agent's output become another's input.
Case studies · The pattern that repeats
- SaaS support triage — SLA thresholds in Context replaced a separate rules engine; JSON Format made output composable.
- Financial compliance review — explicit prohibitions + mandatory escalation belong in Context as a guardrail; a reasoning field gives the audit trail.
- Automated code review — a scope boundary in Task (“Critical & Major only”) turned a noisy reviewer into a trusted first-pass filter.
Iterating & evaluating prompts
Prompting is treated as a software discipline with versioned artifacts and test suites. Two strategies:
A/B comparison
Run two prompt variants against an identical input set; compare on defined metrics (accuracy, format compliance, task completion). Isolates the effect of a single change.
Regression testing
A reference suite of canonical inputs with expected outputs. A revision ships only if it passes the full suite without degrading any previously passing case.
The diagnosis loop when a prompt underperforms: Baseline → Evaluate (categorize the failure by PTCF component) → Identify (smallest targeted fix) → Revise & version (label e.g. v1.2.0, run regression suite, keep prompt history like source code).
Chapter 3 quiz
Fifteen questions across the constitution model, PTCF, cognitive patterns, and evaluation. Answer first, then expand Show answer.
Part A · Multiple choice
What does the PTCF framework stand for?
- A Perception, Task, Context, Feedback
- B Persona, Task, Context, Format
- C Purpose, Tone, Constraints, Format
- D Persona, Thinking, Cognition, Function
Show answer
B — Persona, Task, Context, Format. Who the agent is, what it does, where/how it operates, and how it responds.
In the two-layer architecture, which prompt defines how the agent behaves and persists across the whole session?
- A The user prompt
- B The system prompt
- C The context reference
- D The task payload
Show answer
B — the system prompt. It's the constitution (HOW). The user prompt is the transient stimulus (WHAT).
Which reasoning technique explores multiple parallel reasoning branches that debate before synthesizing a solution?
- A Chain-of-thought (CoT)
- B Few-shot learning
- C Tree-of-thought (ToT)
- D Zero-shot prompting
Show answer
C — Tree-of-thought. CoT is a single linear chain; ToT spins up “virtual experts” that explore branches in parallel, then synthesize.
Roughly how many examples define “few-shot” learning?
- A 0
- B Exactly 1
- C Typically 2–5 (up to ~10)
- D 50–100
Show answer
C. Zero-shot = none, one-shot = one, few-shot = typically 2–5. Example quality matters more than quantity.
Which PTCF component do few-shot examples naturally belong to?
- A Persona
- B Task
- C Context
- D Format
Show answer
C — Context. Embedded examples act as live demonstrations without breaking persona, task, or format.
Approximately how much cheaper is prompt engineering than full model fine-tuning, per the chapter's economic case?
- A ~10%
- B ~50%
- C ~99%
- D No difference
Show answer
C — over 99%. Fine-tuning frontier models can cost millions per run; a complex prompt project costs a few thousand dollars in expert time with zero marginal training cost.
Part B · True or false
“You are a helpful assistant” is an example of a strong, well-scoped persona.
Show answer
False. That's the model's default self-description, not a persona — it causes “identity collapse,” leaving the agent no scope to defend and complying with anything.
Prompt complexity should scale with the agent's cognitive complexity.
Show answer
True. Reactive agents need simple directives; learning agents need metacognitive scaffolding. This is the core principle of aligning prompting strategy with the capability spectrum.
Chain-of-thought is the most efficient choice for simple factual questions like “What is the capital of Canada?”
Show answer
False. Step-by-step reasoning is excessive and inefficient for simple factual lookups; CoT shines where methodical, sequential reasoning is actually needed.
In regulated domains, explicit prohibitions and mandatory escalation rules belong in the Context component, functioning as a compliance guardrail.
Show answer
True. The compliance case study stresses that context is “the agent's operational law,” not mere background — prohibitions shouldn't be left to be inferred from the persona.
Part C · Short answer
State the one-line question each PTCF pillar answers.
Show answer
Persona — who the agent is. Task — what it's supposed to do. Context — where and how it operates. Format — how it should respond.
What distinguishes a system prompt from a user prompt? Give the “diplomat” analogy.
Show answer
The system prompt defines HOW the agent behaves (persistent identity/rules); the user prompt defines WHAT it should do now (transient). Analogy: the system prompt is the diplomat's country, values, and code of conduct; the user prompt is the current negotiation they're handling.
When should you choose few-shot learning over RAG, and vice versa?
Show answer
Few-shot for pattern-rich, bounded, self-contained tasks where reasoning can be learned from a few illustrations (e.g. tone classification, ticket triage) and latency/cost prohibits search. RAG for large/changing document corpora needing long-form knowledge retrieval (e.g. answering from legal docs, policy manuals).
Name the two prompt-evaluation strategies the chapter recommends and what each guards against.
Show answer
A/B comparison — runs two variants on identical inputs to isolate one change's effect (guards against judging by subjective impression). Regression testing — a canonical suite a revision must pass without degrading prior successes (guards against fixing one thing while breaking another).
In a prompt-driven multi-agent protocol, how does each PTCF component map to a communication requirement?
Show answer
Persona → verifiable identity & authority (“who is speaking?”). Task → message intent/type. Context → shared metadata (timestamps, references, priority). Format → a universal schema (usually JSON) so one agent's output cleanly becomes another's input.