Six core patterns for building real LLM apps — one notebook each, every example runnable, every diagram from the official docs.
A complete, runnable companion to the official LangChain page on Workflows & Agents. Designed so a beginner can read top-to-bottom and a professional engineer can skim the table of contents and copy what fits.
Written by Muhammad Abdullah — Agentic AI Engineer.
The official LangChain docs explain each pattern beautifully — but the code is small fragments and assumes you've already set up an LLM. This series:
- Bundles each pattern into a standalone notebook that runs end-to-end.
- Adds a second real-world example for every pattern (customer-support triage, study-guide generator, tweet polisher, mini research agent, and more).
- Renders the graph image at every step so you see what you just built.
- Uses plain language, with "when to use it / when not to use it" for every pattern.
Every notebook follows the same shape — concept → diagram → setup → docs example → real-world example → takeaways → exercise — so once you've read one, the rest are easy to navigate.
| # | Pattern | The idea in one line |
|---|---|---|
| 1 | Prompt Chaining | Run LLM calls in sequence — output of one becomes input of the next. |
| 2 | Parallelization | Run independent LLM calls at the same time, then combine. |
| 3 | Routing | An LLM looks at the input and picks which specialist handles it. |
| 4 | Orchestrator–Worker | A planner LLM decides what sub-tasks exist, dispatches workers, then synthesizes. |
| 5 | Evaluator–Optimizer | One LLM generates, another grades it, loop until good enough. |
| 6 | Agent | Give the LLM tools and let it decide, turn by turn, what to call. |
Patterns 1–5 are workflows — you wire the graph in advance. Pattern 6 is an agent — the LLM decides the path at runtime.
Each notebook is self-contained (the same setup cell is at the top of all of them).
00_workflows_vs_agents.ipynb — Start here
The mental model: what an "augmented LLM" is, the difference between workflows and agents, and a setup smoke test so you know your Gemini key works before class starts.
- Docs example: joke generator with a punchline-check gate
- Real-world example: rough-note → professional email refiner (draft → grammar → tone)
- Docs example: generate joke + story + poem in parallel from one topic
- Real-world example: multi-channel content generator — turn one article into a newsletter blurb, a tweet, and a LinkedIn post simultaneously
- Docs example: route requests to story / joke / poem specialists with
with_structured_output - Real-world example: customer-support triage — billing vs. technical vs. general, each with its own system prompt
- Docs example: dynamic report writer — planner picks sections, workers write them in parallel via the
SendAPI - Real-world example: study-guide generator — given any subject, plan topics → dispatch a worker per topic → assemble guide
- Docs example: generate-grade-loop for jokes ("funny / not funny" + feedback)
- Real-world example: tweet polisher with a quality bar (hook + length + single idea) and a
max_attemptssafety guard
- Docs example: arithmetic agent with
add,multiply,dividetools - Real-world example: mini research agent with
web_search(Tavily) +word_count
From the project root (one level up):
uv sync # install deps
echo "GEMINI_API_KEY=your-key" > .env # add API key
uv run jupyter lab # open notebooksThen open Agentic_Design_Patterns/00_workflows_vs_agents.ipynb and start there.
| Required for | Get it from | |
|---|---|---|
GEMINI_API_KEY |
All notebooks | https://aistudio.google.com/apikey (free tier) |
TAVILY_API_KEY |
Notebook 06's research-agent example only | https://tavily.com/ (free 1000 searches/month) |
If you skip Tavily, just don't run the second example in notebook 06 — the first example uses no external tools.
Every notebook is structured the same way, so once you've done one you can skim the rest:
- The idea in one line — the pattern in a single sentence
- When to use it / when not to — the most useful part for engineers
- The shape of the graph — official diagram + ASCII version
- Setup — copy-pasteable LLM init (same in every notebook)
- Docs example — the canonical version from the LangChain docs, ported to Gemini
- Graph visualization —
display(Image(graph.get_graph().draw_mermaid_png())) - Real-world example — a more practical use case
- Takeaways — bullet summary
- Try it yourself — exercise to extend the pattern
Predefined steps? → Prompt Chaining (1)
Independent steps that can run together? → Parallelization (2)
One of N specialists handles the input? → Routing (3)
Sub-tasks aren't known until runtime? → Orchestrator–Worker (4)
You can grade output and want to retry? → Evaluator–Optimizer (5)
Open-ended, tool-driven problem? → Agent (6)
Most real-world systems combine these — e.g. an agent whose tools are themselves chains, or a router whose branches each contain an evaluator–optimizer loop. Start simple, only add complexity when a pattern genuinely fits.
Annotated[list, operator.add]in the orchestrator–worker pattern is what makes worker outputs append to the list instead of overwriting it. Forgetting it is the #1 bug.with_structured_output(PydanticModel)is how you force a router's decision to be a clean enum value. Don't try to parse free-form text.- Always cap evaluator–optimizer loops with a
max_attemptsguard. An overly strict judge will loop forever. - AVIF images in this folder render in modern Jupyter (VS Code, JupyterLab, GitHub, nbviewer). If you see broken images in an older client, the ASCII diagram below it shows the same thing.
- Pattern definitions, canonical examples, and diagrams: the official LangChain Workflows & Agents documentation.
- The "augmented LLM" framing comes from Anthropic's Building Effective Agents post that the LangChain docs reference.
- Written by Muhammad Abdullah, Agentic AI Engineer.
MIT — fork it, teach with it, ship from it.
If this helped you, star the repo and share it with one person who's stuck building agents.