samples(workflow): routing samples#979
Merged
Merged
Conversation
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.
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.
dpasiukevich
approved these changes
Jun 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Samples for routing