Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:1Panel dev MaxKB Workflow DAG Execution

From Leeroopedia
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:

  1. Loads the graph into a Workflow with O(1) lookup maps
  2. Starts from the `start-node` and submits each node to a ThreadPoolExecutor (200 workers)
  3. Executes each node's `execute()` method, which returns a NodeResult containing step-local and global context
  4. Resolves the next nodes via edge anchor matching (branch_id for condition nodes, AND/OR conditions)
  5. Propagates context between nodes via `generate_prompt()` using Jinja2 templates
  6. 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

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment