AINexus
Tutorial2 min read1d ago·2 comments·5069 views

Hands-on · step by step

Tutorial: checkpointed agent loops you can safely retry

by @priya — Agent infrastructure

Four steps to durable multi-agent workflows with LangGraph and Temporal — checkpoints, tuning knobs and the failure to guard first.

Before you start — about 45 minutes · LangGraph · Temporal · Redis

Ship this in an afternoon. LangGraph does the work — the discipline is in the limits you set around it.

Step 1 — Decide what "working" means

Before touching code, write down three numbers: worst acceptable latency, cost per request, and what should happen when the upstream is unavailable. Everything after this is implementation.

Step 2 — Wire LangGraph

The whole flow is one path. No special branches for "large" inputs — express those as different limits, not different code.

// every node is checkpointed, every tool call carries an idempotency key
const graph = new StateGraph(AgentState)
  .addNode("plan", planNode)
  .addNode("act", withCheckpoint(actNode, { idempotencyKey: (s) => s.runId + s.step }))
  .addNode("verify", verifyNode)
  .addConditionalEdges("verify", (s) => (s.done ? END : "act"));

Why this works

The limit is enforced before the expensive call, not after it. Reserving budget up front means a burst degrades the caller that caused it instead of everyone downstream.

Step 3 — Guard the failure path

in-memory agent state is a lie the moment a worker gets rescheduled

Write that guard before you write the feature. It costs an hour and saves a postmortem.

Step 4 — Verify it

temporal workflow list --namespace agents | head   # all runs should be Completed
  • Lower the limit and confirm the command fails loudly
  • Kill the upstream and confirm you get a typed error, not a timeout
  • Check the metric you emit per outcome: ok, throttled, upstream_error

Tuning knobs

KnobDefaultWhat we runWhy
concurrency824Most of the wait is network, not compute
retry budgetinfinite2, with jitterUnbounded retries turn an outage into an avalanche
timeout30s8s, inherited from the callerNobody waits 30s for a chat reply

Copy it, change the limits, put the verification in CI, move on.

Comments (2)

Log in to join the discussion.

@nadia·1h ago

Curious how this holds up at 10x volume — did the queue depth signal stay stable?

@elena·1h ago

Bookmarked. The verification step is the bit most write-ups skip.