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

Implementation:1Panel dev MaxKB Workflow

From Leeroopedia
Knowledge Sources
Domains Workflow, Graph
Last Updated 2026-10-10 00:00 GMT

Overview

Concrete workflow graph model that loads and indexes a DAG of nodes and edges from serialized JSON, provided by MaxKB.

Description

The Workflow class is the graph data structure for the flow execution engine. It is constructed from a JSON dict containing `nodes` and `edges` arrays (typically stored in the Application.work_flow field). Upon construction, it builds three lookup maps: `node_map` (node_id → Node), `up_node_map` (node_id → upstream EdgeNodes), and `next_node_map` (node_id → downstream EdgeNodes). These maps enable O(1) graph traversal for the WorkflowManage engine during execution. The WorkflowMode enum distinguishes application, knowledge, and tool execution contexts.

Usage

Import this class when you need to:

  • Load a serialized workflow JSON into a navigable graph structure
  • Validate workflow graph integrity (start node, branch connectivity, model params)
  • Traverse upstream/downstream nodes during workflow execution

Code Reference

Source Location

  • Repository: MaxKB
  • File: apps/application/flow/common.py

Signature

class Workflow:
    nodes: List[Node]
    edges: List[Edge]
    node_map: Dict[str, Node]
    up_node_map: Dict[str, List[EdgeNode]]
    next_node_map: Dict[str, List[EdgeNode]]
    workflow_mode: WorkflowMode

    def __init__(
        self,
        nodes: List[Node],
        edges: List[Edge],
        workflow_mode: WorkflowMode = WorkflowMode.APPLICATION.value,
    ):
        """Build graph lookup maps from nodes and edges."""

    @staticmethod
    def new_instance(
        flow_obj: Dict,
        workflow_mode: WorkflowMode = WorkflowMode.APPLICATION,
    ) -> Workflow:
        """Create a Workflow from a serialized JSON dict."""

    def get_node(self, node_id: str) -> Node:
        """Get a node by ID."""

    def get_next_edge_nodes(self, node_id: str) -> List[EdgeNode]:
        """Get downstream edges and nodes for a node."""

    def get_up_edge_nodes(self, node_id: str) -> List[EdgeNode]:
        """Get upstream edges and nodes for a node."""

    def is_valid(self) -> None:
        """Validate the workflow graph (start node, branches, model params)."""

class WorkflowMode(Enum):
    APPLICATION = "application"
    APPLICATION_LOOP = "application-loop"
    KNOWLEDGE = "knowledge"
    KNOWLEDGE_LOOP = "knowledge-loop"
    TOOL = "tool"
    TOOL_LOOP = "tool-loop"

Import

from application.flow.common import Workflow, WorkflowMode, Node, Edge, EdgeNode

I/O Contract

Inputs

Name Type Required Description
flow_obj Dict Yes JSON dict with 'nodes' and 'edges' arrays
workflow_mode WorkflowMode No Execution mode (default: APPLICATION)

Outputs

Name Type Description
returns Graph with lookup maps for traversal
node_map node_id → Node mapping
next_node_map node_id → downstream edges+nodes
up_node_map node_id → upstream edges+nodes

Usage Examples

Loading a Workflow from Application JSON

from application.flow.common import Workflow, WorkflowMode

# flow_obj is the serialized workflow from Application.work_flow
flow_obj = application.work_flow  # Dict with 'nodes' and 'edges'

# Create the workflow graph
workflow = Workflow.new_instance(flow_obj, WorkflowMode.APPLICATION)

# Get the start node
start_node = workflow.get_start_node()  # Node with type 'start-node'

# Traverse downstream
next_nodes = workflow.get_next_edge_nodes(start_node.id)
for edge_node in next_nodes:
    print(f"Next node: {edge_node.node.id}, type: {edge_node.node.type}")

Validating a Workflow

# Validate the workflow graph structure
try:
    workflow.is_valid()
    print("Workflow is valid")
except AppApiException as e:
    print(f"Validation error: {e}")

Related Pages

Implements Principle

Requires Environment

Page Connections

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