File size: 424 Bytes
59cece6
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
from typing import List
from .types import MemoryEntry

def format_injection(memories, max_tokens=320):
    if not memories:
        return ""
    lines = [f"- [{m.type.value}] {m.key}={m.value} (turn {m.source_turn}, c={m.confidence:.2f})" for m in memories]
    txt = "\n".join(lines)
    max_words = int(max_tokens * 0.75)
    words = txt.split()
    return " ".join(words[:max_words]) if len(words) > max_words else txt