import asynciofrom plyra_memory import Memoryasync def main(): async with Memory(agent_id="my-agent") as mem: # Write to memory await mem.remember("User prefers async Python frameworks") await mem.remember("The bug is in the conditional edge logic") # Recall — fused search across all layers result = await mem.recall("Python preferences") for r in result.results: print(f"[{r.layer.value}] {r.content} score={r.score:.2f}") # Context — token-budgeted string ready to inject into a prompt ctx = await mem.context_for("what stack does the user prefer?") print(ctx.content) # → "[episodic] User prefers async Python frameworks (score: 0.94)"asyncio.run(main())
The same agent_id retrieves memory from all previous sessions:
# Session 1async with Memory(agent_id="support-agent") as mem: await mem.remember("User is debugging a LangGraph state machine")# Session 2 — days later, new processasync with Memory(agent_id="support-agent") as mem: ctx = await mem.context_for("LangGraph issue") print(ctx.content) # → "[episodic] User is debugging a LangGraph state machine"