learn-prompt-engineering-with-phoebe / Builder session 6 of 10
Learn Prompt Engineering with Phoebe · Builder track · Session 6 of 10

Chaining and agentic prompting

One giant prompt is where reliability goes to die. Today we split work into chains, then hand the model tools - and discover that the system prompt, the tool spec, and the stop rules are all one prompting surface.

🟠 Builder track Practitioners Any model or API 35 min self-read · 45 min live
0-3 · Welcome 3-20 · Chains, agents, tools 20-42 · Build-along: TriageBot v4 42-45 · Q&A
Part 0

Where we are in the arc

Sessions 1-5 taught you to write one excellent call: clear, structured, grounded, cache-shaped. Session 6 is the phase change. First we stop pretending one call should do everything and learn to chain. Then we let the model act - call tools, observe results, decide what to do next - and learn what that does to your prompts. TriageBot gets hands today.

Live - presented in session Self-study - read after class ★ Build-along - do it with me Any model or API
★ What you walk out with today A rule of thumb for when to chain versus when one call is fine, the self-correction pattern (draft, review against a rubric, refine), the three agentic system-prompt reminders that fix most flaky agents, eagerness calibration in both directions, the habit of engineering tool descriptions like the prompts they are, and TriageBot v4: a triage prompt that can look up order status before routing a refund.
Part 1 · decompose

Chaining: many small prompts beat one giant one 5 min live

Prompt chaining is the simplest idea in this session: the output of one call becomes the input of the next. Anthropic's docs push it for accuracy on multi-step work, and Gemini's docs teach the same move as decompose-and-aggregate: break the task down, run the pieces, merge the results. Each link does one job, so each link can be tested, cached, and fixed on its own.

Ticket in Raw customer message Call 1 Classify + extract fields as JSON Call 2 Draft the routing decision Call 3 Review draft against a rubric Call 4 Refine + emit final JSON fails the rubric? loop back and redraft Calls 3 and 4 are the self-correction pattern: draft, review with a rubric, refine. Each link is testable alone.
🔍 Click to zoom - a prompt chain: output of one call is input to the next, with a self-correction loop on the end
LiveThe self-correction pattern3 min▶

The highest-value chain is only two links longer than what you already have. Anthropic's docs describe it plainly:

  • Draft: the call you have today produces its answer.
  • Review with a rubric: a second call gets the draft plus explicit criteria ("check the quote is verbatim, the category is one of the allowed five, the JSON validates") and returns a pass/fail per criterion.
  • Refine: a third call gets the draft plus the review notes and fixes only what failed.

Why not just tell the first call "double-check your work"? Because a fresh call has no attachment to the draft. Reviewing your own answer in the same context is like grading your own exam with the answers already written in your handwriting.

The rubric is the whole trick A review call without explicit criteria drifts into vibes ("looks good!"). Write the rubric as a checklist, and reuse it later as eval criteria - Session 8 will thank you.
LiveWhen to chain, when one call is fine2 min▶
Stay with one callChain it
One task, one output shapeDistinct sub-tasks with different skills (extract, then judge, then write)
Accuracy already meets the barErrors compound mid-task and you cannot see where
Latency or cost budget is tightYou need to test, cache, or fix one step without touching the rest
The model handles it reliably in evalsDifferent steps want different context, models, or effort levels

Chaining costs latency and money - every link is a round trip. The discipline: chain when a step is measurably failing, not because diagrams look impressive. Modern models handle much more in one call than 2023 folklore suggests.

Real world

Meridian's data team split TriageBot's "summarize the week's tickets" report into decompose-and-aggregate: one call per store's tickets, then one call to merge the 80 mini-summaries. Accuracy jumped and the merge call became the only prompt they ever needed to tune.

Part 2 · the loop

Prompting agents: what changes when the model can act 8 min live

A chain is choreography you wrote. An agent chooses its own next step: it gets a goal and tools, then loops - plan, call a tool, observe the result, reflect, repeat. Your prompt stops being a request and becomes a policy: how hard to persist, when to use tools, when to stop.

Goal "Triage this refund ticket" Plan Decide next step, say it out loud Tool call lookup_order( "MR-88231") Observe Result lands in the context Reflect Done? Loop? Budget left? repeat until resolved - or the early-stop rule fires ◆ persistence + planning reminders live here ◆ tool description + one-line preamble ◆ early-stop criteria + tool budget Every ◆ is a prompt touchpoint. Agent quality is set in the system prompt, the tool spec, and the stop rules.
🔍 Click to zoom - the agent loop, with the prompt touchpoints that steer each stage
LiveThe three reminders that fix most flaky agents (GPT-4.1 guide)3 min▶

OpenAI's GPT-4.1 prompting guide found that three system-prompt reminders transform agent reliability. In spirit:

  • Persistence: "You are an agent - keep going until the user's request is completely resolved before ending your turn. Do not stop at the first uncertainty."
  • Tool-calling: "If you are not sure about facts you can look up, use your tools. Do not guess or make up an answer."
  • Planning: "Plan before each tool call and reflect on the result of the previous one - do not chain silent tool calls with no thinking in between."

