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 BaseChatStep

From Leeroopedia
Knowledge Sources
Domains Chat_Pipeline, LLM
Last Updated 2026-10-10 00:00 GMT

Overview

Concrete pipeline step for LLM invocation with streaming support, direct-return handling, MCP tool integration, and reasoning content extraction, provided by MaxKB.

Description

The BaseChatStep class implements IChatStep for the legacy chat pipeline. It is the most complex step, responsible for:

  • Checking for "directly return" paragraphs that bypass the LLM entirely
  • Handling the "no references" designated-answer fallback
  • Integrating MCP tools, custom tools, application tools, and skill tools via _handle_mcp_request
  • Streaming LLM responses via chat_model.stream() with reasoning content extraction (using configurable start/end tags)
  • Non-streaming (block) mode via chat_model.invoke()
  • Token counting, post-response handler invocation, and access number tracking
  • Long-term memory extraction via Celery

The event_content generator function handles the actual streaming, yielding SSE chunks via BaseToResponse.to_stream_chunk_response.

Usage

Import this class when you need to:

  • Execute the final LLM chat step in the legacy pipeline
  • Stream LLM responses with reasoning content support
  • Integrate MCP/tools with the chat pipeline

Code Reference

Source Location

  • Repository: MaxKB
  • File: apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py

Signature

class BaseChatStep(IChatStep):
    def execute(
        self,
        message_list: List[BaseMessage],
        chat_id,
        problem_text,
        post_response_handler: PostResponseHandler,
        model_id: str = None,
        workspace_id: str = None,
        paragraph_list=None,
        manage: PipelineManage = None,
        padding_problem_text: str = None,
        stream: bool = True,
        chat_user_id=None,
        chat_user_type=None,
        no_references_setting=None,
        model_params_setting=None,
        model_setting=None,
        mcp_tool_ids=None,
        mcp_servers="",
        mcp_source="referencing",
        tool_ids=None,
        application_ids=None,
        skill_tool_ids=None,
        mcp_output_enable=True,
        **kwargs,
    ):
        """Execute LLM chat: streaming or block mode."""

def event_content(
    response,                    # LLM stream iterator
    chat_id, chat_record_id,
    paragraph_list,
    post_response_handler,
    manage, step, chat_model,
    message_list, problem_text,
    padding_problem_text=None,
    chat_user_id=None, chat_user_type=None,
    is_ai_chat: bool = None,
    model_setting=None,
):
    """Generator yielding SSE chunks from LLM stream with reasoning extraction."""

Import

from application.chat_pipeline.step.chat_step.impl.base_chat_step import BaseChatStep, event_content

I/O Contract

Inputs

Name Type Required Description
message_list List[BaseMessage] Yes Formatted messages from GenerateHumanMessageStep
model_id str No LLM model ID
stream bool No Streaming mode (default: True)
paragraph_list List No Search results for direct-return check
model_setting dict No Reasoning content config (enable, start/end tags)
mcp_tool_ids list No MCP tool IDs for tool integration
tool_ids list No Custom tool IDs
no_references_setting dict No Fallback when no paragraphs found

Outputs

Name Type Description
returns (stream) StreamingHttpResponse SSE streaming response
returns (block) Response Non-streaming JSON response
context['answer_text'] str Full answer text
context['message_tokens'] int Request token count
context['answer_tokens'] int Response token count

Usage Examples

Streaming LLM Chat

step = BaseChatStep()
response = step.execute(
    message_list=messages,  # From BaseGenerateHumanMessageStep
    chat_id="chat-uuid",
    problem_text="What is RAG?",
    post_response_handler=handler,
    model_id="model-uuid",
    workspace_id="ws-uuid",
    stream=True,
    paragraph_list=paragraphs,
    manage=pipeline_manage,
    model_setting={
        "reasoning_content_enable": True,
        "reasoning_content_start": "<think>",
        "reasoning_content_end": "</think>",
    },
)
# response: StreamingHttpResponse yielding "data: {...}\n\n" chunks

Related Pages

Implements Principle

Requires Environment

Page Connections

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