Python SDK
Full guide for integrating ZizkaDB in Python agents — FastAPI services, LangChain, CrewAI, notebooks, or scripts.
Python 3.10+. Works in venv, conda, or system Python.
bashpython3 --version # 3.10 or higher
Managed cloud: Sign up → Settings → Create API key (zizkadb_live_…).
Self-host: use host="http://localhost:8000" (dev key auto-sent). See Self-host docs → click Open my dashboard → on the login page.
bashpip install "zizkadb-sdk>=0.7.0"
agentdb package.pythonfrom zizkadb import ZizkaDB # Managed cloud (db.zizka.ai) db = ZizkaDB("zizkadb_live_xxxx") # Self-hosted # db = ZizkaDB(host="http://localhost:8000")
The SDK is async-first. Wrap calls in async def main() and run with asyncio.run(main()).
pythonimport asyncio from zizkadb import ZizkaDB db = ZizkaDB("zizkadb_live_xxxx") async def main(): result = await db.log( agent="support-bot", event="tool_call", data={"tool": "search", "query": "pricing"}, session_id="sess_abc123", # group one conversation ) print("Saved:", result.event_id) asyncio.run(main())
Pass parent_id so you can call why() later.
pythonasync def main(): msg = await db.log( agent="support-bot", event="user_message", data={"text": "why is my bill $200?"}, session_id="sess_abc123", ) tool = await db.log( agent="support-bot", event="tool_call", data={"tool": "get_billing"}, parent_id=msg.event_id, session_id="sess_abc123", ) resp = await db.log( agent="support-bot", event="assistant_response", data={"text": "I found a duplicate charge."}, parent_id=tool.event_id, session_id="sess_abc123", ) chain = await db.why(resp.event_id) chain.print() asyncio.run(main())
pythonasync def main(): # Search: keyword out of the box, hybrid with embeddings (mode="keyword"|"semantic"|"hybrid") hits = await db.search("billing complaint", agent="support-bot", limit=5) # Safe retries and batches await db.log("support-bot", "tool_call", {"tool": "refund"}, idempotency_key="req-42") await db.log_batch([ {"agent": "support-bot", "event": "user_message", "data": {"text": "hi"}}, {"agent": "support-bot", "event": "llm_response", "data": {"text": "hello"}, "parent_index": 0}, ]) # Prove the history is untouched; keep chain_head elsewhere as an anchor check = await db.verify_chain("support-bot") print(check["intact"], check["chain_head"]) # Reconstruct logged state at a time from datetime import datetime, timezone state = await db.at("support-bot", datetime(2026, 5, 1, 15, 0, tzinfo=timezone.utc)) # Prompt-ready memory block ctx = await db.context_for( agent="support-bot", task="user asking about refund policy", max_tokens=2000, ) # Drift vs baseline (needs enough sessions with session_id) baseline = await db.baseline("support-bot", recent_window=50) print(baseline) asyncio.run(main())
Framework example: OpenAI tool loop
pythonimport asyncio from openai import AsyncOpenAI from zizkadb import ZizkaDB db = ZizkaDB("zizkadb_live_xxxx") openai = AsyncOpenAI() async def run_turn(user_text: str, session_id: str): msg = await db.log( agent="my-agent", event="user_message", data={"text": user_text}, session_id=session_id, ) parent_id = msg.event_id response = await openai.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": user_text}], ) text = response.choices[0].message.content or "" await db.log( agent="my-agent", event="assistant_response", data={"text": text}, parent_id=parent_id, session_id=session_id, ) return text asyncio.run(run_turn("Hello", "sess_001"))
Auto-capture LLM calls (one line)
Instead of logging each step, let the SDK record every LLM call, tool call and tool result with its cause and token usage. db.why(), the token cost view and the audit log then work with no db.log() calls. Requires zizkadb-sdk 0.7.0 or later.
pythonimport zizkadb from zizkadb import ZizkaDB zizkadb.instrument(ZizkaDB("zizkadb_live_xxxx"), agent="my-agent") # then use your model client as usual: # user_message -> llm_end -> tool_call -> tool_result -> llm_end ...
Streaming is recorded too: you get the provider's stream unchanged, and when it ends the events carry the full answer, tool calls and token usage. Reasoning text (DeepSeek, GLM, Kimi, Gemini thoughts) is recorded as reasoning. Inside async with db.track(agent=...) the events share that session.
capture_content=False keeps prompts and answers out of the record (models, tool names, token usage and the causal links are still kept). A failed write never breaks your LLM call.Turn a bad session into a test
Copy the session id from the dashboard's Sessions view, then generate a pytest regression test that replays the session's user inputs through your agent and checks it calls the same tools, in the same order, without errors:
bashzizkadb test from-session <session_id> --agent my-agent --entry my_app.agent:answer pytest tests/test_session_<id>.py
The test runs inside zizkadb.testing.capture(), which records the agent's calls in memory (no server needed). Use it in your own tests too:
pythonfrom zizkadb.testing import capture with capture() as run: my_agent("How long do refunds take?") assert run.tool_calls == ["search_policies"] and not run.errors
All Python methods
db.log()Log any event. parent_id links cause → effect; idempotency_key makes retries safe; supersedes retires an outdated fact.db.log_batch(events)Up to 500 events in one request, with per-event results.db.why(event_id)Walk the causal chain from an event to its root.db.search(query)Search agent history in plain English: keyword out of the box, hybrid keyword + vector with embeddings.db.verify_chain(agent)Prove no event was edited, removed or reordered (per-agent hash chain).db.at(agent, timestamp)Reconstruct logged state at a past timestamp.db.query(agent)List recent events, optionally filtered by event type.db.context_for(agent, task)Memory block formatted for system prompt injection.db.baseline(agent)Behavioral baseline and drift score vs historical sessions.db.memory_diff(session_id)Summary of what happened in one session.db.forget(key, value)GDPR erasure by metadata filter; leaves a content-free tombstone in the audit chain.db.export_events(agent)Stream every event as NDJSON; import_events() loads it into another workspace.db.iter_events(agent)Every event, newest first, cursor-paged.db.agents()List all agents for your tenant.