They read like management advice because they are: finish the job, check instead of guessing, think between actions. Models tuned for agentic work default toward chat-style politeness (stop early, hand back to the user); these reminders flip the default.

LiveEagerness: a dial you turn in both directions (GPT-5 era)3 min▶

Newer agentic models made the opposite failure common: too much persistence. The GPT-5 guidance calls the dial agentic eagerness, and you calibrate it both ways in the prompt:

Agent gives up too earlyAgent rummages forever
Add persistence clauses: do not hand back on uncertainty, make the most reasonable assumption and note itAdd early-stop criteria: "as soon as you can name the order status, stop looking things up"
Tell it not to ask permission for steps inside its mandateSet tool budgets: "at most 2 lookups per ticket, then route to a human"

Same era, second habit: tool preambles. Ask the model to restate its plan before the first tool call and narrate progress between calls. Costs a few tokens, buys you debuggable transcripts and fewer silent wrong turns.

LiveAnthropic's agentic playbook: state, action defaults, honesty tags3 min▶

Anthropic's best-practices docs have a whole agentic section. The pieces you will reuse constantly:

  • Long-horizon state: for work that outlives one context window, tell the agent to keep progress notes in a file it updates as it goes, and to use git commits as durable checkpoints - the context window is working memory, not storage.
  • Action defaults: named snippets set the posture. <default_to_action> for agents that should just do the thing; <do_not_act_before_instructions> for agents that must wait for explicit direction. Pick one deliberately.
  • Parallel tool calls: <use_parallel_tool_calls> - when reads are independent, fire them together instead of one by one.
  • Anti-hallucination: <investigate_before_answering> - never claim a file, record, or fact exists without having looked at it in this session.
  • De-escalate the shouting: older prompts full of CRITICAL and MUST in all caps make modern Claude models overtrigger on those rules at the expense of everything else. State rules once, calmly, and reserve strong language for the one rule that genuinely is critical.
Self-studyGemini's 9-point agentic system-instruction framework2 min read▶

Google's Gemini agentic guidance arrives as a framework: nine sections a serious agent system instruction should cover. Paraphrasing the categories:

  • 1 Role - who the agent is and what it owns. 2 Objective - what done looks like. 3 Instructions - the behavioural rules. 4 Workflow - the planned sequence of steps. 5 Tool guidance - which tool for what, and what not to touch. 6 Context - the environment and data it operates in. 7 Constraints and escalation - hard limits, and when to hand to a human. 8 Output format - the shape of the final answer. 9 Examples and reminders - a worked case plus the rules worth restating at the end.

Notice how much this overlaps the GPT-4.1 template from Session 2 and Anthropic's agentic sections above. Three vendors, one converged shape: role, rules, tools, limits, format. That convergence is next session's whole subject.

Part 3 · the hidden prompt

Tool descriptions ARE prompts 4 min live

Here is the most under-engineered prompting surface in production systems: the tool spec. Teams agonize over the system prompt, then describe their most important tool as "looks up orders". The model chooses tools by reading those descriptions - they are prompts, and they deserve the same craft.

LiveWhat a well-engineered tool spec contains2 min▶
  • Name: a verb phrase the model can reason about - lookup_order, not svc_call_3.
  • Description: what it does, what it returns, and its limits, written for a reader with zero backend knowledge.
  • When to use it: the trigger conditions, concretely ("the ticket mentions an order and status affects routing").
  • When NOT to use it: the anti-triggers - the missing half in most specs, and the main cause of both tool spam and tool neglect.

One more GPT-4.1 finding with teeth: pass tools through the API's tools field, not by pasting descriptions into the prompt text. Models are trained on the structured format; in OpenAI's testing, using the tools field improved performance and hand-injected descriptions underperformed. Same message from every vendor: let the API carry the spec.

Self-studyReAct in one honest paragraph1 min read▶

ReAct (Yao et al., 2022) taught models to interleave Thought / Action / Observation as literal text you parsed with regex, and for a year every agent tutorial made you hand-roll that loop. As a prompt technique it is dead: native tool calling won, the models are trained for it, and nobody should be parsing "Action:" lines in 2026. As an architecture it is immortal - plan, act, observe, reflect is exactly the loop running inside Claude Code, Gemini's agent stack, and every harness you will ever use. Honor it as lineage; do not hand-roll it.

Build-along

TriageBot v4: it gets hands ★ 22 min · build it with me

TriageBot v3 (Session 5) classifies tickets into schema JSON, grounded in the policy manual with quote extraction, cache-shaped. Its blind spot: refund routing depends on order status, which it can only guess at. v4 gets one tool - lookup_order - and the agentic rules to use it well.

Write the tool description first. Name, description, when to use, when NOT to use. Draft it before touching the system prompt - if the spec cannot explain the tool to a colleague, the model has no chance.

