Distributed Graph Orchestration: Combining Local and Remote Graphs
This article explains how to split agent workflows into a local orchestration graph and remote execution graphs, using a looping math engine as the example. It covers the responsibility boundary between stateful orchestration and stateless remote decision-making, conditional routing within a single remote graph, sequential versus parallel (fan-out/fan-in) invocation patterns, and key design points such as explicit termination signals, human-in-the-loop hooks, observability, and failure isolation. It also outlines local development and debugging practices for both graphs.
Distributed Graph Orchestration: Combining Local and Remote Graphs
1. Why Split a Graph in the First Place
Once an agent’s business logic grows from a single linear chain into a multi-branch, multi-role collaboration flow, cramming every node into one graph quickly creates three problems. Responsibilities get mixed together, with flow control, domain computation, and external input collection tangled in the same place. The graph can no longer scale independently, because compute-heavy nodes are forced to share a release lifecycle with orchestration nodes. And debugging becomes painful, since any single change requires restarting the entire flow.
A common industry approach is to layer orchestration and execution separately: one local orchestration graph handles flow control and state progression, while several remote graph servers handle the actual computation. The key to this split is a clear responsibility boundary for state management and control flow. The orchestrator holds the global context and decides what happens next; the executor receives only the minimum necessary input and returns a structured result.
This article uses a looping math engine as the example. The local graph orchestrates a remote graph that randomly picks a math operation and generates a random number, looping until the remote graph returns the termination signal end. The orchestrator is implemented in two ways, sequential and parallel, so the trade-offs can be compared.
2. Overall Architecture and Responsibilities
The system consists of two graphs:
- Remote service graph (math_service): runs on a development server, accepts an
actionfield, wherepick_operationreturns a random math operation orend, andgenerate_numberreturns a random integer. - Local orchestration graph (math_orchestrator): runs as a regular script, accepts an initial number, calls the remote graph twice per iteration (each with a different
action), performs the math operation, and stops when it receivesend.
The responsibility boundary comes down to one sentence: the remote graph makes stateless decisions, the local graph drives stateful progression. The remote graph is unaware of the iteration count or prior results, and the local graph does not implement any domain algorithm.
3. Remote Graph Implementation: Conditional Routing Reuses One Graph
The remote graph uses conditional routing to handle two operations within a single graph, avoiding a separate deployment for each capability. The state is defined as follows:
import randomfrom typing import TypedDictfrom langgraph.graph import StateGraph, START, ENDclass MathServiceState(TypedDict):action: str # "pick_operation" or "generate_number"operation: str # "add"/"subtract"/"multiply"/"divide"/"end"number: int # random integermanual_input_chance: float # probability of requesting user input, 0.0-1.0ask_user: bool # True means the orchestrator should prompt the user
The routing function reads action to decide the branch. The two branch nodes write operation and number respectively, then converge at the end node. The benefit of this design is that adding a new operation only requires extending the enum and adding one branch node, with no change to the service topology.
Keep the directory structure minimal:
math_service/├── graph.py├── langgraph.json├── auth.py└── .env
Example dependency declaration:
[project]name = "random-math-service"version = "0.1.0"requires-python = "==3.13"dependencies = ["langgraph", "langgraph-cli", "langgraph-sdk"]
Note that Python 3.13 is chosen because some data validation libraries are not yet fully compatible with 3.14 and above. This is a temporary constraint and can be revisited as the ecosystem matures.
4. Local Orchestration Graph: Sequential and Parallel Flows
Sequential flow
The remote graph is called twice in sequence: the first call fetches the operation type, the second fetches the operand. The structure is straightforward and results are highly deterministic, which suits scenarios where remote resources are tight or where strict rate limiting and cost sensitivity matter. The cost is that the two network round trips add up serially, so end-to-end latency equals the sum of both calls.
Parallel flow
The remote graph is called twice at the same time using a fan-out/fan-in pattern. Both branches are launched concurrently within the same iteration and converge before the operation is executed. Latency is close to a single call and throughput is higher. The cost is a higher demand on the remote service’s concurrency capacity, plus the need for a clear strategy for overall rollback or retry when a branch fails.
Which to choose: prefer parallel when there are many iterations and each computation takes noticeable time; prefer sequential when remote-side quota is limited or when you need fine-grained observation of every single call.
5. Key Design Points
- Make termination explicit: use
operation == "end"as the only termination signal, avoiding implicit conventions such as a maximum iteration count. - Human-in-the-loop hook: the remote graph expresses the intent “user input is needed” through
manual_input_chanceandask_user, while the orchestrator handles the actual interaction, keeping the remote side decoupled from any UI. - Observability: tag every remote call with the iteration number and
action, making it easy to tell in log services and monitoring alerts whether the orchestration or the execution is slow. - Failure isolation: define a clear strategy when any parallel branch fails, either failing the whole thing and retrying, or degrading to sequential execution.
- Environment consistency: the local and remote graphs share the same state contract definition, preventing field drift.
6. Local Development and Debugging
Both graphs run locally: the remote graph runs on a development server, and the local graph runs as a regular script. The practical value of this mode is:
- You can integration-test the control flow without standing up a full production environment.
- After modifying the remote graph, hot reload applies and the orchestration side is unaffected.
- You can use breakpoints to inspect each state write and quickly verify routing branches.
To migrate to the cloud later, the remote graph can be containerized and deployed on a container platform, a message queue can decouple things asynchronously, object storage can archive run artifacts, and a unified logging and monitoring system can observe end-to-end latency.
7. Conclusion
Combining a local graph with a remote graph is fundamentally about using a clear contract to decouple flow control from domain computation. Sequential and parallel are not a matter of better or worse, but a trade-off among resources, latency, and observability. Once you master the four patterns of conditional routing, fan-out/fan-in, explicit termination, and human-in-the-loop hooks, complex multi-service agent orchestration can stay structurally clear and well-bounded.
