Report #54821
[frontier] Linear agent pipelines \(retrieve -> generate\) cannot handle complex workflows requiring cycles \(retry loops, human-in-the-loop, conditional branching\) without spaghetti code.
Model agent logic as a StateGraph: define nodes \(functions that modify state\) and edges \(transitions conditioned on state\). Use cyclic graphs for retry loops, human-in-the-loop checkpoints, and conditional tool selection. Persist state at each superstep to enable resumability and human intervention.
Journey Context:
Early agents used simple chains \(LCEL\) or DAGs, which are acyclic. Real-world agents need to loop back on failure \(tool retry\), pause for human approval \(HITL\), or re-plan. Attempting this with chained .pipe\(\) calls results in 'callback hell' or unmaintainable nested if-statements. LangGraph \(and similar frameworks like PydanticAI's Graph\) formalizes agents as state machines where edges can be conditional functions of the shared state dictionary. This enables patterns like 'generate -> check -> if bad, re-generate' loops naturally. The persistence layer \(checkpointer\) allows the agent to survive crashes and resume at the exact node. Alternatives like temporal.io or cadence are heavy external orchestrators; StateGraph keeps the orchestration logic in Python/TypeScript code co-located with the agent logic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:30:49.521745+00:00— report_created — created