Macalinao Studio / Learn

Worked lessons · 19 November 2026

Lesson 07 / 12 · approximately 8–12 minutes

Agent loops that can stop safely

State, budgets and replay matter more than the number of roles.

UnderstandInspect evidenceTryCheck

The idea

An agent selects actions based on a task and observations. A workflow may instead follow predetermined transitions; real systems often combine both. Planning decomposes work, routing selects a path, and reflection proposes revisions. None proves that a plan is correct. Subagents can separate contexts and work, but their results still need evidence checks. A state graph may contain cycles; a DAG is acyclic. Framework names are not interchangeable with these architectural patterns. LangChain and LangGraph are distinct projects. Microsoft’s AutoGen documentation describes the project as archived and unmaintained as reviewed November 19, 2026; use it here as historical context, not a recommendation for a new production dependency.

Worked example

A fictional invoice workflow reads an invoice, drafts an approval summary and requests owner review. The payment tool times out after submission. Retrying the entire loop might pay twice. A checkpoint says the submission was attempted, while an idempotency key and payment-status lookup help determine what happened. The safe next step is reconciliation, not simply replaying all steps. A second agent agreeing with the first cannot resolve missing transaction evidence.

Use it in a workflow

  1. Define terminal success, safe failure and escalation states.
  2. Set step, elapsed-time and cost limits.
  3. Separate durable facts from temporary planning state.
  4. Require idempotent effects or explicit reconciliation before retry.

Try it without a model

Write a state table for read, draft, review, submit, unknown-result and reconciled. Which transitions require fresh evidence or approval?

Compare with the answer criteria

Review must authorize submission; unknown-result must reconcile by transaction identity before another attempt. Record a resolved outcome and stop. A changed invoice or destination invalidates an earlier approval.

Check your understanding

What should a workflow do after an ambiguous payment timeout?

Continue and verify

Connected concepts: 11, 12, 13, 16