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:24kchengYe MemoMind build system prompt for tools

From Leeroopedia
Knowledge Sources
Domains Prompt_Engineering, LLM_Engineering
Last Updated 2026-10-28 00:00 GMT

Overview

Concrete tool for constructing the reflect agent's system prompt with anti-hallucination rules, directive injection, hierarchical retrieval strategy, and query decomposition guidance.

Description

The build_system_prompt_for_tools function assembles the complete system prompt for the reflect agent's tool-calling loop. The prompt is structured in fixed sections:

  1. Anti-hallucination rule (top): "MUST ONLY use information from retrieved tool results"
  2. Directives (injected after anti-hallucination): user-defined hard rules with priority ordering
  3. Agent role: "You are a reflection agent that answers questions by reasoning over retrieved memories"
  4. Language rule: respond in the user's language (directives take precedence)
  5. Critical rules: only use tool results, search before giving up, synthesize and reason
  6. Hierarchical retrieval strategy: mental models -> observations -> raw facts (adapts based on has_mental_models)
  7. Query strategy: decompose queries into targeted searches, never echo the question

The retrieval strategy section adapts: if the bank has mental models, three levels are described; otherwise only observations and raw facts (two levels).

Usage

Import this function when you need to build the system prompt for the reflect agent's tool-calling loop. It is called by run_reflect_agent at the start of each reflection.

Code Reference

Source Location

  • Repository: MemoMind
  • File: engine/hindsight_api/engine/reflect/prompts.py
  • Lines: L95-329

Signature

def build_system_prompt_for_tools(
    bank_profile: dict[str, Any],
    context: str | None = None,
    directives: list[dict[str, Any]] | None = None,
    has_mental_models: bool = False,
    budget: str | None = None,
) -> str:

Import

from hindsight_api.engine.reflect.prompts import build_system_prompt_for_tools

I/O Contract

Inputs

Name Type Required Description
bank_profile dict[str, Any] Yes Bank profile with name and mission
context str No Optional additional context
directives list[dict[str, Any]] No Directive mental models to inject as hard rules
has_mental_models bool No Whether bank has mental models (controls retrieval levels, default False)
budget str No Search depth budget ("low", "mid", "high")

Outputs

Name Type Description
system_prompt str Complete system prompt string with anti-hallucination rules, directives, retrieval strategy

Usage Examples

Building a Reflect Agent Prompt

from hindsight_api.engine.reflect.prompts import build_system_prompt_for_tools

prompt = build_system_prompt_for_tools(
    bank_profile={"name": "Memo", "mission": "Track user activities and preferences"},
    directives=[
        {"name": "Language", "content": "Always respond in Chinese", "priority": 10},
    ],
    has_mental_models=True,
    budget="high",
)

# The prompt is passed to the LLM as the system message
messages = [
    {"role": "system", "content": prompt},
    {"role": "user", "content": "What patterns do I see in my work habits?"},
]

Related Pages

Implements Principle

Page Connections

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