emit_delta. The node’s result is returned unchanged.
When to use it
Usewrap_node to report Deltas from LangGraph nodes without adding reporting code inside each node.
Signature
What you implement
wrap_node only sends what you give it. You write extract and workspace_revision for your use case.
extract
You decide, for each node:
- Which events to report, and their names, e.g.
"dependency.scan.completed". - What goes in each payload. Only what
extractreturns is sent. - How many Deltas to send: one, several (e.g. one per change applied), or none (
[]), e.g. when the node produced nothing worth reporting.
extract defensively. An error raised inside it fails the node. For example, use result.get("findings", []), not result["findings"].
workspace_revision
You decide what “revision” means for your workspace: a git commit SHA, a document version, a run id, and so on. It is called once per node run, and all Deltas from that run share it.
The revision is read after the node runs. If the node changes the workspace (e.g. commits a fix), you get the new revision. To report the revision the node started from, store it in the state before the node runs and return it from there.
Returns
An async node that you add to the graph in place offn.
Behavior
- Runs
fn, then callsextract(state, result). - Sends one Delta per
(event, payload)pair. - Adds
wall_ms(the node’s run time in milliseconds) to every payload. - Converts dataclasses in the payload to plain values with
to_jsonable. - Delta failures never break the node:
emit_deltafails open. - Errors raised by
fnorextractstill propagate.
Example
summary.created Delta with the payload {"summary": "...", "wall_ms": 12}.
