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

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

Overview

Concrete node that reflects on a paragraph's current state and generates a refined search query to fill information gaps, shared across all three search engine pipelines.

Description

The ReflectionNode is a BaseNode that examines the paragraph's current summary (paragraph_latest_state), its original title and content, and generates a new search query targeting missing information. This node drives the iterative research loop: after the first search and summary, the reflection node identifies what is still unknown and produces a query to find it. The LLM is prompted to output JSON with `search_query` and `reasoning` fields explaining what gap the new query addresses.

Usage

Import this node when implementing a reflection loop that iteratively refines search queries based on what has already been found. It runs after FirstSummaryNode in each iteration of the research loop.

Code Reference

Source Location

  • Repository: BettaFish
  • Files:
    • `InsightEngine/nodes/search_node.py:L154-286`
    • `MediaEngine/nodes/search_node.py:L154-286`
    • `QueryEngine/nodes/search_node.py:L154-286`

Signature

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

    def run(self, input_data: Any, **kwargs) -> Dict[str, str]:
        """
        Call LLM to reflect on current state and generate a new search query.

        Args:
            input_data: dict with 'title', 'content', and 'paragraph_latest_state' keys

        Returns:
            Dict with 'search_query' (str) and 'reasoning' (str)
        """

Import

from InsightEngine.nodes import ReflectionNode  # or MediaEngine/QueryEngine

I/O Contract

Inputs

Name Type Required Description
input_data.title str Yes Paragraph title from report structure
input_data.content str Yes Paragraph content description
input_data.paragraph_latest_state str Yes Current summary text from previous iteration

Outputs

Name Type Description
search_query str Refined search query targeting information gaps
reasoning str LLM's reasoning for what gap this query addresses

Usage Examples

Reflection Loop Iteration

from InsightEngine.nodes import ReflectionNode
from InsightEngine.llms import LLMClient

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

# After first summary has been generated
input_data = {
    "title": "技术发展现状",
    "content": "分析AI技术在教育领域的最新进展",
    "paragraph_latest_state": "AI技术在教育领域应用广泛..."
}

result = reflection.run(input_data)
print(result["search_query"])  # e.g., "AI教育技术 实际案例 效果评估"
print(result["reasoning"])     # e.g., "当前总结缺乏具体案例和效果数据"

Related Pages

Implements Principle

Requires Environment

Page Connections

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