LangGraphOrchestrator wires a PlanningAgent, ExecutionAgent, and MonitoringAgent into a compiled LangGraph state machine. Each node in the graph corresponds to one agent; a conditional router after the monitor node decides whether to advance to the next step, retry the current step, or terminate.
Import
Constructor
Responsible for decomposing the input task into an ordered list of step strings via
generate_plan(task).Executes a single step given the step description and accumulated context via
execute_step(step, context=...).Evaluates an execution result against the step objective via
evaluate(objective, result). Must return a dict with "success" (bool) and "feedback" (str) keys.Optional context compressor. Called before each executor invocation when accumulated context is non-empty. Must expose either an
invoke(text) or _run(text) method. Typically a CompressContextTool or a local agent.Maximum number of retry attempts for a single step before the orchestrator sets
status to "failed" and terminates.State Machine
OrchestratorState fields
The full state dictionary passed between every node:
| Field | Type | Description |
|---|---|---|
task | str | The original task string |
plan | List[str] | Steps generated by the planner |
current_step_index | int | Index into plan for the active step |
context | str | Accumulated results from completed steps |
results | List[Dict[str, Any]] | Result records (append-only via operator.add) |
attempts | int | Retry counter for the current step |
max_retries | int | Copy of the constructor value |
status | str | "planning" → "executing" → "success" | "failed" |
Nodes
| Node | Role |
|---|---|
planner_node | Calls generate_plan, sets plan and resets current_step_index to 0 |
executor_node | Runs the current step, appends a "pending_validation" result entry |
monitor_node | Validates the latest result; updates status, context, and attempts |
Routing after monitor_node
| Route key | Condition | Destination |
|---|---|---|
"next_step" | Step validated; more steps remain | executor_node |
"retry" | Step failed; attempts ≤ max_retries | executor_node |
"end" | All steps done or status == "failed" | END |
Methods
run
Invokes the compiled LangGraph state machine and returns the final state.
The high-level task or question to orchestrate.
Return value
The returned dictionary is the finalOrchestratorState. Key fields:
Final workflow status. One of
"success", "failed", or "executing" (if the graph terminated unexpectedly).The full ordered list of steps generated by the planner.
All result records accumulated during execution.
The accumulated context string built from all validated step results.
The index of the last step that was processed.
The retry counter at the time the graph terminated.
The configured maximum retries value.