Skip to content

docs(examples/workflow): add a WithUseAsOutput sample - #922

Merged
wolo-lab merged 4 commits into
mainfrom
wolo/run_node_use_as_output_sample
Aug 27, 2026
Merged

wolo-lab merged 4 commits into
mainfrom
wolo/run_node_use_as_output_sample

Conversation

@wolo-lab

@wolo-lab wolo-lab commented May 29, 2026

Copy link
Copy Markdown
Contributor

Problem

The workflow examples cover dynamic orchestration (dynamic/basic) and calling an LlmAgent from a dynamic body (dynamic/llm), but none of them shows output delegation. workflow.WithUseAsOutput() promotes a child's output to the parent dynamic node's terminal output. Without it the same value rides two events, the child's own event and the orchestrator's terminal event. With it only the child's event carries the value, stamped for both node paths, so an LlmAgent's reply reaches the caller authored by the agent instead of being restated by the workflow. There was no runnable sample for the option and no entry for it in the workflow example index.

Summary

Adds examples/workflow/dynamic/use_as_output/ and registers it in examples/workflow/README.md. The layout follows the sibling samples: a main.go plus a README with concept bullets, goal, auth block, Mermaid diagram, run command, example session, and a "what it shows" table.

A single orchestrator holds both behaviors so the contrast is visible from the console. An in-scope request is delegated to an LlmAgent child with WithUseAsOutput(). Anything else is answered by the orchestrator's own return, without calling the model at all.

Which branch runs is decided by a substring check on the user's request rather than by anything the model produces, and that is deliberate. An earlier draft gated on the length of the generated email, so the delegating branch — the only thing the sample exists to show — never ran: drafts measured 412 and 506 characters against a 60-character threshold. A guard evaluated in Go before the model call keeps both branches reachable on demand and makes the session in the README reproduce.

The orchestrator is the last node in the graph, which is the shape that works today. A successor placed after a delegating dynamic node receives the zero value instead of the delegated output, which is a separate engine defect and out of scope here.

@wolo-lab
wolo-lab force-pushed the wolo/run_node_use_as_output branch from 982aa73 to 1ebaccb Compare May 29, 2026 19:10
@wolo-lab
wolo-lab force-pushed the wolo/run_node_use_as_output_sample branch from 3b93b94 to 01ce85a Compare May 29, 2026 19:10
@wolo-lab
wolo-lab force-pushed the wolo/run_node_use_as_output branch from 1ebaccb to f864f49 Compare May 29, 2026 19:18
@wolo-lab
wolo-lab force-pushed the wolo/run_node_use_as_output_sample branch 2 times, most recently from 8e5abba to f04ccc5 Compare May 29, 2026 19:34
@wolo-lab
wolo-lab force-pushed the wolo/run_node_use_as_output branch from f864f49 to 94fd0ec Compare May 29, 2026 20:03
@wolo-lab
wolo-lab force-pushed the wolo/run_node_use_as_output_sample branch 5 times, most recently from b1644a5 to 7948949 Compare May 30, 2026 15:41
@wolo-lab
wolo-lab force-pushed the wolo/run_node_use_as_output branch 15 times, most recently from 467581b to 3f8bec4 Compare June 5, 2026 12:36
@wolo-lab
wolo-lab force-pushed the wolo/run_node_use_as_output_sample branch from 6c18731 to 915433d Compare June 5, 2026 19:24
@wolo-lab
wolo-lab changed the base branch from wolo/run_node_use_as_output to wolo/output-for June 5, 2026 19:48
@wolo-lab
wolo-lab force-pushed the wolo/run_node_use_as_output_sample branch from 915433d to 1bbcff8 Compare June 5, 2026 20:04
@wolo-lab
wolo-lab force-pushed the wolo/run_node_use_as_output_sample branch from ba4809e to dce4f28 Compare June 8, 2026 08:07
@wolo-lab
wolo-lab force-pushed the wolo/run_node_use_as_output_sample branch from dce4f28 to 43c93bd Compare June 8, 2026 08:16
@wolo-lab
wolo-lab force-pushed the wolo/run_node_use_as_output_sample branch from 43c93bd to 656ebe4 Compare June 8, 2026 08:18
Base automatically changed from wolo/output-for to v2 June 9, 2026 09:34
@wolo-lab
wolo-lab force-pushed the v2 branch 2 times, most recently from fbb3e0c to 1ccdf49 Compare June 22, 2026 10:45
@wolo-lab
wolo-lab force-pushed the wolo/run_node_use_as_output_sample branch from 656ebe4 to 7d9e344 Compare June 22, 2026 10:57
@wolo-lab
wolo-lab force-pushed the wolo/run_node_use_as_output_sample branch from 7d9e344 to 6edb613 Compare August 26, 2026 19:14
@wolo-lab
wolo-lab changed the base branch from v2 to main August 26, 2026 21:37
The workflow examples cover dynamic orchestration and AgentNode
composition, but nothing shows output delegation: handing a dynamic
node's terminal output to a child so the child's event carries it and
the parent emits none.

