Cross-session memory store for agents, backed by Memgraph
Project description
Sessions Graph
Sessions Graph is the Context Graph component for session context and cross-session recall. It is the authority on (:Session) nodes in the Context Graph family. It stores free-form text assertions — called Memories — written explicitly by agents, and makes them searchable in future sessions.
Requires Memgraph ≥ 3.6 (text search is stable from that release).
Installation
pip install sessions-graph
To use with Agent Context Graph:
pip install sessions-graph[agent-context-graph]
Quick start
from sessions_graph import SessionsGraph
graph = SessionsGraph() # connects via MEMGRAPH_HOST / MEMGRAPH_PORT env vars
graph.setup() # creates constraints and the text index (run once)
# Write a memory
mem = graph.save_memory(
user_id="alice",
content="Prefers Python over TypeScript",
session_id="s-abc123", # optional — links memory to a session for provenance
)
# Retrieve all memories for a user
memories = graph.get_memories("alice")
# Search memories by content (full-text, powered by Tantivy)
results = graph.search_memories("alice", "Python")
# Update or delete
graph.update_memory(mem.memory_id, "Prefers Python, especially for data tooling")
graph.delete_memory(mem.memory_id)
Integration with Agent Context Graph
Wire the SessionsGraphConnector into an AgentLink to get automatic session provenance — the connector tracks the active session_id and user_id from SessionStartEvent so you can reference them when saving memories.
from sessions_graph import SessionsGraph
from sessions_graph.connector import SessionsGraphConnector
from agent_context_graph import AgentLink
from agent_context_graph.adapters.claude import ClaudeAdapter
graph = SessionsGraph()
graph.setup()
connector = SessionsGraphConnector(graph)
link = AgentLink()
link.add_connector(connector)
adapter = ClaudeAdapter(
link,
session_id="s-abc123",
session_kwargs={"user_id": "alice"},
)
# During the session, save memories via the Python API:
graph.save_memory(
user_id=connector.active_user_id,
content="User works primarily in the ai-toolkit repository",
session_id=connector.active_session_id,
)
Graph schema
(:User {user_id})
└─[:HAS_MEMORY]─▶ (:Memory {memory_id, user_id, content, created_at})
▲
[:PRODUCED_MEMORY]
│
(:Session {session_id}) ← shared idempotent coordination point
Text search
Sessions Graph uses Memgraph text search (powered by Tantivy) for search_memories. The text index is created on setup():
CREATE TEXT INDEX memory_content_index ON :Memory(content);
Searches run as:
CALL text_search.search_all('memory_content_index', 'Python')
YIELD node AS m, score
WHERE m.user_id = 'alice'
RETURN m.content, score
ORDER BY score DESC
LIMIT 10;
The query string follows Tantivy query syntax.
API reference
| Method | Description |
|---|---|
setup() |
Create constraints and text index. Run once on first use. |
drop() |
Remove all Memory-related constraints and indexes. |
save_memory(user_id, content, *, session_id, memory_id) |
Persist a new Memory. Returns the stored Memory object. |
get_memories(user_id) |
Return all Memories for a user, newest first. |
search_memories(user_id, query, *, limit=10) |
Full-text search over Memory content. |
update_memory(memory_id, content) |
Replace the content of an existing Memory. Returns None if not found. |
delete_memory(memory_id) |
Remove a Memory and all its relationships. |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sessions_graph-0.1.2.tar.gz.
File metadata
- Download URL: sessions_graph-0.1.2.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b70c485aa209f2fb28bf6ec77a1d79d89cbb7f272d1df109554ab9a6635e382d
|
|
| MD5 |
e71881ac6febbe0bf43e7ad78a6c4cf0
|
|
| BLAKE2b-256 |
783b0ccff5254355af72d78dd0df0eef33fd38147bd21e7cfac2d725c20f62f2
|
File details
Details for the file sessions_graph-0.1.2-py3-none-any.whl.
File metadata
- Download URL: sessions_graph-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a4438a675c27261c8ad25b7c2fc0e87a22aa5292f815aa3f245555b8026f3b3
|
|
| MD5 |
b30d063113aed875da798009932cdd6e
|
|
| BLAKE2b-256 |
e1696a55c0b78000130aa77bf8f493b329ae3aa71a34765d2e1ab050eeaad5b7
|