Per-node executor. Drives BaseNode.run(), enriches events. Creates child Context, iterates node.run(), enqueues events to ic.event_queue, writes output/route/interrupt_ids to ctx, and returns the child Context.
| 47 | |
| 48 | |
| 49 | class NodeRunner: |
| 50 | """Per-node executor. Drives BaseNode.run(), enriches events. |
| 51 | |
| 52 | Creates child Context, iterates node.run(), enqueues events to |
| 53 | ic.event_queue, writes output/route/interrupt_ids to ctx, and |
| 54 | returns the child Context. |
| 55 | """ |
| 56 | |
| 57 | def __init__( |
| 58 | self, |
| 59 | *, |
| 60 | node: BaseNode, |
| 61 | parent_ctx: Context, |
| 62 | run_id: str | None = None, |
| 63 | # Output delegation (use_as_output) |
| 64 | use_as_output: bool = False, |
| 65 | # Resume state from a previous run |
| 66 | prior_output: Any = None, |
| 67 | prior_interrupt_ids: set[str] | None = None, |
| 68 | use_sub_branch: bool = False, |
| 69 | override_branch: str | None = None, |
| 70 | override_isolation_scope: str | None = None, |
| 71 | ) -> None: |
| 72 | """Initialize a NodeRunner. |
| 73 | |
| 74 | Args: |
| 75 | node: The BaseNode to execute. |
| 76 | parent_ctx: The parent node's Context. |
| 77 | run_id: Unique ID for this run. Should be a sequential |
| 78 | counter string ("1", "2", …) unique per node path. |
| 79 | Falls back to "1" if not provided. |
| 80 | |
| 81 | use_as_output: If True, this node's output also represents the parent |
| 82 | node's output. |
| 83 | prior_output: Output from a previous run, carried |
| 84 | forward on resume when the node had both output and |
| 85 | interrupts. |
| 86 | prior_interrupt_ids: Unresolved interrupt IDs (set) from a |
| 87 | previous run, carried forward on resume. |
| 88 | use_sub_branch: Whether the node should use a sub-branch. |
| 89 | override_branch: Optional branch to use instead of parent's branch. |
| 90 | """ |
| 91 | # Core |
| 92 | self._node = node |
| 93 | self._parent_ctx = parent_ctx |
| 94 | |
| 95 | self._run_id = str(run_id) if run_id else "1" |
| 96 | self._use_sub_branch = use_sub_branch |
| 97 | self._override_branch = override_branch |
| 98 | self._override_isolation_scope = override_isolation_scope |
| 99 | |
| 100 | # Output delegation |
| 101 | self._use_as_output = use_as_output |
| 102 | |
| 103 | # Resume state |
| 104 | self._prior_output = prior_output |
| 105 | self._prior_interrupt_ids = prior_interrupt_ids |
| 106 |
no outgoing calls