Demo code for the talk on building production agent memory using knowledge graphs and vectors in SurrealDB.
- SurrealDB (nightly or
tobiemh/aibranch for DEFINE AGENT teaser) - uv (Python package manager)
- An OpenAI API key
- Copy the env file and add your OpenAI API key:
cp .env.example .env
# Edit .env and set your keyOr export it directly:
export OPENAI_API_KEY=sk-proj-...
export OPENROUTER_API_KEY=sk-or-...- Start SurrealDB in-memory:
surreal start --log trace --user root --pass root --allow-funcs --allow-net --allow-experimental memory- Load the knowledge graph (schema, data, and embeddings):
uv run load.py- Run the agent:
uv run agent.pyThe same agent is also available using popular frameworks:
uv run agent_pydantic.py # PydanticAI
uv run agent_agno.py # Agno
uv run agent_langchain.py # LangChain
uv run agent_langgraph.py # LangGraph (enforced review-first flow)| Step | File | What it shows |
|---|---|---|
| 1 | surql/01-schema.surql |
Tables, vector indexes, graph relations -- the knowledge graph schema |
| 2 | surql/02-ingest.surql |
Documents, entities, RELATE statements -- building the graph |
| 3 | surql/03-query.surql |
Vector search, graph traversal, then hybrid queries -- the retrieval layer |
| 4 | agent.py |
Python agent using OpenAI + SurrealDB -- the production agent |
| 5 | surql/04-agent.surql |
DEFINE AGENT teaser -- replacing the Python app with SurrealQL |
surql/
00-configure.surql # AI provider config (for DEFINE AGENT / ai::embed)
01-schema.surql # Tables, fields, vector indexes, relation types
02-ingest.surql # Sample data and graph edges (embeddings via async events)
03-query.surql # Standalone query patterns for the walkthrough
04-agent.surql # DEFINE AGENT teaser (experimental)
load.py # Load schema + data + embeddings into SurrealDB
agent.py # Python agent with tool-calling loop (raw OpenAI SDK)
agent_pydantic.py # Same agent using PydanticAI
agent_agno.py # Same agent using Agno
agent_langchain.py # Same agent using LangChain
agent_langgraph.py # Same agent using LangGraph (forced review step)
walkthrough.md # Code slides for the talk
pyproject.toml # Dependencies (managed by uv)