Nemori Prompt Templates: A Complete Guide to LLM Interactions

Nemori centralizes all LLM prompt templates in a single PromptTemplates class located in src/generation/prompts.py, exposing eight core prompt constants and helper methods that format dynamic content before sending requests to the language model.

The nemori-ai/nemori repository implements a sophisticated memory architecture that relies heavily on structured prompt templates to convert conversations into episodic memories, generate semantic abstractions, and manage memory merging operations. Every interaction with the underlying LLM flows through the centralized prompt management system defined in the generation module.

Centralized Prompt Management in Nemori

The PromptTemplates class serves as the single source of truth for all text generation operations within the Nemori system. Located at src/generation/prompts.py, this class defines raw prompt templates as triple-quoted string constants and provides helper methods that inject runtime data—such as conversation history, episode titles, and knowledge statements—into these templates.

This architecture ensures consistency across the codebase, allowing components like the episode generator, semantic generator, and prediction correction engine to use standardized prompts without duplicating prompt text.

Core Prompt Templates for Memory Operations

Nemori defines eight primary prompt constants, each optimized for a specific memory management task. These templates handle everything from initial episode creation to advanced knowledge extraction and memory consolidation.

Episode Generation Prompt

The EPISODE_GENERATION_PROMPT (defined at line 11) converts raw conversation transcripts into structured episodic memories. This template accepts formatted conversation text and boundary metadata to produce a coherent summary of a specific interaction period.

Prediction and Correction Prompts

The PREDICTION_PROMPT (line 57) drives Nemori's ability to reconstruct full episodes from partial cues using the knowledge base. When combined with the EXTRACT_KNOWLEDGE_FROM_COMPARISON_PROMPT (line 93), this system compares original conversations against predicted episodes to extract high-value knowledge statements for storage.

Semantic Memory Generation

The SEMANTIC_GENERATION_PROMPT (line 160) generates concise, persistent semantic memories from sets of related episodes. This template distills temporal episode data into factual knowledge that remains relevant beyond the specific context of individual conversations.

Batch Processing and Segmentation

The BATCH_SEGMENTATION_PROMPT (line 241) handles large conversation histories by splitting them into coherent episodes. This template analyzes message batches to identify natural boundaries for memory segmentation.

Memory Merge Operations

Two specialized prompts handle episode consolidation: the MERGE_DECISION_PROMPT (line 311) determines whether a newly generated episode should merge with existing similar memories, while the MERGE_CONTENT_PROMPT (line 350) generates the final consolidated content when merges are required.

Helper Methods for Dynamic Prompt Formatting

The PromptTemplates class exposes helper methods that inject runtime data into the raw templates. These methods ensure consistent formatting across all LLM interactions:

  • get_episode_generation_prompt(conversation, boundary_reason) (line 392): Renders the episode generation template with formatted conversation data.
  • get_semantic_generation_prompt(episodes) (line 400): Prepares the semantic memory prompt with episode summaries.
  • format_conversation(messages) (line 407): Utility that formats message lists with timestamps for episode generation.
  • format_episodes_for_semantic(episodes) (line 431): Structures episode data specifically for semantic generation prompts.
  • get_prediction_prompt(episode_title, knowledge_statements) (line 443): Prepares prediction prompts with title and knowledge context.
  • get_batch_segmentation_prompt(count, messages) (line 454): Formats batch segmentation requests for large conversation sets.
  • get_merge_decision_prompt(new_time_range, new_content, candidates) (line 462): Evaluates potential episode merges.
  • get_merge_content_prompt(new_time_range, new_content, selected_candidate) (line 471): Generates consolidated content for approved merges.

Practical Code Examples

Generating Episodes from Conversations

from nemori.generation.prompts import PromptTemplates

conversation = [
    {"role": "user", "content": "Hey, how are you?"},
    {"role": "assistant", "content": "I'm good, thanks!"},
    # …

]

prompt = PromptTemplates.get_episode_generation_prompt(
    conversation=PromptTemplates.format_conversation(conversation),
    boundary_reason="Conversation ended"
)

# `prompt` is now ready to be sent to the LLM client

Predicting Episodes from Knowledge

from nemori.generation.prompts import PromptTemplates

title = "Project kickoff"
knowledge = [
    "The client wants a mobile-first UI.",
    "Budget is $150k.",
    # …

]

prompt = PromptTemplates.get_prediction_prompt(title, knowledge)

# Send `prompt` to the LLM for reconstruction

Merging Similar Episodes

from nemori.generation.prompts import PromptTemplates

new_range = "2024-01-10 09:00-10:30"
new_content = "Discussed API design."
candidates = "2024-01-09 14:00-15:00: Reviewed API endpoints."

# Decision step

decision_prompt = PromptTemplates.get_merge_decision_prompt(
    new_time_range=new_range,
    new_content=new_content,
    candidates=candidates,
)

# If the model says "merge", generate the merged content:

merge_prompt = PromptTemplates.get_merge_content_prompt(
    new_time_range=new_range,
    new_content=new_content,
    selected_candidate=candidates,
)

Integration with Nemori's Generation Pipeline

The prompt templates integrate with specialized generator classes throughout the Nemori codebase:

These components form the "prompt layer" of Nemori, ensuring that every LLM interaction follows a well-structured, version-controlled template defined in the centralized PromptTemplates class.

Summary

  • Nemori centralizes all LLM prompt templates in the PromptTemplates class within src/generation/prompts.py.
  • Eight core prompt constants handle specific memory operations: episode generation, prediction, knowledge extraction, semantic generation, batch segmentation, merge decisions, and merge content creation.
  • Helper methods format runtime data (conversations, knowledge statements, episode metadata) into these templates before LLM transmission.
  • The prompt system integrates with specialized generators including episode_generator.py, semantic_generator.py, and episode_merger.py to maintain consistent memory architecture across the codebase.

Frequently Asked Questions

How does Nemori handle dynamic content in prompt templates?

Nemori uses helper methods within the PromptTemplates class to inject runtime data into static prompt templates. Methods like format_conversation() and format_episodes_for_semantic() preprocess raw data (such as message lists with timestamps or episode clusters) into formatted strings that are then substituted into the triple-quoted prompt constants before being sent to the LLM.

What is the difference between episode generation and semantic generation prompts?

The EPISODE_GENERATION_PROMPT converts raw conversation transcripts into structured episodic memories with specific temporal boundaries, while the SEMANTIC_GENERATION_PROMPT distills multiple episodes into concise, persistent factual memories that transcend specific conversation contexts. Episode generation handles immediate conversation summarization, whereas semantic generation creates long-term knowledge abstractions from episode clusters.

Where are the prompt templates defined in the Nemori codebase?

All prompt templates are defined in src/generation/prompts.py within the PromptTemplates class. This file contains eight string constants representing the raw prompt templates and nine helper methods that format these templates with dynamic data. The file serves as the single source of truth for all LLM interactions within the Nemori memory system.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →