LangGraphOrchestrator is an alternative to SequentialWorkflow that uses LangGraph’s StateGraph to wire planning, execution, and monitoring as explicit graph nodes. This provides durable, inspectable state rather than plain Python control flow.
OrchestratorState
All data passed between nodes lives in aTypedDict:
results uses Annotated[..., operator.add] — LangGraph merges partial state updates by appending to this list rather than replacing it.
Building the graph
_build_graph(), the graph is wired as:
State flow
planner_node
Calls
self.planner.generate_plan(state["task"]) and sets plan, current_step_index = 0, and status = "executing" in the returned state patch.executor_node
Reads
plan[current_step_index]. If a compressor is configured, compresses the accumulated context before passing it to executor.execute_step(). Appends a {step, result, status: "pending_validation"} dict to results.monitor_node
Reads
results[-1] and calls monitor.evaluate(current_step, actual_result). On success, increments current_step_index, resets attempts to 0, and marks the result as "validated". On failure, increments attempts and appends feedback to context._route_after_monitor (conditional edge)
Decides what happens next:
"end"—status == "failed"or all steps completed (current_step_index >= len(plan))"retry"—attempts > 0and not yet failed"next_step"— step succeeded and more steps remain
"retry" and "next_step" route back to executor_node.Retry logic
When a step fails, the monitor node:- Increments
attempts - Appends
"\n[Failed Attempt Feedback]: {feedback}"tocontext - Returns
{"attempts": attempts, "context": new_context, "status": "executing"}
attempts > 0 and routes back to executor_node. If attempts > max_retries, the monitor returns {"status": "failed"} and the router terminates with "end".
Running the orchestrator
run() builds the initial state and calls self.graph.invoke(initial_state), which runs the compiled StateGraph to completion and returns the final OrchestratorState.
LangGraphOrchestrator vs SequentialWorkflow
LangGraphOrchestrator
State is an explicit
TypedDict passed through graph nodes. LangGraph manages transitions, enabling inspection, checkpointing, and replay. Context compression is built in via the compressor parameter.SequentialWorkflow
State is implicit Python variables (
context, results, attempts). Simpler setup with no LangGraph dependency. Compression is driven by tools[0] if present.Both approaches implement the same Plan-Execute-Monitor loop. Prefer
LangGraphOrchestrator when you need durable execution, state inspection, or plan to add branching logic. Use SequentialWorkflow for simpler setups where plain Python control flow is sufficient.