results = client.recall( agent_id="agent-1", query="What does the user prefer?", memory_type="semantic", # Optional: filter by type top_k=5, # Max results (default: 10))for r in results: print(r.content, "(relevance:", round(r.relevance_score, 2), ")")
# Soft delete all memories for an agentclient.forget_all(agent_id="agent-1")# Hard delete all memories for an agentclient.forget_all(agent_id="agent-1", hard=True)
Retrieve the full version history of a specific memory.
history = client.history(memory_id="mem_a1b2c3d4")for version in history: print("v" + str(version.version) + ":", version.content) print(" Active:", version.valid_from, "→", version.valid_to or "current")
Sessions group related interactions and manage working memory lifecycle.
# Start a sessionsession = client.start_session(agent_id="agent-1")# Store working memory within the sessionclient.store( agent_id="agent-1", content="User is asking about pricing.", memory_type="working", session_id=session.id,)# End the session — working memories are consolidated into episodic memoryclient.end_session(session_id=session.id)
When a session ends, Z3rno automatically consolidates working memories into episodic memories. You do not need to manually manage this transition.
The SDK raises typed exceptions that inherit from Z3rnoError:
from z3rno import Z3rnoError, AuthenticationError, NotFoundError, RateLimitErrortry: results = client.recall(agent_id="agent-1", query="test")except AuthenticationError: # Invalid or expired API key print("Check your API key")except NotFoundError: # Agent or memory not found print("Agent does not exist")except RateLimitError as e: # Rate limit exceeded print("Rate limited. Retry after", e.retry_after, "seconds")except Z3rnoError as e: # Any other Z3rno error print("Z3rno error:", e.message, "(code:", e.code, ")")
For async applications, use AsyncZ3rnoClient. The API is identical — every method is an async coroutine.
from z3rno import AsyncZ3rnoClientclient = AsyncZ3rnoClient( base_url="http://localhost:8000", api_key="z3rno_sk_prod_your_key_here",)# All methods are awaitablememory = await client.store( agent_id="agent-1", content="User prefers dark mode.", memory_type="semantic",)results = await client.recall( agent_id="agent-1", query="What does the user prefer?",)# Don't forget to close the client when doneawait client.close()
async with AsyncZ3rnoClient( base_url="http://localhost:8000", api_key="z3rno_sk_prod_your_key_here",) as client: memory = await client.store( agent_id="agent-1", content="User prefers dark mode.", memory_type="semantic", ) # Client is automatically closed when the block exits