Free webinar · Thursday, 29 October 2026

AI agent workflows,
pattern by pattern.

From one LLM call to many agents: the patterns, the trade-offs, and how to pick.

Pouria Jahandidehpjsofts.github.io · linkedin.com/in/pouria-jahandideh

Who decides what happens next: your code, or the model?

Every pattern today is a different answer to that one question.

Pouria Jahandideh · AI Agent Workflows02 / 45
Today

Five modules, one climb

  1. 01Agent fundamentalsReasoning LLMs vs agents · Tools · MCP & Skills · RAG · Context · Agent memory · Planning & reflection
  2. 02Non-agent workflowsPrompt chaining · Routing · Parallelization
  3. 03Single-agent systemsReAct · Plan & execute · Reflection & self-refining · CodeAct
  4. 04Multi-agent systemsSequential agents · Multi-agent parallelization · Supervisor · Dispatcher · Evaluator-optimizer · Peer-to-peer
  5. 05EvaluationEvaluating agents
Pouria Jahandideh · AI Agent Workflows03 / 45
The control dial

Three rungs of autonomy

01

Workflow

Your code writes the arrows.

inputLLMoutlinegatecheckLLMdraftoutputpassfail: retry
02

Single agent

The model picks the next step from tools you defined.

goalthinkacttool callobservetool resultanswerdone
03

Multi-agent

Models pick the next step, and which agent takes it.

usersupervisorsubagentsearchsubagentcodesubagenttests

More autonomy buys flexibility, and costs calls, latency and predictability.

Pouria Jahandideh · AI Agent Workflows04 / 45
How we judge a pattern

Four questions, every time

  1. 01How many calls? Calls are money and latency. Count them before you draw the boxes.
  2. 02What does each call see? Every call gets a context window. Smaller and more focused usually means better.
  3. 03Can I test one step alone? If you can’t isolate a step, you can’t tell which step broke.
  4. 04How does it fail? Loudly, silently, or by looping forever. Pick the failure you can live with.
Pouria Jahandideh · AI Agent Workflows05 / 45
01

Agent fundamentals

The parts every agent is built from

Pouria Jahandideh · AI Agent Workflows06 / 45
01 · Agent fundamentals

An agent is a loop

Call the model with tools. If it asks for a tool, run it in your code and hand the result back. Stop when it answers without asking. Everything else today is built on top of these lines.

