L

Learn AI

Track progress · learn offline

Open

Lesson 6 of 7

Agent patterns — ReAct / Plan-and-Execute / Reflexion

8 min read

The loop is think → act → observe. But how it decides varies. Three patterns cover most agents you'll build — and knowing which to reach for saves you a rewrite.

Three ways to run the loop

The bare loop has variants. ReAct interleaves reasoning and action — think, act, observe, repeat — the default for open-ended tool use. Plan-and-Execute plans the whole route up front, then runs the steps — fewer model calls, better for tasks you can lay out in advance. Reflexion adds self-critique: try, judge your own output, retry with that feedback — for hard tasks where the first attempt usually misses.

ReAct reacts step by step; Plan-and-Execute commits to a plan first; Reflexion critiques and retries. Same loop, three different control shapes.

Choosing between them

Match the pattern to the task. Unpredictable, tool-heavy work → ReAct: it adapts each step. A task you can decompose cleanly → Plan-and-Execute: cheaper and more legible. A task with a checkable result — code that must pass tests, an answer you can grade → Reflexion: the critique loop earns its extra cost. Many real agents combine them.

There's no best pattern, only a best fit: ReAct for adaptability, Plan-and-Execute for efficiency, Reflexion for quality on checkable tasks.

Every extra loop costs latency and tokens. Reflexion's retries and ReAct's step-by-step reasoning are powerful but not free — cap the iterations and stop early when the result is good enough.

The shape of it

Your agent writes code that must pass a test suite, and its first attempt often fails. Which pattern fits best?

Continue in the app

Take the whole AI Agents in Production course — tracked

Get your personalized path, progress and streaks in the app — this lesson and every next one, in order.