Skip to content

samples(workflow): routing samples#979

Merged
wolo-lab merged 10 commits into
v2from
wolo/workflow_route_sample
Jun 8, 2026
Merged

samples(workflow): routing samples#979
wolo-lab merged 10 commits into
v2from
wolo/workflow_route_sample

Conversation

@wolo-lab

@wolo-lab wolo-lab commented Jun 7, 2026

Copy link
Copy Markdown

Samples for routing

wolo-lab added 4 commits June 7, 2026 20:41
Smallest end-to-end demonstration of workflow routing: a node
generates a random integer 1..10, the next emits a routing event
with that integer in Event.Routes, and the engine dispatches to
one of three downstream branches keyed by MultiRoute[int].

* No LLM, no HITL, no persistence — pure routing primitives.
* roll_die is a FunctionNode returning int; route_by_value is a
  custom BaseNode (FunctionNode cannot today emit Event.Routes,
  see the HITL design doc's open question on that gap).
* handle_low / handle_mid / handle_high are FunctionNodes
  receiving the typed int input that route_by_value forwarded
  via StateDelta["output"].
* math/rand/v2 in roll_die so successive runs hit different
  branches; the README shows three sample transcripts.

Run with:
  go run ./examples/workflow/route/ console
The smallest end-to-end demonstration of workflow.StringRoute and
the Event.Routes contract. A trivial classifier picks the route
based on the message's terminal punctuation: ? / . / ! map to
"question" / "statement" / "exclamation" respectively, and
the engine dispatches to one of three downstream FunctionNodes.

* No LLM, no HITL, no random.
* classifyNode is a custom BaseNode (FunctionNode cannot today
  emit Event.Routes; same gap noted in the route/ sample).
* Three handler nodes are FunctionNodes receiving the original
  message as a typed string input via StateDelta["output"].
* Direct port of adk-python's workflow_samples/route/ pattern,
  with the LLM classifier replaced by a one-line Go switch.

Run with:
  go run ./examples/workflow/route_string/ console
The smallest sample that uses an LLM as the routing brain inside
a workflow graph. Builds on the freshly-added workflow.AgentNode
to wrap an LLMAgent classifier; a trivial routing BaseNode reads
the classifier's reply from the workflow's 'output' magic state
key (LLMAgent.OutputKey="output") and emits the corresponding
Event.Routes value.

Same shape as adk-python's contributing/workflow_samples/route/
sample: LLM classifier + plain function emitting the routing
event. Two nodes, not one — keep the LLM stateless about
routing, keep routing logic in plain Go.

Three handlers (answer_question / comment_statement /
react_exclamation) read the original user message from
ctx.UserContent rather than receiving it as graph input — the
routing node only forwards the classification, not the original
text. README explains the trade-off.

Requires GOOGLE_API_KEY. Uses gemini-flash-latest (the most
evergreen tag); a comment in the README points users to swap it
for whatever model their key has access to.

Run with:
  export GOOGLE_API_KEY=...
  go run ./examples/workflow/route_llm/ console
NewAgentNode on v2 (PR #840) returns (*AgentNode, error) instead of
just *AgentNode. Handle the error in the example main.
@wolo-lab wolo-lab changed the title Wolo/workflow route sample samples(workflow): routing samples Jun 7, 2026
wolo-lab added 3 commits June 7, 2026 20:50
The route and route_string samples set Event.Actions.StateDelta["output"]
to pass the node value downstream, but the v2 engine reads node output
only from Event.Output (since the StateDelta-output channel was removed).
Routing worked, but successor handlers received the zero value. Switch
both to ev.Output and refresh the stale OutputKey/StateDelta comments in
route_llm, where AgentNode already synthesizes Event.Output.
…ents

Move the three route samples into a shared examples/workflow/routing/
folder (int, string, llm), matching the dynamic/ layout, and drop the
redundant route_ prefix. Trim sample comments that restated the code so
they focus on the routing behavior being demonstrated; keep only the
non-obvious "why" (BaseNode vs FunctionNode for Routes, defensive LLM
parsing, SubAgents registration).
…go-specific

The route README implied FunctionNode not emitting Event.Routes was an
open design question. It is specific to adk-go's FunctionNode wrapper:
adk-python has no such split — a plain function node there can
yield Event(route=...) directly. Reword to state this accurately.
@wolo-lab wolo-lab marked this pull request as ready for review June 7, 2026 21:28
@wolo-lab wolo-lab requested a review from dpasiukevich June 7, 2026 21:28
@wolo-lab wolo-lab merged commit 583f97d into v2 Jun 8, 2026
3 checks passed
@wolo-lab wolo-lab deleted the wolo/workflow_route_sample branch June 8, 2026 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants