Skip to main content

The injection pattern

At the start of each agent session, call /context and prepend the returned fdm_block to your system prompt:
import httpx

def build_system_prompt(base_prompt: str, user_id: str, api_key: str) -> str:
    r = httpx.get(
        "https://api.spectralmemory.com/context",
        params={"user_id": user_id},
        headers={"Authorization": f"Bearer {api_key}"},
    )
    ctx = r.json()
    fdm_block = ctx.get("fdm_block", "")
    if fdm_block:
        return f"{fdm_block}\n\n{base_prompt}"
    return base_prompt
The Hermes3 reader model will decode the signal automatically during inference. Other models see an opaque token sequence and ignore it.

What /context returns

{
  "user_id": "alice",
  "fdm_block": "[MEM]magistrate yi GOP...[/MEM]",
  "channel_count": 3,
  "channel_labels": ["USER.gpu", "TASK.current", "PROJ.token_budget"],
  "plain_index": "USER.gpu=5090\nTASK.current=train\nPROJ.token_budget=1024"
}
plain_index is a human-readable summary of stored facts — useful for debugging or for passing to non-Hermes models as a fallback.

Empty state

If no facts have been encoded for the user_id, fdm_block is an empty string and channel_count is 0. Handle this gracefully:
fdm_block = ctx.get("fdm_block", "")
if not fdm_block:
    # No memory yet — use base prompt only
    system_prompt = base_prompt
else:
    system_prompt = f"{fdm_block}\n\n{base_prompt}"

Token budget

The [MEM] block is always exactly 512 tokens, regardless of how many facts are stored. Budget 512 tokens in your context window for the memory block.