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 WorkflowManage

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

Overview

Concrete workflow execution engine that runs DAG nodes concurrently on a thread pool, manages context propagation, and streams SSE responses, provided by MaxKB.

Description

The WorkflowManage class is the core engine of the flow system. It takes a loaded Workflow graph and executes its nodes concurrently using a module-level ThreadPoolExecutor with 200 max workers. Key responsibilities include:

  • Initializing node fields and global/chat context from node properties
  • Running nodes via `run_node_future()` → `node.run()` → `node.execute()`
  • Resolving branch transitions via `get_next_node_list()` using edge anchor matching
  • Propagating context through `generate_prompt()` with Jinja2 template substitution
  • Streaming output chunks via NodeChunkManage and BaseToResponse SSE formatting
  • Supporting both streaming (`run_stream`) and blocking (`run_block`) modes

Usage

Import this class when you need to:

  • Execute a workflow graph for an application chat request
  • Stream SSE responses from workflow node execution
  • Resume execution from a specific node (for form nodes, loops)

Code Reference

Source Location

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

Signature

class WorkflowManage:
    def __init__(
        self,
        flow: Workflow,
        params: Dict,
        work_flow_post_handler: WorkFlowPostHandler,
        base_to_response: BaseToResponse = SystemToResponse(),
        form_data=None,
        image_list=None,
        document_list=None,
        audio_list=None,
        video_list=None,
        other_list=None,
        start_node_id=None,
        start_node_data=None,
        chat_record=None,
        child_node=None,
        is_the_task_interrupted=lambda: False,
    ):
        """Initialize workflow engine with graph, params, and media lists."""

    def run(self):
        """Start execution: run_stream() or run_block() based on params['stream']."""

    def run_node_future(self, node) -> NodeResultFuture:
        """Submit a node for execution on the thread pool."""

    def get_next_node_list(self, current_node, current_node_result) -> List[INode]:
        """Resolve next executable nodes via branch anchor matching."""

    def generate_prompt(self, prompt: str) -> str:
        """Format prompt template with workflow context via Jinja2."""

class NodeChunkManage:
    def pop(self) -> str | None:
        """Pop the next SSE chunk from the node chunk queue."""

Import

from application.flow.workflow_manage import WorkflowManage, NodeChunkManage

I/O Contract

Inputs

Name Type Required Description
flow Workflow Yes Loaded graph from Workflow.new_instance()
params Dict Yes Chat params: chat_id, chat_record_id, stream, question, etc.
work_flow_post_handler WorkFlowPostHandler Yes Post-execution handler for chat record persistence
base_to_response BaseToResponse No SSE response formatter (default: SystemToResponse)
image_list list No Uploaded images for the chat
document_list list No Uploaded documents
start_node_id str No Resume from this node (for form/loop continuation)
is_the_task_interrupted callable No Cancellation check (default: always False)

Outputs

Name Type Description
run() returns Streaming: yields SSE chunks; Blocking: returns HttpResponse
node_context All executed node instances with context
answer Concatenated answer text from all result nodes

Usage Examples

Executing a Workflow with Streaming

from application.flow.common import Workflow, WorkflowMode
from application.flow.workflow_manage import WorkflowManage
from application.flow.i_step_node import WorkFlowPostHandler
from common.handle.impl.response.system_to_response import SystemToResponse

# Load the workflow graph
workflow = Workflow.new_instance(application.work_flow, WorkflowMode.APPLICATION)

# Create the engine
manage = WorkflowManage(
    flow=workflow,
    params={
        "chat_id": "chat-uuid",
        "chat_record_id": "record-uuid",
        "stream": True,
        "question": "What is RAG?",
        "workspace_id": "ws-uuid",
        "application_id": "app-uuid",
    },
    work_flow_post_handler=WorkFlowPostHandler(chat_info),
    base_to_response=SystemToResponse(),
)

# Run and stream SSE chunks
for chunk in manage.run():
    yield chunk  # "data: {...}\n\n"

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

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