Back to Knowledge Base

Runnable Agents Lab

Agent patterns are the hardest, most hype-laden part of AI engineering, and prose alone doesn't build intuition. Here you can step through pre-recorded runs of the real patterns from the agents-lab/ Python package — watch a thought become a tool call, a tool result re-enter the loop, and the loop finally stop. For the theory behind them, read agent architectures and the code-first ReAct agents lab.

How to read a trace

Thoughtthe model reasons about what to do next
Actiona tool call (or an executed step), with its input
Observationthe real result fed back into the loop
Critiqueself-evaluation / verbal reflection on an attempt
Planan up-front decomposition into steps
Finalthe answer the run terminates on

When to use which

ReActReach for ReAct as the default when the task needs a few tool calls and each next move depends on what the last observation returned — lookups, calculations, short multi-hop questions. It is the cheapest pattern to build and debug, but it decides one step at a time with no plan and no memory of past runs, so it can wander or repeat itself on longer tasks.
ReflexionReach for Reflexion when you have a reliable way to tell success from failure — a unit-test runner, a grader, a checker — and a first attempt often misses. The self-reflection turns that signal into a lesson the next attempt can use, so it excels on tasks that are hard to get right in one shot but easy to check. It needs that trustworthy evaluator; with a noisy or missing signal it reflects on nothing and just burns trials.
Plan-and-ExecuteReach for Plan-and-Execute when the task decomposes cleanly into steps you can name in advance — multi-part questions, pipelines, anything where a stated plan keeps a long run on track. Committing to a plan cuts drift and makes the trajectory auditable, but that same commitment is a weakness when reality diverges from the plan; the replanner is what buys back some adaptivity between steps.

ReAct — one trip through the reason-act-observe loop

The smallest possible agent: an `agent` node (DeepSeek bound to tools) and a `tools` node, wired by one conditional edge that loops back until the model stops calling tools or the step budget runs out. This task needs exactly one tool call, so you see a single clean pass through the loop.
TASKWhat is 17 * 23, minus 100?
SOURCEagents-lab/agents_lab/react.py
RUN ITuv run python -m cli react "What is 17 * 23, minus 100?"
PAPERReAct: Synergizing Reasoning and Acting in Language Models (ICLR 2023) · arXiv:2210.03629
Step 1 of 4
Thoughtnode: agent

Reason

I need to compute 17 × 23 and then subtract 100. That is exact arithmetic — I should not do it in my head, I should call the calculator so the result is ground truth rather than a guess.

What to notice: This is the 'reason' half of ReAct. The thought is where tool selection happens — the model decides *which* tool and *why* before it acts. The paper's key ablation showed that acting without this thought makes the model pick tools poorly and flail when a result surprises it.

Tip: press Play to watch the loop run, or use the ← / → arrow keys to step through it yourself.

Reflexion — fail, self-critique in words, retry

An actor attempts the task, an evaluator judges it, and on failure a reflect step writes a short *verbal* self-reflection that is carried into the next attempt's prompt. No weights change — the 'reinforcement' is natural language. Here a deterministic word-count evaluator gives a crisp pass/fail signal, so you can watch one failed trial turn into a corrected one.
TASKWrite an example sentence that is exactly seven words long.
SOURCEagents-lab/agents_lab/reflexion.py
RUN ITuv run python -m cli reflexion "Write an example sentence that is exactly seven words long."
PAPERReflexion: Language Agents with Verbal Reinforcement Learning (NeurIPS 2023) · arXiv:2303.11366
Step 1 of 6
Actionnode: actor

Attempt 1

"The waves crashed loudly against the rocky shore." — that reads like about seven words to me.

What to notice: The actor runs with an empty lessons list — a plain first try, no memory yet. Reflexion adds nothing to a single attempt; its whole value appears only across trials.

Tip: press Play to watch the loop run, or use the ← / → arrow keys to step through it yourself.

Plan-and-Execute — decompose first, then run the steps

A planner writes the whole plan up front, an executor runs one step at a time, and a replanner inspects the results after each step and either continues or emits `FINAL:`. Front-loading the plan reduces the per-step drift of a pure ReAct loop, at the cost of some in-flight flexibility.
TASKA team of 3 reads 40 pages/day each. How many days to finish a 1,320-page book, and what weekday do they finish if they start on a Monday?
SOURCEagents-lab/agents_lab/plan_execute.py
RUN ITuv run python -m cli plan-execute "A team of 3 reads 40 pages/day each. How many days to finish a 1320-page book, and what weekday do they finish if they start Monday?"
PAPERUnderstanding the Planning of LLM Agents: A Survey (plan-then-execute taxonomy); see also Wang et al., Plan-and-Solve (2024 / ACL 2023) · arXiv:2402.02716
Step 1 of 11
Plannode: plan

Plan

1. Compute the team's combined pages-per-day rate.

2. Divide the total pages by that rate to get the number of days.

3. Count that many days forward from Monday to find the finish weekday.

What to notice: The planner emits the entire decomposition BEFORE any step runs — this is the defining difference from ReAct, which decides one action at a time. A stated plan is what cuts per-step drift on long tasks and makes the whole trajectory auditable up front.

Tip: press Play to watch the loop run, or use the ← / → arrow keys to step through it yourself.