The orchestrator branches in plain Go before any model call, so both
paths are reachable from the console and the documented session
reproduces. The in-scope branch delegates to an LlmAgent child with
WithUseAsOutput, the out-of-scope branch returns its own string.
@wolo-lab
wolo-lab force-pushed the wolo/run_node_use_as_output_sample branch from 6edb613 to 9bc1ed0 Compare August 26, 2026 21:44
@wolo-lab
wolo-lab marked this pull request as ready for review August 27, 2026 08:30
Review of the sample turned up four claims that do not match what the
code does.

The "needs LLM on the delegating branch only" bullet was wrong in the
way that costs a newcomer the most time: the model client is built at
startup, so without credentials the sample dies with "api key is
required" before printing a prompt, including on the branch that never
calls the model.

"Reaches the caller exactly once" was true of events but not of the
console, which prints the reply once either way, so a reader deleting
WithUseAsOutput to see the promised duplicate would have concluded the
option does nothing.

Nothing said why the orchestrator has no successor. A node chained
after a delegating dynamic node receives the zero value rather than the
delegated text, silently, so the omission was the one thing a reader
most needed explained.

The unknown-agent warning fires on turns after a delegated one, when
the runner walks the history, not on the delegated turn itself.

Also numbers the diagram edge that was skipped on the delegating path,
reconciles the legend with the arrows actually drawn, and switches the
transcript to US spelling. The transcript was re-captured from a live
run rather than edited by hand.
@wolo-lab wolo-lab changed the title examples: dynamic workflow with WithUseAsOutput docs(examples/workflow): add a WithUseAsOutput sample Aug 27, 2026
Comment thread examples/workflow/dynamic/use_as_output/README.md
Comment thread examples/workflow/dynamic/use_as_output/README.md
Switches the sample to gemini-3.5-flash. gemini-flash-latest is an AI
Studio alias and returns 404 NOT_FOUND on Vertex, which the README
offers as Option B, so a reader following that path hit an error. The
15 samples still on the alias were all written in one batch on the same
day; every example touched since #1162 uses gemini-3.5-flash, and that
commit made the switch specifically to drop the API-key dependency.

Replaces the flowchart with a sequence diagram, as suggested in review.
The sample exists to show WHICH participant emits the event carrying the
output, and a flowchart cannot express authorship — the sequence diagram
shows the reply leaving drafter rather than assistant. It also carries
the branch natively through alt/else, so the step numbering and the
solid-versus-dotted legend the flowchart needed are both gone.
Precedent: examples/agentregistry/{bind,a2a}.

The example session was re-captured from a live run on the new model
rather than edited by hand.

@kdroste-google kdroste-google left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@wolo-lab wolo-lab added the v2 For PRs targeting main branch. label Aug 27, 2026
@wolo-lab
wolo-lab merged commit f709db7 into main Aug 27, 2026
14 checks passed
@wolo-lab
wolo-lab deleted the wolo/run_node_use_as_output_sample branch August 27, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 For PRs targeting main branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants