Implementation:1Panel dev MaxKB PipelineManage
| Knowledge Sources | |
|---|---|
| Domains | Chat_Pipeline, Design_Patterns |
| Last Updated | 2026-10-10 00:00 GMT |
Overview
Concrete linear pipeline manager with a fluent builder pattern for assembling and executing ordered chat processing steps, provided by MaxKB.
Description
The PipelineManage class is the older of MaxKB's two execution engines (the other being the flow-based WorkflowManage). It assembles a list of IBaseChatPipelineStep classes into a sequential pipeline via the inner builder class. When run() is called, each step is instantiated and executed in order, with a shared `context` dict that carries data between steps (question, paragraphs, message list, etc.). The pipeline is used for the legacy chat flow: question reset → knowledge search → prompt construction → LLM streaming → response delivery.
Usage
Import this class when you need to:
- Assemble and run the legacy linear chat pipeline
- Understand the builder pattern for step assembly
- Access shared context between pipeline steps
Code Reference
Source Location
- Repository: MaxKB
- File: apps/application/chat_pipeline/pipeline_manage.py
Signature
class PipelineManage:
def __init__(
self,
step_list: List[Type[IBaseChatPipelineStep]],
base_to_response: BaseToResponse = SystemToResponse(),
debug: bool = False,
):
"""Initialize with step classes, response formatter, and debug flag."""
def run(self, context: Dict = None) -> None:
"""Execute all steps in order with shared context."""
def get_details(self) -> Dict:
"""Aggregate details from all executed steps."""
def get_base_to_response(self) -> BaseToResponse:
"""Return the response formatter."""
class builder:
def append_step(self, step: Type[IBaseChatPipelineStep]) -> builder:
"""Add a step class to the pipeline. Returns self for chaining."""
def add_base_to_response(self, base_to_response: BaseToResponse) -> builder:
"""Set the response formatter. Returns self."""
def add_debug(self, debug: bool) -> builder:
"""Set debug mode. Returns self."""
def build(self) -> PipelineManage:
"""Construct the PipelineManage instance."""
Import
from application.chat_pipeline.pipeline_manage import PipelineManage
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| step_list | List[Type[IBaseChatPipelineStep]] | Yes | Ordered step classes |
| base_to_response | BaseToResponse | No | SSE response formatter (default: SystemToResponse) |
| debug | bool | No | Debug mode flag |
| context | Dict | No | Initial context dict for step data sharing |
Outputs
| Name | Type | Description |
|---|---|---|
| context | Dict | Shared context with step outputs (message_tokens, answer_tokens, etc.) |
| get_details() returns | Dict | Aggregated step details for chat record |
Usage Examples
Building and Running a Chat Pipeline
from application.chat_pipeline.pipeline_manage import PipelineManage
from application.chat_pipeline.step.reset_problem_step.impl.base_reset_problem_step import BaseResetProblemStep
from application.chat_pipeline.step.search_dataset_step.impl.base_search_dataset_step import BaseSearchDatasetStep
from application.chat_pipeline.step.generate_human_message_step.impl.base_generate_human_message_step import BaseGenerateHumanMessageStep
from application.chat_pipeline.step.chat_step.impl.base_chat_step import BaseChatStep
# Build the pipeline
pipeline = (
PipelineManage.builder()
.append_step(BaseResetProblemStep)
.append_step(BaseSearchDatasetStep)
.append_step(BaseGenerateHumanMessageStep)
.append_step(BaseChatStep)
.add_debug(False)
.build()
)
# Run with initial context
pipeline.run(context={
'question': 'What is RAG?',
'chat_id': 'chat-uuid',
'chat_record_id': 'record-uuid',
'stream': True,
# ... other params
})
# Access results
details = pipeline.get_details()