Spring AI for Beginners

Module 14 of 17

Module 14: Agentic Patterns

5 min read881 words
What you'll learn
Explain the progression from a single call to autonomous agentsDescribe the five core agentic workflow patternsChoose the right pattern for a taskSee how each is orchestrated with `ChatClient`

"One LLM call answers a question. Many orchestrated calls — chained, parallelized, routed, refined — solve real problems. That's what makes a system agentic."

Level: Intermediate · Time: ~4–5 days · Prerequisites: Modules 4–13

Learning Objectives

By the end of this module, you will be able to:

  • Explain the progression from a single call to autonomous agents
  • Describe the five core agentic workflow patterns
  • Choose the right pattern for a task
  • See how each is orchestrated with ChatClient

1. From One Call to Orchestration

So far, most interactions were "one prompt → one response." That's fine for simple tasks, but real problems need multiple coordinated steps. There's a clear progression:

LevelWhat it does
Single LLM callOne prompt → one response ("summarize this")
Enhanced LLMAdds retrieval, tools, memory (RAG + tools)
WorkflowMultiple calls orchestrated in code (this module)
Autonomous agentThe model decides its own next steps
The enhanced LLM — the building block you orchestrate
The enhanced LLM — the building block you orchestrate

The enhanced LLM (a call boosted with retrieval, tools, and memory — everything from Modules 5–13) is the building block. Agentic workflows combine many of these calls.

The jump from a single call to a workflow is like the jump from one function to a whole program: the individual pieces are familiar, but arranging them in the right order — and letting some run in parallel — is where real capability emerges.

Concept: "Agentic" doesn't require a mysterious autonomous robot. Most production "agents" are workflows — several LLM calls wired together in code you control. Reliable and easy to reason about.

2. Pattern 1 — Chain

Break a task into sequential steps, each transforming the previous output (extract → standardize → sort → format). Decomposition raises accuracy.

Chain workflow: each step feeds the next
Chain workflow: each step feeds the next

Use it for: multi-stage transformations where order matters.

For example, turning messy meeting notes into a task list: step one pulls out every action item, step two rewrites each in a consistent format, step three groups them by owner. Each call is simple and easy to check, and because the output of one feeds the next, mistakes are caught early rather than compounding.

3. Pattern 2 — Parallelization

Run independent subtasks at the same time, then combine. Translate a document into French, Spanish, and German concurrently — or ask several models to "vote" for a better answer.

Parallelization: independent calls run concurrently
Parallelization: independent calls run concurrently

Use it for: independent subtasks (throughput) or multi-perspective voting (quality).

4. Pattern 3 — Routing

Classify the input first, then send it to a specialized handler. A support ticket is classified (billing? technical? refund?) and routed to the best-fit prompt or workflow.

Routing: classify, then dispatch to the right handler
Routing: classify, then dispatch to the right handler

Use it for: varied inputs that each deserve specialized handling.

Real-world use case: A helpdesk routes "I was charged twice" to a billing workflow and "the app crashes" to a technical one — each handler is tuned for its domain, so answers are sharper than one catch-all prompt.

5. Pattern 4 — Orchestrator-Workers

A central orchestrator LLM breaks a big task into subtasks and delegates each to worker calls, then assembles the results. Unlike a fixed chain, the orchestrator decides the breakdown dynamically.

Orchestrator-workers: a lead LLM delegates to workers
Orchestrator-workers: a lead LLM delegates to workers

Use it for: complex tasks whose sub-steps aren't known in advance.

Real-world use case: Ask an agent to "research and summarize three competitors." The orchestrator decides — at runtime — that it needs one worker per competitor, dispatches them in parallel, then merges their findings into a single report. A fixed chain couldn't adapt to two competitors or five.

6. Pattern 5 — Evaluator-Optimizer

Generate → evaluate → refine, in a loop. One call produces a draft; another critiques it against criteria; the first revises. Repeat until it's good enough.

Evaluator-optimizer: iterate until quality criteria are met
Evaluator-optimizer: iterate until quality criteria are met

Use it for: highest-quality output — code, important writing — where a review loop pays off.

Common mistake: Jumping straight to a fully autonomous agent. Start with the simplest pattern that works — often a chain or router. Add complexity only when a real limitation demands it. Simpler workflows are more reliable and cheaper.

✅ Checkpoint

  1. What's the difference between a "workflow" and an "autonomous agent"?
  2. Which pattern classifies input and dispatches to a specialized handler?
  3. Which pattern uses a generate-evaluate-refine loop?

Answers: 1) A workflow orchestrates multiple LLM calls through code paths you define; an autonomous agent decides its own next steps. 2) Routing. 3) Evaluator-optimizer.

Key Takeaway: Agentic systems orchestrate many enhanced-LLM calls. The five core patterns are Chain (sequential steps), Parallelization (concurrent subtasks/voting), Routing (classify then dispatch), Orchestrator-Workers (dynamic delegation), and Evaluator-Optimizer (iterative refinement). All five are built with plain ChatClient calls — start with the simplest pattern that solves your problem.

Further Learning

Part of "Spring AI for Beginners." Adapted from Microsoft's open Spring AI curriculum (MIT License).