Repository navigation
Conversation
Share one immutable Graph between the DSL and the engine. Each root
or container call gets its own FrameGraph so that choosing an entry
or traversing an edge in one execution leaves other executions alone.
Migrating host code
- Replace Graph(root_node=node) with FrameGraph(root_node=node) and
import FrameGraph from graphon.engine. Pass existing nodes, edges,
in_edges, out_edges, graph_config and node_factory with the same
keyword arguments.
- Graph.init(...) and Graph.new().add_root(node).build() still work.
Annotate their results as FrameGraph and update isinstance checks
for executable graphs. New code can call FrameGraph.init(...) or
FrameGraph.new(). For GraphBuilder(graph_cls=Graph), pass FrameGraph
as graph_cls or use FrameGraph.new().
- Read the selected root, node instances and edge states from
engine.graph. Read the reusable definition from engine.definition,
which can be None for a host-built frame. Edge and GraphBuilder are
available from graphon.engine, and NodeFactory from graphon.protocols.
Their existing imports under graphon.graph still resolve.
Building and running a reusable definition
- Import Graph, NodeDefinition and EdgeDefinition from graphon.graph.
Construct Graph(nodes=..., edges=...) with definition values. Inspect
topology with node(id), incoming(id) and outgoing(id). To edit the
definition, build a new Graph from the updated values. When
entry_node_ids contains multiple entries, pass root_node_id to choose
one for the execution.
- dsl.loads(text, ...) still builds an Engine with the document's
variables and plugin dependencies. To reuse an executable document,
set plan = dsl.inspect(text) and call dsl.load_graph(plan.document.graph)
for each run. Pass runtime_variables=plan.document.runtime_variables
and dependencies=plan.dependencies when needed. With a host factory, use
Engine(definition, runtime_state, node_factory=factory).
- Existing flat Iteration and Loop bodies are read as embedded Graphs.
When constructing a NodeDefinition, pass call_target=body for an
embedded Graph or call_target=GraphReference("body", version="v1")
for a reference. Supply graph_resolver to dsl.loads, dsl.load_graph
or Engine for referenced bodies. It takes a GraphReference and
returns its Graph.
BREAKING CHANGE: graphon.graph.Graph now takes definition values.
The mutable graph constructor and execution state belong to
graphon.engine.FrameGraph.
Keep the shared Graph focused on its immutable definition. Remove the execution constructors, type forwarding modules and the import rule that allowed graphon.graph to reach into graphon.engine. Migrating hosts that construct executable graphs - Import FrameGraph from graphon.engine. Replace Graph.init(...) with FrameGraph.init(...). Keep graph_config, node_factory, root_node_id and any container_id or skip_validation arguments. - Replace Graph.new().add_root(node).build() with FrameGraph.new().add_root(node).build(). The builder also accepts the existing add_node() and connect() calls. When constructing it directly, use GraphBuilder(graph_cls=FrameGraph). - Replace Graph(root_node=node) with FrameGraph(root_node=node). Pass any existing nodes, edges, in_edges and out_edges maps with the same keywords. Use FrameGraph for executable graph type annotations and isinstance checks. - Use "from graphon.engine import Edge, GraphBuilder" for the former aliases under graphon.graph or graphon.graph.graph. Importing Edge from graphon.engine also replaces "from graphon.graph.edge import Edge". - Replace NodeFactory imports from graphon.graph or graphon.graph.graph with "from graphon.protocols import NodeFactory". Construct an immutable graphon.graph.Graph from NodeDefinition and EdgeDefinition values. For DSL text, dsl.loads(text) builds an engine with the document's variables and plugin dependencies. For an existing definition, use dsl.load_graph(definition) or Engine(definition, runtime_state, node_factory=factory). Supply root_node_id when there is more than one entry. Read the selected root, live nodes and edge states from engine.graph. Read the shared Graph from engine.definition, which can be None for a host-built frame. When upgrading Dify's pinned GraphOn dependency, update both Graph.init calls in workflow_app_runner.py and the calls in pipeline_runner.py and workflow_tool_container_handler.py. Update the protocol import in api/core/workflow/node_factory.py and switch host builders to FrameGraph.new(). BREAKING CHANGE: Graph.init(), Graph.new(), graphon.graph.edge and the execution type re-exports under graphon.graph are removed.
Keep Python graph authoring alongside the definition shared by the DSL and engine. Each build captures the node definitions, ordered edges, and eligible entry IDs. A caller can extend the builder and reuse graphs it has already built. The Slim example now binds the model at execution. BREAKING CHANGE: Import GraphBuilder from graphon.graph and construct it with GraphBuilder() or Graph.new(). Replace each runnable Node passed to add_root or add_node with a NodeDefinition carrying its ID, type, version, config, and optional call target. Remove graph_cls from direct builder construction. Existing add_node(from_node_id=..., source_handle=...) and connect(tail=..., head=...) calls keep their edge order and edge_N IDs starting at edge_0. Use Graph(nodes=..., edges=...) for explicit edge IDs. Pass the resulting Graph to dsl.load_graph(graph, start_inputs=...) or to Engine(graph, runtime_state, node_factory=factory). Supply entry_types for custom roots and root_node_id to select among multiple entries. Code using the draft's FrameGraph.new() or graphon.engine.GraphBuilder should use the graphon.graph authoring API above. Hosts that already own runnable nodes can pass their root, nodes, edges, in_edges, and out_edges to FrameGraph and run it with Engine(frame_graph, runtime_state).
Place graphon.graph_builder beside graphon.dsl. Both author the same immutable graphon.graph.Graph. Keep the entry types, node settings and container call targets in that shared definition. Connecting nodes explicitly lets callers use ordinary branches and loops while building a graph, regardless of the order in which nodes are registered. BREAKING CHANGE: Remove Graph.new() and the GraphBuilder exports from graphon.graph and graphon.graph.graph. Import GraphBuilder from graphon.graph_builder and create a builder with GraphBuilder(). If complete NodeDefinition and EdgeDefinition values are already available, pass them directly to Graph(nodes=..., edges=...). For NodeDefinition inputs, replace add_root(node) and add_node(node) with builder.add_node(node.id, node.node_type, version=node.version, config=node.config, call_target=node.call_target). Each call returns the local ID. Register entry nodes this same way. Pass entry_types to GraphBuilder for host-defined entry types and versions. Call builder.connect(source, target, source_handle=...) for every former implicit successor, from_node_id connection or connect(tail=..., head=...) call. Add edges in their original order to preserve outgoing order and generated IDs (edge_0, edge_1, ...). Finish with graph = builder.build() and pass that reusable definition to load_graph or Engine. Hosts with prebuilt executable nodes can pass their node, edge and adjacency maps and selected root directly to FrameGraph for execution.
Pass the host node factory when constructing an Engine from a shared Graph and select the entry for graphs with multiple roots. Show how to queue an abort, read its terminal event and give each execution a unique Redis command channel key. The other four guides from the earlier documentation review are already in main through #441, including the revised Python support range.
laipz8200
force-pushed
the
laipz8200/graph-definition-and-frame-graph
branch
from
November 26, 2026 09:53
6c4eabd to
ae110b9
Compare
Bind root and child node factories to a live read-only view. Reading a value, variable or file returns detached data. Variable Assigner v2 stages its dependent assignments in a private pool before yielding the updates. Copy variable writes, output values and container requests before resuming the node so later edits cannot change a pending commit. BREAKING CHANGE: NodeFactory.with_runtime_state receives a read-only frame view. Pass it to node constructors. Tool adapters that receive a pool should accept ReadOnlyVariablePool. Read abort status through node.runtime_state.aborted. Yield VariableUpdatedEvent for a shared assignment or return a node output. Use variable_pool.mutable_copy() for local calculations that need several dependent writes. A host can still seed a RuntimeState and pass it to a directly constructed node.
Use a two-string VariableAddress for pool writes and removals. Existing two-part lists and tuples remain valid. Keep field traversal on reads and reject malformed addresses before changing the pool. Have Loop clear just the node scopes it owns when it starts the next round. BREAKING CHANGE: Replace pool.remove([scope]) with pool.clear_scope(scope). Use pool.remove((scope, name)) to delete one variable. A field path such as (scope, name, field) still works with get(), and now raises ValueError on removal. An empty selector and a bare string also raise ValueError on writes and removals.
Keep VariableEntity available for saved Start configurations and its existing public import. Mark it final and deprecated for type checkers and generated schemas without warning on construction. Limit exceptions to its existing compatibility uses. Pin the form fields, their types and declared defaults, required fields, and input kinds in a contract test. Track host ownership in TD-11 and direct new input controls and form validation to the host.
This branch has not been deployed
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.
Important
!Related Issue
Refs #405
Summary
The DSL reader and the Python builder both produce an immutable
Graphcontaining node definitions, edges, and container call targets. The engine
selects an entry for each run and builds a fresh
FrameGraphfor the root and for each callto a container body. Each frame owns its executable nodes and edge states.
flowchart LR DSL["DSL document"] --> Definition["Root Graph"] Python["graphon.graph_builder.GraphBuilder"] --> Definition Definition -->|run A| RootA["Root FrameGraph A"] Definition -->|run B| RootB["Root FrameGraph B"] RootA -->|container call| Child["Child FrameGraph"] Body["Embedded or referenced Graph"] --> ChildHost migration
Graph(root_node=node)FrameGraphfromgraphon.engineand callFrameGraph(root_node=node). Thenodes,edges,in_edges,out_edges,graph_config, andnode_factorykeywords still work.Graph.init(...)FrameGraph.init(...)with the samegraph_config,node_factory,root_node_id, and anycontainer_idorskip_validationarguments.Graph.new()orGraphBuilderimported fromgraphon.graphGraphBuilderfromgraphon.graph_builderand callGraphBuilder(). Drop the oldgraph_clsargument.add_root(node)oradd_node(node, from_node_id=..., source_handle=...)builder.add_node(node_id, node_type, version=..., config=..., call_target=...)for each node, including entries. It returns the local ID. Usebuilder.connect(previous_id, node_id, source_handle=...)for each edge the old call created.connect(tail=..., head=...)in a builder chainbuilder.connect(source, target)for each edge, thenbuilder.build()to get the immutable Graph. Edge IDs start atedge_0in connection order.isinstancecheck that expects an executable graphFrameGraph. Read the selected root, live nodes, and edge states fromengine.graph. Useengine.definitionfor the shared definition when one was supplied.Import mutable
Edgefromgraphon.engineand the host'sNodeFactoryfromgraphon.protocols. Hosts that already own runnable nodes can pass the rootand the
nodes,edges,in_edges, andout_edgesmaps toFrameGraph.Run that frame with
Engine(frame_graph, runtime_state).When upgrading Dify's GraphOn dependency, replace both
Graph.initcalls inworkflow_app_runner.pyand the calls inpipeline_runner.pyandworkflow_tool_container_handler.py. Update the protocol import inapi/core/workflow/node_factory.pyand migrate executable-graph annotationsand builder calls in the same change.
The same Python definition can be run with different inputs.
To specify edge IDs yourself, use
Graph(nodes=..., edges=...)withEdgeDefinitionvalues. Usenode(id),incoming(id), andoutgoing(id)to inspect the graph. Pass
root_node_idwhen executing a graph withmultiple entries.
dsl.loads(text, ...)still loads the document's variables and plugindependencies. To reuse an executable document, set
plan = dsl.inspect(text)and call
dsl.load_graph(plan.document.graph)for each run. Passruntime_variables=plan.document.runtime_variablesanddependencies=plan.dependencieswhen needed. With a host node factory,use
Engine(definition, runtime_state, node_factory=factory).Flat Iteration and Loop bodies import as embedded Graphs. When building a
NodeDefinition, passcall_target=bodyto embed a Graph orcall_target=GraphReference("body", version="v1")to reference it.For a reference, pass a
graph_resolverthat takes aGraphReferenceandreturns its
Graphtodsl.loads,dsl.load_graph, orEngine.Checklist
!