LangGraphOrchestrator is a production-grade alternative to SequentialWorkflow. Rather than a plain Python loop, it models the planner → executor → monitor pipeline as a LangGraph state machine, giving you full visibility into state transitions and clean retry semantics.
The state machine
The graph has three nodes connected by edges:| Node | What it does |
|---|---|
planner_node | Calls PlanningAgent.generate_plan() to produce a list of step strings |
executor_node | Calls ExecutionAgent.execute_step() on the current step, optionally compressing context first |
monitor_node | Calls MonitoringAgent.evaluate() and decides whether to advance, retry, or abort |
monitor_node, a conditional edge (_route_after_monitor) chooses one of three routes:
next_step— step succeeded, advancecurrent_step_indexand loop back toexecutor_noderetry— step failed but retries remain, loop back toexecutor_nodewith failure feedback appended to contextend— all steps complete or max retries exceeded, exit the graph
Building the orchestrator
Initialize the LLM and create agents
Different agents can use different LLMs. In
main.py, the monitor uses a cloud model while the planner and executor use a local one:Choose a context compressor (optional)
The compressor runs on accumulated context before each
executor_node call. Two options are available:- LocalAgent (Ollama)
- CompressContextTool (no LLM)
LocalAgent uses the local LLM to summarise context aggressively. It is preferred when Ollama is running, because it produces semantically dense summaries.Instantiate the orchestrator
__init__ via _build_graph() and reused across calls to .run().Interpret the result
The return value is the full Only steps with
OrchestratorState dictionary:status == "validated" have a usable result. Steps marked "failed" were rejected by the monitor.Retry behaviour
Theattempts counter in OrchestratorState tracks failed attempts for the current step. It is reset to 0 every time a step succeeds.
Context compression
Before each call toexecutor_node, the compressor runs on the accumulated context string:
invoke or _run method as a compressor — both LocalAgent and CompressContextTool satisfy this interface.