Add the three agentic reminders to the system prompt: persistence (finish the triage), tool-calling (do not guess order status - look it up), planning (reflect after each result).

Add the early-stop rule. Max 2 lookups per ticket; if status is still unclear, route to a human with needs_human: true. Eagerness calibrated in both directions: it must look, and it must stop.

Dry-run a refund ticket on paper. "Order MR-88231 never arrived, refund me." Walk the loop: what does it look up? Suppose the tool returns status: delivered, signed_by: neighbor - how does the final JSON change? (Category shifts from refund to delivery-dispute, and the evidence field cites the tool result.)

Add the preamble rule. One line of plan before any tool call. Now your logs read "Checking order status because the customer claims non-delivery" instead of a bare function call - future-you debugging at 5pm will be grateful.

TriageBot v4 - system prompt additions + tool spec (steal this shape)[TriageBot v3 stays as-is above this line: role, policy manual in <policy_manual> tags, 3 few-shot examples, JSON schema, quote-grounding rule. Static, cache-shaped. New agentic block below.] Agentic rules: - You are an agent: keep going until this ticket is fully triaged. Do not stop early or hand back a half-answer. - If order status could change the routing, use the lookup_order tool. Do not guess or invent an order status. - Before each tool call, state a one-line plan. After each result, reflect on what it changes before acting again. - Early stop: at most 2 lookups per ticket. If status is still unclear, set needs_human to true and route to a human agent. - Only cite order facts that came back from lookup_order in this conversation - never from memory. --- tool spec (goes in the API tools field, NOT in this prompt) --- name: lookup_order description: Returns the current status of one Meridian Retail order: status (processing | shipped | delivered | returned), carrier, delivery date, and signature record if any. Read-only; covers the last 24 months of orders. when to use: The ticket references an order (order number, "my order", a delivery complaint) AND the routing decision depends on status - refunds, missing parcels, delivery disputes. when NOT to use: Tickets with no order dimension (store feedback, product questions, job applications), or when the customer already pasted a status you have no reason to doubt. input: order_id (string, format MR-XXXXX)
Why the tool spec sits outside the prompt box in production In the real API call, everything below the divider goes into the tools parameter as structured JSON. It is shown here so you can see the whole prompting surface in one place - system prompt and tool spec are one design, split across two fields.
Homework

Three things before Session 7 ◐ 30 min total

Source material

What this session covers

Builder-level coverage of the sources below. Official docs and guides stay with the vendors; links live in the course map.

✓Prompt chaining + self-correction patternPart 1 · Anthropic docs; decompose/aggregate per Gemini docs
✓GPT-4.1 guide - the three agentic remindersPart 2 · persistence, tool-calling, planning
✓GPT-5 era - eagerness calibration + tool preamblesPart 2 · both directions: persistence clauses vs stop criteria + budgets
✓Anthropic agentic sectionsPart 2 · state tracking, action-default tags, parallel calls, anti-hallucination, de-escalation
✓Gemini 9-point agentic system-instruction frameworkPart 2 · categories named, convergence noted
✓Tool descriptions as prompts + API tools field findingPart 3 + build-along · GPT-4.1 guide
✓ReAct (Yao et al. 2022) as architecture, not promptPart 3 · lineage paragraph; native tool calling won
Check yourself

Three questions before you go 🎯 ◐ 90 seconds

1 · The GPT-4.1 guide's three agentic system-prompt reminders are...

Finish the job, check instead of guessing, think between actions. Three sentences in the system prompt that flip a chat-tuned model into a reliable agent.

2 · Your agent keeps looking things up long after it has the answer. The eagerness fix is...

Eagerness is a two-direction dial. Under-eager agents need persistence clauses; over-eager agents need explicit stop criteria and budgets. This one is over-eager.

3 · The most under-engineered prompt surface in most tool-using systems is...

The model chooses tools by reading their descriptions, so they are prompts. Pass them through the API's tools field - and never hand-roll ReAct text loops in 2026.

Builder session 6 cheat sheet · pin this

Chain when it earns itOutput of one call = input of the next. Chain for distinct sub-tasks or compounding errors; one call when it passes evals.
Self-correctionDraft, review with an explicit rubric, refine. A fresh call grades better than "double-check your work".
The three remindersPersistence, tool-calling ("do not guess - use your tools"), planning. Paste into every agent system prompt.
Eagerness, both waysGives up early: persistence clauses. Rummages forever: early-stop criteria + tool budgets.
PreamblesOne-line plan before tool use, narrate progress between calls. Cheap tokens, debuggable transcripts.
Tool specs are promptsName, description, when to use, when NOT to. Pass via the API tools field, never pasted into prompt text.
Anthropic's tagsdefault_to_action vs do_not_act_before_instructions, parallel tool calls, investigate_before_answering. Calm language beats CRITICAL/MUST shouting.
ReAct's afterlifeDead as a prompt template, alive as the loop inside every harness. Long jobs: progress files + git as state.