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:666ghj BettaFish ReportStructureNode mutate state

From Leeroopedia
Knowledge Sources
Domains NLP, Report_Generation, LLM_Prompting
Last Updated 2026-10-08 00:00 GMT

Overview

Concrete node that generates a multi-paragraph report outline from a user query using an LLM, shared across InsightEngine, MediaEngine, and QueryEngine pipelines.

Description

The ReportStructureNode is a StateMutationNode that takes a user's research query and calls an LLM to produce a structured report outline consisting of titled paragraphs with content descriptions. This outline drives the entire research pipeline: each paragraph becomes a unit of research that is searched, summarized, and refined independently. The node is identical across all three search engines, differing only in the system prompt used.

Usage

Import this node when you need to generate a report outline from a research query. It is the first step in every search agent pipeline and must run before any search or summarization nodes.

Code Reference

Source Location

  • Repository: BettaFish
  • Files:
    • `InsightEngine/nodes/report_structure_node.py:L22-204`
    • `MediaEngine/nodes/report_structure_node.py:L22-204`
    • `QueryEngine/nodes/report_structure_node.py:L22-204`

Signature

class ReportStructureNode(StateMutationNode):
    def __init__(self, llm_client, query: str):
        """
        Args:
            llm_client: LLMClient - OpenAI-compatible LLM client
            query: str - User research query
        """

    def run(self, input_data: Any = None, **kwargs) -> List[Dict[str, str]]:
        """
        Call LLM to generate report structure.

        Returns:
            List of dicts, each with 'title' and 'content' keys
            describing a paragraph section.
        """

    def mutate_state(
        self, input_data: Any = None, state: State = None
    ) -> State:
        """
        Generate structure and update State with query, report_title,
        and paragraphs list.

        Returns:
            Updated State with paragraphs populated.
        """

Import

# InsightEngine
from InsightEngine.nodes import ReportStructureNode

# MediaEngine
from MediaEngine.nodes import ReportStructureNode

# QueryEngine
from QueryEngine.nodes import ReportStructureNode

I/O Contract

Inputs

Name Type Required Description
llm_client LLMClient Yes OpenAI-compatible LLM client for generating structure
query str Yes User research query (e.g., "武汉大学舆情分析")

Outputs

Name Type Description
paragraphs List[Dict[str, str]] List of paragraph dicts with 'title' and 'content' fields
state.query str The original user query stored in State
state.report_title str LLM-generated report title

Usage Examples

Basic Report Structure Generation

from InsightEngine.nodes import ReportStructureNode
from InsightEngine.llms import LLMClient
from InsightEngine.state import State

# Initialize LLM client and node
llm = LLMClient(api_key="sk-...", model_name="moonshot-v1-8k", base_url="https://api.moonshot.cn/v1")
node = ReportStructureNode(llm, "人工智能在教育领域的应用")

# Generate structure
structure = node.run()
print(f"Generated {len(structure)} paragraphs")
for p in structure:
    print(f"  - {p['title']}: {p['content'][:50]}...")

# Update pipeline state
state = State()
state = node.mutate_state(state=state)
# state.paragraphs is now populated

Related Pages

Implements Principle

Requires Environment

Page Connections

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