
@node decorator. The decorator labels the function so the runtime treats it as a workflow step.
Inside that function, ctx.run_node(...) returns an awaitable you can await to run another node and receive its result. Use standard Python control flow (for example, a while loop) to decide at runtime how many times to call other nodes. You can also yield intermediate state so traces show each pass.
Mark functions with
@node to make them workflow steps. Use await ctx.run_node(...) to execute other nodes from inside a node. Emitting intermediate yield values lets traces report progress across multiple passes.async node that implements dynamic behavior: it runs writer → quality_check, then repeats reviser → quality_check until no issues remain. The snippet emits intermediate state so traces record pass 1, pass 2, etc.; the final emitted state contains the completed reply.
while loop decides the structure at runtime: as long as quality_check reports issues, you run the reviser and check again. Track passes and include it in yielded state so traces show each revision round and the evolving reply.
Conceptually, consider this run:
- The writer creates the first draft.
- The quality check finds two issues (e.g., missing API step and missing refund steps).
- The reviser runs, then the quality check runs again and now finds one issue (tone too formal).
- The reviser runs again, and a third check returns zero issues — the loop ends.

reviser runs — the data does. That is the first dynamic case: the data determines how many loop iterations the node performs at runtime.
There is a second dynamic case: the data can also decide how many things run in parallel. For example, a ticket might include multiple subtasks that you want to run concurrently, but only after you know how many subtasks exist. You must defer that decision until the node runs and inspects the data.
Below is a short comparison to clarify trade-offs.
Be careful with common Python idioms that eagerly evaluate or spawn tasks (for example, building a list of awaited calls or using list comprehensions that call
ctx.run_node immediately). If you create tasks or call nodes before you intend to, you can accidentally hardcode parallelism or freeze the runtime structure. Always await or construct tasks intentionally inside the node when you want them to run.- Python async/await guide: https://docs.python.org/3/library/asyncio.html
- Workflow and orchestration patterns: https://en.wikipedia.org/wiki/Workflow_(computing)