class AgentMemory:
"""Full-stack memory architecture using all four tiers."""
def __init__(self, client: Z3rnoClient, agent_id: str):
self.client = client
self.agent_id = agent_id
def build_context(self, query: str) -> dict:
"""Build a comprehensive context from all memory tiers."""
# Procedural: How should I respond?
procedures = self.client.recall(
agent_id=self.agent_id,
query=query,
memory_type="procedural",
top_k=3,
)
# Semantic: What do I know?
facts = self.client.recall(
agent_id=self.agent_id,
query=query,
memory_type="semantic",
top_k=5,
)
# Episodic: What has happened before?
episodes = self.client.recall(
agent_id=self.agent_id,
query=query,
memory_type="episodic",
top_k=5,
)
# Working: What is happening right now?
working = self.client.recall(
agent_id=self.agent_id,
query=query,
memory_type="working",
top_k=10,
)
return {
"guidelines": [r.content for r in procedures.results],
"facts": [r.content for r in facts.results],
"history": [r.content for r in episodes.results],
"current_context": [r.content for r in working.results],
}
def format_system_prompt(self, context: dict) -> str:
"""Format memory context into a system prompt section."""
parts = []
if context["guidelines"]:
parts.append("## Response Guidelines\n" + "\n".join(f"- {g}" for g in context["guidelines"]))
if context["facts"]:
parts.append("## Known Facts\n" + "\n".join(f"- {f}" for f in context["facts"]))
if context["history"]:
parts.append("## Relevant History\n" + "\n".join(f"- {h}" for h in context["history"]))
if context["current_context"]:
parts.append("## Current Session\n" + "\n".join(f"- {c}" for c in context["current_context"]))
return "\n\n".join(parts)
# Usage
memory = AgentMemory(client, "support-agent")
context = memory.build_context("User asking about refund")
prompt_section = memory.format_system_prompt(context)