Dynamic Edge Computation: Computing Target Nodes at Runtime
When static conditional edges are not enough, compute target nodes at runtime with dynamic workflows, ctx.run_node, and Event(route=...) routing — and know which tool to choose.
Published on • December 2, 2026
AI Assistant

A router node returns Event(route="ESCALATE") and the dispatch dict sends it to escalate_to_lawyer. Clean, reviewable, deterministic — until the requirement becomes “route to whichever of our twelve regional desks is on shift,” where the target is a lookup result that does not exist when the graph is constructed. You can enumerate twelve routes… but the thirteenth desk goes live next quarter, and the graph has to be recompiled for a data change.
Static conditional edges excel at known branching. They cannot express a target computed from runtime data, a loop whose bound arrives with the input, or recursion. For those, ADK 2.0 offers dynamic workflows: an orchestrator node whose body — ordinary Python — decides what to run next via ctx.run_node(). This post compares the two dispatch mechanisms and shows when each earns its place.
Prerequisites
- Comfort with static graph routing:
Event(route=...), dispatch dicts,DEFAULT_ROUTE. Our conditional edge routing post covers the fundamentals. - ADK 2.0 dynamic workflow basics:
@node,Context,ctx.run_node(), andrerun_on_resume=Truefor orchestrators (see the dynamic workflows guide and our resume post).
1. What static conditional edges can (and cannot) do
The static mechanism has two halves. A router node emits a route value:
from google.adk import Event
def router(node_input: str):
if condition(node_input):
return Event(route="RUN_TASK_C")
return Event(route="RUN_TASK_B")
and an edge row maps each value to a node:
root_agent = Workflow(
name="routing_workflow",
edges=[
("START", task_A_node, router),
(router, {
"RUN_TASK_B": task_B_node,
"RUN_TASK_C": task_C_node,
DEFAULT_ROUTE: task_B_node,
}),
],
)
This is excellent engineering: the topology is declarative, reviewable, diffable — and the set of targets is fixed at construction time. Every branch you could ever take must be written into the dict. That constraint is exactly where it breaks down:
- Targets computed from data. “Run the node named in this database row” has no dict form.
- Data-dependent iteration counts. A cycle must contain a routed edge (the engine rejects unconditional cycles), and every loop iteration funnels back through the same nodes — fine for “retry until clean,” awkward for “process however many pages the API returned.”
- Unbounded fan-out. Static graphs fan out to a fixed set of nodes feeding a
JoinNode. “One branch per item in a list of unknown length” is not a static topology. - Recursion / self-similar decomposition. A graph cannot contain itself as a node in any meaningful finite way.
When the set of targets or the number of steps is runtime data, stop fighting the edge list.
2. Dynamic workflows: the body is the router
A dynamic workflow replaces edge-declared routing with code. The orchestrator is an async node that calls ctx.run_node() wherever the next step is computed:
from google.adk import Context, Workflow
from google.adk.workflow import node
@node(rerun_on_resume=True) # required: this body calls ctx.run_node()
async def dispatch_orchestrator(ctx: Context, node_input: str):
desk = await lookup_on_shift_desk() # runtime-computed target
result = await ctx.run_node(desk.node, node_input)
return result
ctx.run_node() accepts any node-like value — an LlmAgent, a function node, another Workflow — without wrapping. That is what makes the target genuinely dynamic: desk.node was resolved a millisecond ago from live data.
Three route shapes map to ordinary Python control flow.
Sequence route
Await ctx.run_node() calls in order; each finishes before the next starts:
@node(rerun_on_resume=True)
async def city_workflow(ctx: Context):
city = await ctx.run_node(city_generator_agent)
city_time = await ctx.run_node(city_time_function, city)
report_text = await ctx.run_node(city_report_agent, city_time)
return report_text
Data flows through return values — no session-state reads between steps.
Loop route
An iteration is a plain while/for, bounded by its own condition rather than by a back-edge that the graph validator must accept:
@node(rerun_on_resume=True)
async def code_workflow(ctx: Context, node_input: str):
code = await ctx.run_node(coder_agent, node_input)
check_resp = await ctx.run_node(compile_lint_check, code)
while check_resp.findings:
code = await ctx.run_node(
fixer_agent,
{"code": code, "findings": check_resp.findings},
)
check_resp = await ctx.run_node(compile_lint_check, code)
return code
Compare this with the static loop: no router, no "RETRY" route, no DEFAULT_ROUTE — and the loop bound lives next to the loop instead of in a dispatch table three edges away. Values stay in local variables; on resume, the re-entered body rebuilds them from checkpointed child results.
Parallel route
Fan out by collecting coroutines rather than listing nodes — the count can be anything:
import asyncio
@node(rerun_on_resume=True)
async def parallel_supervisor(ctx: Context, node_input: list):
tasks = [
ctx.run_node(worker_node, item, use_sub_branch=True)
for item in node_input # N known only at runtime
]
results = await asyncio.gather(*tasks)
return results
use_sub_branch=True isolates each run’s events so concurrent children don’t interleave their traces. On resume, only failed or interrupted workers re-execute — checkpointing applies to parallel children too.
One detail that matters for exactly this topic: run IDs are assigned in call order. Build your task list in a synchronous loop (as above) so the ordering — and therefore the checkpoint keys — is deterministic across a resume. Scheduling children in a non-deterministic order would mismatch checkpoints on restart.
3. When static routing is still the answer
Dynamic control flow is not an upgrade over conditional edges; it is a different trade. Event(route=...) retains real advantages:
- The topology is inspectable. You can read, export (see our visualization post), and review every possible path without executing anything.
- Validation happens at build time. The engine rejects broken graphs when the
Workflowis constructed: no unconditional cycles, one terminal output, route targets that exist. - Fan-out targets are explicit. A
JoinNodewaits on named predecessors; you know exactly who must produce output. - Dispatch is data, not logic. The route dict can be diffed and tested without a model call or a database.
A good rule of thumb:
| Choose… | When |
|---|---|
| Static conditional edges | The branch set is known when you write the code; each target is a fixed node; you want the path visible in review. |
| Dynamic workflow | The target is computed at runtime (lookup, data, model output naming a node); loop bounds or fan-out counts arrive with the input; you need recursion. |
| Both | Common in practice: a dynamic orchestrator whose inner steps are a small static Workflow, or a static graph whose router emits a route that resolves to a dynamic sub-process. |
The hybrid is the mature pattern. Keep the coarse, review-worthy structure static — classify, enrich, export — and localize dynamism inside one orchestrator node that owns its loop or its runtime target list. A thirty-node static graph with three dynamic sprinkles is unreadable; a five-node static graph wrapping one dynamic “process N items” node is not.
4. A decision walkthrough
Take the regional-desk problem from the intro and work the options:
- Enumerate twelve routes. Correct today, wrong next quarter — and the on-shift desk is still a lookup, so you have both static and dynamic routing stacked on top of each other.
- Let the router emit a route naming the desk, and add a dynamic node as the dict’s default. The dict stays fixed; only the dynamic node computes its children. This works, but you have invented a two-tier dispatch for what is really one decision.
- Make the dispatch node dynamic. The orchestrator looks up the desk, then
ctx.run_node(desk.node, ...)— one mechanism, target computed where the data is, loop/recursion available if a desk needs multi-step handling.
Option 3 wins whenever the target is data. Option 1 wins when a human should be able to read every possible destination in the PR.
Checklist
- Every static router’s route values are enumerable in a test — including
DEFAULT_ROUTE. - Dynamic orchestrators set
rerun_on_resume=True(their bodies callctx.run_node()). - Fan-out task lists are built in deterministic call order so run IDs — and checkpoints — line up.
- Parallel children use
use_sub_branch=True(or equivalent isolation) to keep traces separable. - Loop bounds in dynamic bodies have a hard safety cap where the condition could be unbounded.
- Dynamism is contained in dedicated orchestrator nodes, not smeared across the whole graph.
- Static topology is exported/documented so reviewers still see the overall shape.
The edge list answers “what can happen next?” with names. The orchestrator body answers it with data. Static routing makes the question visible; dynamic routing makes it possible. Knowing which question your workflow is actually asking is the whole skill.