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 ReportFormattingNode run

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

Overview

Concrete node that formats all paragraph summaries into a final Markdown report using an LLM, shared across all three search engine pipelines.

Description

The ReportFormattingNode is a BaseNode that takes the final state of all paragraphs (title + paragraph_latest_state for each) and calls an LLM to produce a polished Markdown report. The LLM is prompted with a formatting system prompt that instructs it to organize the content with proper headings, lists, and emphasis. If the LLM output contains markdown code fences or reasoning artifacts, the node cleans them up via `clean_markdown_tags` and `remove_reasoning_from_output`.

Usage

Import this node when all paragraph research is complete and you need to produce the final Markdown report. It is the last step in each engine's research pipeline.

Code Reference

Source Location

  • Repository: BettaFish
  • Files:
    • `InsightEngine/nodes/formatting_node.py:L20-170`
    • `MediaEngine/nodes/formatting_node.py:L20-168`
    • `QueryEngine/nodes/formatting_node.py:L20-168`

Signature

class ReportFormattingNode(BaseNode):
    def __init__(self, llm_client):
        """
        Args:
            llm_client: LLMClient - OpenAI-compatible LLM client
        """

    def run(self, input_data: Any, **kwargs) -> str:
        """
        Call LLM to format all paragraphs into Markdown report.

        Args:
            input_data: List[Dict] - each dict has 'title' and
                        'paragraph_latest_state' keys

        Returns:
            str: Formatted Markdown report
        """

    def format_report_manually(self, input_data: Any) -> str:
        """
        Fallback: manually format report without LLM if LLM fails.
        """

Import

from InsightEngine.nodes import ReportFormattingNode  # or MediaEngine/QueryEngine

I/O Contract

Inputs

Name Type Required Description
input_data List[Dict] Yes List of paragraphs, each with 'title' and 'paragraph_latest_state'

Outputs

Name Type Description
report str Formatted Markdown report string

Usage Examples

Format Final Report

from InsightEngine.nodes import ReportFormattingNode
from InsightEngine.llms import LLMClient

llm = LLMClient(api_key="sk-...", model_name="moonshot-v1-8k", base_url="https://api.moonshot.cn/v1")
node = ReportFormattingNode(llm)

# All paragraphs have completed research
paragraphs = [
    {"title": "技术发展现状", "paragraph_latest_state": "AI技术在教育领域..."},
    {"title": "应用场景分析", "paragraph_latest_state": "主要应用场景包括..."},
    {"title": "挑战与展望", "paragraph_latest_state": "面临的主要挑战..."},
]

report = node.run(paragraphs)
print(report[:500])  # Formatted Markdown report

Related Pages

Implements Principle

Requires Environment

Page Connections

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