Context Rendering and Prompt Injection
dmf does not manage your LLM or interact directly with its API. Instead, it acts as a "context engine" that retrieves and formats relevant information into a structured text block. It is entirely up to you to append this block to the LLM's system prompt (or as a separate message) before generating a response.
When you call Memory.render_context(query_text), dmf runs the full retrieval and assembly pipeline, generating a string ready to be injected into your agent.
Output Structure
The output generated by dmf is designed to give the LLM clear, temporal, and source-attributed context. When the rendered context contains both high-level memory and supporting turns, it has this structure:
- STRUCTURED EVIDENCE: Contains the selected memory items, including memory cards and raw records promoted as directly answerable evidence.
- RAW SUPPORTING EVIDENCE: Contains exact source turns that support a structured item, such as the original turn that produced a card or neighboring turns included for local context.
Here is a realistic example of what memory.render_context(query_text) returns when both sections are present:
=== STRUCTURED EVIDENCE ===
[R1] user | time=2026-05-23 14:28:11 UTC | current
The user prefers technical responses with Python code examples.
=== RAW SUPPORTING EVIDENCE ===
[S1] source | turn=39
Can you explain how this works? Please always include Python snippets, I hate reading theoretical walls of text.
[S2] next | turn=40
Of course! Let's implement the temporal decay mechanism.
Anatomy of a Context Block
Every piece of evidence is prefixed with a metadata header enclosed in brackets, followed by role, temporal locators, state markers, or support relation labels separated by |. This grounds the LLM in source and time without exposing retrieval scores or internal diagnostics.
Headers and Labels
[R1],[R2]: Structured evidence items selected for the query.[S1],[S2]: Raw support turns attached to structured evidence.current: Indicates a currently valid memory card or state.source: Indicates the raw interaction that originally triggered the creation of a memory card.retrieved: Indicates a raw interaction retrieved directly through semantic or lexical search.history/newer: Indicates the temporal relationship if a memory card was superseded by a newer one.prev/next: Neighboring turns pulled from the LTM to provide local conversational context around a retrieved match.
Temporal Locators
dmf attaches precise temporal coordinates to every block:
time=...: The absolute UTC timestamp of the interaction.turn=...: The monotonically increasing interaction ID of the conversation.
This allows the LLM to logically deduce which information is more recent if conflicting instructions are found in the prompt.
Integration Example
Once the context is rendered, append it to your system prompt when it is not empty.
context_str = memory.render_context(user_input)
system_prompt = (
"You are a helpful AI assistant. "
"Use the following temporal memory to answer the user:\n\n"
)
if context_str:
system_prompt += context_str
# Inject into your favorite LLM client (e.g., LiteLLM, OpenAI, Anthropic)
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_input}
]