Read more → What is an agent loop, really?
agent.ts
const messages = [system, user]while (true) { const res = await llm(messages, tools) messages.push(res) if (!res.toolCalls.length) return res.text // done for (const call of res.toolCalls) { const out = await run(call) // your code messages.push(toolResult(call.id, out)) }}
Pouria Jahandideh · AI Agent Workflows07 / 45
01 · Agent fundamentals

Reasoning LLMs vs agents

Reasoning LLM

  • Spends extra tokens thinking before it answers
  • Still one request, one response
  • Can’t look anything up or change anything
  • Better at planning, maths and multi-step logic

Agent

  • A model in a loop with tools
  • Acts, sees the result, decides again
  • Touches files, APIs, databases, the web
  • Any model can drive it, but reasoning models drive it better

A reasoning model is a better brain. An agent is a brain with hands and a loop. They compose.

Pouria Jahandideh · AI Agent Workflows08 / 45
01 · Agent fundamentals

Tools

  1. 01A tool is four things a name, a description, a JSON schema for its arguments, and your function.
  2. 02The model only proposes it emits a tool call; your code decides whether and how to run it.
  3. 03Read vs write reading is cheap to allow. Anything that changes the world goes behind a permission check.
  4. 04The description is a prompt most “the model is dumb” bugs are a vague tool description or a confusing schema.
Read more → Most agent failures are tool design failures
Pouria Jahandideh · AI Agent Workflows09 / 45
01 · Agent fundamentals

What the model actually sees

This is the whole contract. The model never sees your function, only this. Write the description as if for a new colleague: what it does, when to use it, what it returns.

tools.json
{ "name": "search_courses", "description": "Find courses matching a career goal. Use before recommending any program. Returns at most 10 results, cheapest first.", "input_schema": { "type": "object", "properties": { "goal": { "type": "string" }, "budget": { "type": "number", "description": "USD" } }, "required": ["goal"] }}
Pouria Jahandideh · AI Agent Workflows10 / 45
01 · Agent fundamentals

MCP & Skills

MCP · access

  • A protocol: an MCP server exposes tools, resources and prompts
  • Any MCP client can connect: an IDE, a chat app, your own agent
  • It standardises the plug, not what the tool does
  • Write the integration once, use it from every client

Skills · know-how

  • A folder with a SKILL.md, plus optional scripts and reference files
  • Only the name and description sit in context until needed
  • Teaches the agent how to do a job, step by step
  • Can ship code, so install them like dependencies: from sources you trust

MCP gives the agent new abilities. A skill tells it how to use the ones it has. You often want both.

Pouria Jahandideh · AI Agent Workflows11 / 45
01 · Agent fundamentals

Anatomy of a skill

The frontmatter is all the agent carries around. When a task matches the description, it reads the body, and only then the files the body points at. That is how a skill protects the context window.

skills/release-notes/SKILL.md
---name: release-notesdescription: Write release notes from merged PRs. Use when the user asks for a changelog.---1. Run scripts/merged_prs.sh <since-tag>2. Group PRs by label: feature, fix, chore3. Follow the tone in reference/style.md4. Never mention internal ticket numbers
Pouria Jahandideh · AI Agent Workflows12 / 45
01 · Agent fundamentals

RAG

Retrieval-augmented generation: index your documents ahead of time, then at question time fetch the few chunks that look relevant and put them in the prompt. New knowledge without retraining.

docschunkembedvector indexquestionretrieve top-kLLMprompt + chunkssimilar
Use when

The answer lives in documents the model has never seen: policies, catalogues, your codebase.

Watch for

When RAG is wrong it is usually retrieval, not generation. Measure whether the right chunk came back.

Pouria Jahandideh · AI Agent Workflows13 / 45
01 · Agent fundamentals

Context

  1. 01The window is the agent’s whole world on every call: system prompt, tools, history, retrieved text, tool results.
  2. 02More is not better long, noisy context makes models miss what matters, and every token is paid for again on every turn.
  3. 03Fetch just in time retrieve or read when needed instead of loading everything up front.
  4. 04Compact and offload summarise old turns, write notes to files, give a sub-task its own clean window.
Read more → Context engineering for agents
Pouria Jahandideh · AI Agent Workflows14 / 45
01 · Agent fundamentals

Agent memory

Short-term

  • The model is stateless; the message list is the memory
  • Goal, conversation, tool results, scratch notes
  • Lives in the context window, so it has to be curated

Long-term

  • Semantic: facts and documents, often searched with RAG
  • Episodic: what happened before, past runs and their lessons
  • Procedural: how to behave, from system prompts, rules files and skills

The long-term split comes from the CoALA paper (Sumers et al., 2023). It gives you a vocabulary for where a fact should live.

Pouria Jahandideh · AI Agent Workflows15 / 45
01 · Agent fundamentals

Planning & reflection

Planning · before acting

  • Break the goal into steps before taking the first one
  • Keep the plan in context, like a todo list, so long tasks stay on track
  • A plan is a hypothesis. Revise it when a step surprises you

Reflection · before finishing

  • Check the work against criteria before calling it done
  • Signals the model can’t fake (tests, linters, validators) beat self-opinion
  • Every round costs a call. Cap the rounds

Planning decides what to do. Reflection decides whether it worked, and often triggers a new plan.

Pouria Jahandideh · AI Agent Workflows16 / 45
02

Non-agent workflows

Your code owns the control flow

Pouria Jahandideh · AI Agent Workflows17 / 45
02 · Non-agent workflows

Prompt chaining

Split the task into fixed steps. Each call does one step and its output becomes the next call’s input. Between steps, plain code can check the output and stop or retry.

inputLLMoutlinegatecheckLLMdraftoutputpassfail: retry
Use when

The task splits cleanly into the same steps every time: outline, draft, translate, format.

Watch for

Latency adds up step by step, and an early mistake poisons everything after it. Check at the gates.

Pouria Jahandideh · AI Agent Workflows18 / 45
02 · Non-agent workflows

Routing

One cheap call classifies the input, then code sends it down the path built for that class: a specialised prompt, a cheaper model, or no LLM at all.

inputrouterclassifyrefund promptsmall modelplain codeoutput
Use when

Inputs fall into distinct kinds that deserve different handling, or easy ones can go to a small model.

Watch for

A wrong route fails quietly. Log every decision and give the router an “unsure” path.

Pouria Jahandideh · AI Agent Workflows19 / 45
02 · Non-agent workflows

Parallelization

Run several calls at once and combine the results. Sectioning splits the work into independent parts. Voting runs the same task several times and takes the consensus.

inputLLMsection ALLMsection BLLMsection Caggregatemerge / voteoutput
Use when

The parts don’t depend on each other, or you want more confidence: guardrails, reviews, classifications.

Watch for

You pay for every branch. The aggregator is a design problem of its own: what if the branches disagree?

Pouria Jahandideh · AI Agent Workflows20 / 45
02 · Non-agent workflows

A workflow is just functions

No framework needed. Chaining is calling one function after another, routing is a switch statement, parallelization is Promise.all. You can unit-test every line.

workflow.ts
const kind = await classify(input) // routingswitch (kind) { case 'refund': return refundFlow(input) case 'question': { const outline = await llm(OUTLINE, input) // chaining if (!isValid(outline)) throw new Error('gate') const [a, b] = await Promise.all([ // parallel llm(DRAFT, outline), llm(CHECK, outline), ]) return merge(a, b) }}
Pouria Jahandideh · AI Agent Workflows21 / 45

If you can draw the flowchart before the request arrives, you don’t need an agent.

Workflows are cheaper, faster and easier to test. Reach for autonomy only when the path really is unknown.

Pouria Jahandideh · AI Agent Workflows22 / 45
03

Single-agent systems

The model picks the next step

Pouria Jahandideh · AI Agent Workflows23 / 45
03 · Single-agent systems

ReActYao et al., 2022

Reason, then act, then observe, then reason again. The model writes down a thought, makes a tool call, reads the result, and decides the next move until it can answer.

goalthinkacttool callobservetool resultanswerdone
Use when

Open-ended tasks where the next step depends on what you just found: research, debugging, support.

Watch for

Without a step limit and a clear definition of done, it wanders. Cap steps, log every thought.

Pouria Jahandideh · AI Agent Workflows24 / 45
03 · Single-agent systems

ReAct, as a trace

Nothing here was planned in advance. Each action came from the last observation. That adaptability is the point, and it is also why you can’t predict the cost.

trace.log
goal Which services still call payments v1?think Search the code for the v1 client first.act grep("PaymentsV1Client", "services/")obs 3 files: billing, refunds, legacy-exportthink legacy-export might be dead code. Check it.act read("services/legacy-export/main.ts")obs not imported anywhere since 2024think Enough to answer.done billing and refunds. legacy-export is unused.
Pouria Jahandideh · AI Agent Workflows25 / 45
03 · Single-agent systems

Plan & execute

A planner writes the whole plan up front, then an executor works through it step by step. When a step fails, go back to the planner instead of improvising.

goalplannerstep 1step 2step 3answerfailed: replan
Use when

Long tasks with a predictable shape, where a strong planner and a cheaper executor save money.

Watch for

Plans go stale when reality surprises you. If the steps never change, you may just want a workflow.

Pouria Jahandideh · AI Agent Workflows26 / 45
03 · Single-agent systems

Reflection & self-refiningMadaan et al., 2023 · Shinn et al., 2023

Generate, critique, revise. In self-refine the model critiques its own draft. In Reflexion a real failure, like a failing test, produces a written lesson that the next attempt carries.

taskgeneratecritiquetests / rubricoutputlessonwritten downpassnext try
Use when

Quality is checkable: tests pass, a schema validates, a rubric is clear.

Watch for

A model grading itself with no outside signal tends to approve its own work. Cap the rounds.

Pouria Jahandideh · AI Agent Workflows27 / 45
03 · Single-agent systems

CodeActWang et al., 2024

Instead of one JSON tool call per step, the agent writes a small program as its action. Loops, variables and composition happen in one move, in a language the model has seen a lot of.

agentcode actionpythonsandboxno networkstdout / error
Use when

Many small operations over data: filtering, joining, calculating, batch edits.

Watch for

You are running code a model wrote. That belongs in a sandbox with no secrets and no open network.

Pouria Jahandideh · AI Agent Workflows28 / 45
03 · Single-agent systems

One action instead of five

With JSON tools this is a glob, then a read per file, then a count, each a round trip through the model. As code it is one action and one observation.

Read more → Sandboxing agent code execution
action.py
# the agent's action is a programfiles = glob("services/**/*.ts")hits = [f for f in files if "PaymentsV1Client" in read(f)]by_service = {}for f in hits: svc = f.split("/")[1] by_service[svc] = by_service.get(svc, 0) + 1print(sorted(by_service.items(), key=lambda kv: -kv[1]))
Pouria Jahandideh · AI Agent Workflows29 / 45

Start with one agent.

Most “we need multi-agent” problems are one agent that needs better tools or a cleaner context.

Pouria Jahandideh · AI Agent Workflows30 / 45
04

Multi-agent systems

Models pick the step, and who takes it

Pouria Jahandideh · AI Agent Workflows31 / 45
04 · Multi-agent systems

Sequential agents

A pipeline like prompt chaining, except every stage is a full agent with its own prompt, tools and maybe model. Each stage can plan, retry and check its own work before handing off.

briefagentresearchagentwriteagentreviewnotesdraft
Use when

Clear stages that need different tools or expertise: research, then write, then review.

Watch for

Errors compound down the line and latency stacks. Define the handoff format and validate it.

Pouria Jahandideh · AI Agent Workflows32 / 45
04 · Multi-agent systems

Multi-agent parallelization

Fan the request out to several agents at once, each with its own clean context, then merge. Sectioning splits the work; voting has several agents attempt the same thing.

questionagentown contextagentown contextagentown contextmergeor reconcileanswer
Use when

Broad questions with independent threads: research across sources, reviewing many files.

Watch for

Fast in wall-clock time, expensive in tokens. Merging conflicting findings is the hard part.

Pouria Jahandideh · AI Agent Workflows33 / 45
04 · Multi-agent systems

Supervisor

One agent keeps the big picture. It breaks the task down as it goes, briefs subagents, reads what they return and decides what next. Subagents never need to know about each other.

usersupervisorsubagentsearchsubagentcodesubagenttests
Use when

You can’t list the subtasks in advance, and each one benefits from a narrow, clean context.

Watch for

The supervisor is the bottleneck and the biggest bill. A vague brief to a subagent wastes a whole run.

Pouria Jahandideh · AI Agent Workflows34 / 45
04 · Multi-agent systems

Dispatcher

The multi-agent version of routing. A triage step reads the request and hands it to exactly one specialist agent. Only one path runs: it is a fork, not a decomposition.

requestdispatcherbilling agenttech agentsales agentthis one
Use when

Requests fall into distinct domains with different tools: billing, technical support, sales.

Watch for

A wrong handoff is hard to recover from. Let specialists hand back, and escalate when unsure.

Pouria Jahandideh · AI Agent Workflows35 / 45
04 · Multi-agent systems

Evaluator-optimizer

One agent does the work, a second agent judges it and sends back a critique, and the loop repeats until the evaluator passes it or a limit is hit.

taskoptimizeragentevaluatoragentdoneattemptpasscritique · max N rounds
Use when

There is a clear bar to clear (tests, a rubric, a spec) and quality matters more than cost.

Watch for

Context grows every round. Always set a max-iteration cap and a timeout.

Pouria Jahandideh · AI Agent Workflows36 / 45
04 · Multi-agent systems

Peer-to-peer

No coordinator. Agents message each other directly and pass work around until a stop condition fires. Every agent has to know about every other agent.

agentagentagentagent
Use when

Rarely. Debates, simulations, problems with no natural hierarchy.

Watch for

The connections grow faster than the agent count. Hardest to debug: a last resort, not a default.

Pouria Jahandideh · AI Agent Workflows37 / 45
04 · Multi-agent systems

The multi-agent cheat sheet

PatternWho decides the next agentTypical costBreaks when
SequentialFixed order, in codeLow · slowAn early stage is wrong
ParallelFixed fan-out, in codeHigh · fastResults conflict at merge
SupervisorThe supervisor, as it goesHighBriefs are vague
DispatcherThe triage step, onceLowestThe route is wrong
Evaluator-optimizerThe evaluator’s verdictGrows per roundThere is no stop condition
Peer-to-peerEvery agentHighestCoordination drifts
Pouria Jahandideh · AI Agent Workflows38 / 45
05

Evaluation

Proving any of it works

Pouria Jahandideh · AI Agent Workflows39 / 45
05 · Evaluation

What to measure

  1. 01Outcome did the world end up in the right state? Right answer, right file changed, right ticket closed.
  2. 02Trajectory did it get there sensibly? Check for forbidden actions, but don’t demand one exact path.
  3. 03Cost and latency next to success, on the same report. A 2% gain at 3× the cost is a different decision.
  4. 04Benchmarks aren’t your evals they test someone else’s task, usually once, usually only accuracy.
Pouria Jahandideh · AI Agent Workflows40 / 45
05 · Evaluation

pass@k vs pass^k

pass@k · at least one

  • Chance that at least one of k attempts succeeds
  • Goes up as k grows
  • Right when you can verify and keep the best one, like code with tests
  • 70% per run → pass@3 ≈ 97%

pass^k · every one

  • Chance that all k attempts succeed
  • Goes down as k grows
  • Right for user-facing agents, where every run is someone’s experience
  • 70% per run → pass^3 ≈ 34%

Same agent, same 70%. One number says ship it, the other says not yet. pass^k comes from τ-bench (Yao et al., 2024).

Pouria Jahandideh · AI Agent Workflows41 / 45
05 · Evaluation

Build your own evals

  1. 01Start from real failures 20 to 50 tasks taken from what actually went wrong beat a thousand synthetic ones.
  2. 02Binary pass/fail a clear check you can automate beats a fuzzy 1–10 score.
  3. 03Test the negatives cases where the agent should not call the tool, refund, or delete.
  4. 04Clean, repeatable environments as close to production as you can, reset on every run.
  5. 05Run on every change prompts, tools and models are all code. Evals are their tests.
Read more → Why your agent needs evals
Pouria Jahandideh · AI Agent Workflows42 / 45
So what do I use?

Climb only when the rung below fails

  1. 01One good callA single prompt with the right context. Most features stop here.
  2. 02A workflowYou know the steps. One or two of them need an LLM.
  3. 03One agentThe path is unknown, but the set of tools is known.
  4. 04Many agentsTruly independent sub-problems, or more context than one window can hold.

“Fails” means fails your evals, not that it feels too simple.

Pouria Jahandideh · AI Agent Workflows43 / 45
Further reading

Where these ideas come from

Pouria Jahandideh · AI Agent Workflows44 / 45

Thank you. Questions?

Build all of this yourself, from the agent loop up, in the 12-week AI Engineering course.