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 batch consolidation prompt

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

Overview

Concrete tool for building the LLM prompt used in batch memory consolidation, with a customizable mission, processing rules, and structured output format.

Description

The build_batch_consolidation_prompt function constructs the prompt sent to the LLM during the consolidation batch call. The prompt has four sections:

  1. Mission: defines what to track (customizable per bank via observations_mission; defaults to "Track every detail: names, numbers, dates, places, and relationships")
  2. Processing rules: always present regardless of mission
    • Language: write observations in the SAME language as source facts (never translate)
    • Redundant: same info worded differently -> UPDATE existing observation
    • Contradiction: capture both states with temporal markers ("used to X, now Y")
    • Resolve references: when a new fact resolves a vague placeholder, update the observation
    • Never merge observations about different people or unrelated topics
  3. Data section: format placeholders {facts_text} and {observations_text} substituted at call time
  4. Output format: JSON with creates/updates/deletes arrays, including examples of good vs. bad observation text

The prompt uses `.format()` with doubled braces ({{ }}) for literal JSON braces in the output format template.

Usage

Import this function when you need to build the consolidation LLM prompt. It is called by _consolidate_batch_with_llm for each batch of facts.

Code Reference

Source Location

  • Repository: MemoMind
  • File: engine/hindsight_api/engine/consolidation/prompts.py
  • Lines: L70-84

Signature

def build_batch_consolidation_prompt(
    observations_mission: str | None = None,
) -> str:

Import

from hindsight_api.engine.consolidation.prompts import build_batch_consolidation_prompt

I/O Contract

Inputs

Name Type Required Description
observations_mission str No Bank-specific mission defining what to track (defaults to "Track every detail...")

Outputs

Name Type Description
prompt str Prompt template with {facts_text} and {observations_text} placeholders

Usage Examples

Building and Formatting a Consolidation Prompt

from hindsight_api.engine.consolidation.prompts import build_batch_consolidation_prompt

# Build the prompt template
prompt_template = build_batch_consolidation_prompt(
    observations_mission="Track user health metrics: sleep, exercise, diet, mood"
)

# Format with actual data
prompt = prompt_template.format(
    facts_text="[abc123] Alice ran 5km this morning\n[def456] Alice slept 8 hours",
    observations_text='[{"id": "obs1", "text": "Alice exercises regularly", "proof_count": 3}]',
)

# Send to LLM
response = await llm_config.call(
    messages=[{"role": "user", "content": prompt}],
    response_format=ConsolidationBatchResponse,
)

Related Pages

Implements Principle

Requires Environment

Page Connections

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