Principle:1Panel dev MaxKB Workflow DAG Execution
| Knowledge Sources | |
|---|---|
| Domains | Workflow, Concurrency |
| Last Updated | 2026-10-10 00:00 GMT |
Overview
A graph-based execution model that runs workflow nodes as a Directed Acyclic Graph (DAG) with concurrent node execution, branch resolution, and context propagation.
Description
DAG-based workflow execution is the core pattern of MaxKB's flow engine. A workflow is defined as a JSON graph of nodes (AI chat, search, condition, tool, loop, etc.) and edges (with branch anchors). At runtime, the engine:
- Loads the graph into a Workflow with O(1) lookup maps
- Starts from the `start-node` and submits each node to a ThreadPoolExecutor (200 workers)
- Executes each node's `execute()` method, which returns a NodeResult containing step-local and global context
- Resolves the next nodes via edge anchor matching (branch_id for condition nodes, AND/OR conditions)
- Propagates context between nodes via `generate_prompt()` using Jinja2 templates
- Streams output chunks via NodeChunkManage as SSE responses
This design enables parallel branch execution, conditional branching, loop iteration, and real-time streaming.
Usage
Use this principle when designing:
- Agentic workflow systems with conditional branching
- Concurrent node execution with thread pool orchestration
- Visual workflow builders with DAG graph representation
Theoretical Basis
The DAG execution model uses a topological traversal with concurrent execution of independent branches:
# Abstract algorithm description (NOT real implementation)
def execute_dag(workflow, start_node):
pending = [start_node]
while pending:
node = pending.pop(0)
result = thread_pool.submit(node.execute)
next_nodes = resolve_branches(node, result)
for next_node in next_nodes:
if all_upstream_executed(next_node):
pending.append(next_node)
Branch resolution uses edge anchor matching: each edge has a `sourceAnchorId` like `{node_id}_{branch_id}_right`. For condition nodes, the `branch_id` in the NodeResult must match the edge's anchor to select the correct downstream branch. For AND-condition nodes, all upstream nodes must have completed before execution.
Related Pages
Implemented By
- Implementation:1Panel_dev_MaxKB_Workflow
- Implementation:1Panel_dev_MaxKB_WorkflowManage
- Implementation:1Panel_dev_MaxKB_INode
- Implementation:1Panel_dev_MaxKB_get_node
- Implementation:1Panel_dev_MaxKB_BaseSearchKnowledgeNode