File size: 843 Bytes
6b53875
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from typing import List, Dict, Optional, Callable

# Plug-in hooks so Belel can inject memory/context without xAI owning it.
ContextFetcher = Callable[[str], List[Dict[str,str]]]
ContextLogger = Callable[[Dict], None]

def with_memory_context(
    messages: List[Dict[str,str]],
    identity: str,
    fetch_context: ContextFetcher,
    log_context: Optional[ContextLogger] = None,
) -> List[Dict[str,str]]:
    """
    Prepend Belel long-term signals (truth-locks, continuity notes, prior adjudications),
    append a minimal chain-of-custody marker.
    """
    memory = fetch_context(identity) or []
    stitched = memory + messages + [{"role":"system","content":"[context: custody=belel-permanent-memory:v1]"}]
    if log_context:
        log_context({"type":"ctx_use","identity":identity,"messages_used":len(memory)})
    return stitched