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 INode

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

Overview

Abstract interface specification for workflow nodes in the flow execution engine, defining the execution contract that all node types must implement.

Description

The INode abstract class defines the contract for all workflow node types in MaxKB's flow engine. Every node type (ai-chat, search-knowledge, condition, tool, mcp, loop, form, etc.) extends INode and implements execute() to return a NodeResult. The base class manages:

  • Node identity (`id`, `runtime_node_id` — a deterministic SHA1 hash)
  • Execution context (`context` dict for step-local variables)
  • Validation via DRF serializers (`valid_args()`)
  • Error handling (`get_write_error_context()`)
  • Answer tracking (`answer_text`, `get_answer_list()`)
  • The NodeChunk for streaming output

The NodeResult class wraps the output of a node's `execute()` method, carrying `node_variable` (step-local context) and `workflow_variable` (global context). It supports branch assertions via `branch_id` for condition nodes.

Usage

Use this pattern when you need to:

  • Implement a new workflow node type
  • Understand the execution contract for existing nodes
  • Access node context or results during workflow execution

Code Reference

Source Location

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

Signature

class INode:
    view_type = 'many_view'  # or 'single_view'

    def __init__(
        self,
        node: Node,
        workflow_params: Dict,
        workflow_manage: WorkflowManage,
        up_node_id_list=None,
        get_node_params=lambda node: node.properties.get('node_data'),
        salt=None,
    ):
        """Initialize node with graph node, workflow params, and context."""

    def run(self) -> NodeResult:
        """Execute the node: records timing, calls _run() → execute()."""

    def execute(self, **kwargs) -> NodeResult:
        """Abstract: implement node-specific logic. Must return NodeResult."""

    def valid_args(self, node_params, flow_params) -> None:
        """Validate params via DRF serializers before execution."""

    def get_details(self, index: int, **kwargs) -> Dict:
        """Return runtime details for the chat record."""

class NodeResult:
    def __init__(
        self,
        node_variable: Dict,
        workflow_variable: Dict,
        _write_context=write_context,
        _is_interrupt=is_interrupt,
    ):
        """Wrap node execution output with context and branch info."""

    def write_context(self, node, workflow) -> Generator:
        """Apply node_variable to node.context, workflow_variable to workflow.context."""

    def is_assertion_result(self) -> bool:
        """True if node_variable contains 'branch_id' (condition node)."""

    def is_interrupt_exec(self, current_node) -> bool:
        """True if execution should be interrupted (e.g., form not submitted)."""

Import

from application.flow.i_step_node import INode, NodeResult, WorkFlowPostHandler
from application.flow.common import NodeChunk

I/O Contract

Inputs

Name Type Required Description
node Node Graph node from Workflow
workflow_params Dict Chat-level params (chat_id, chat_record_id, etc.)
workflow_manage WorkflowManage Parent engine instance
up_node_id_list List[str] IDs of upstream executed nodes

Outputs

Name Type Description
execute() returns Contains node_variable and workflow_variable
node.context Step-local context (populated by write_context)
get_details() returns Runtime metadata for chat record persistence

Usage Examples

Implementing a Custom Node

from application.flow.i_step_node import INode, NodeResult
from rest_framework import serializers

class MyNode(INode):
    def get_node_params_serializer_class(self):
        class MyParamsSerializer(serializers.Serializer):
            text = serializers.CharField(required=True)
        return MyParamsSerializer

    def execute(self, text, **kwargs) -> NodeResult:
        # Process the text
        result = text.upper()
        # Return result with branch_id (for condition nodes) or without
        return NodeResult(
            node_variable={'answer': result, 'text': result},
            workflow_variable={},
        )

Related Pages

Implements Principle

Requires Environment

Page Connections

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