Long-term memory for AI agents — wisdom acquired through experience. Extraction, entity resolution, reconciliation, and retrieval.
Project description
arandu
Long-term memory system for AI agents. Extract facts from conversations, resolve entities, reconcile updates, and retrieve relevant context — works with any LLM provider.
Quickstart
pip install arandu[openai]
import asyncio
from arandu import MemoryClient
from arandu.providers.openai import OpenAIProvider
provider = OpenAIProvider(api_key="sk-...")
memory = MemoryClient(
database_url="postgresql+psycopg://user:pass@localhost/mydb",
llm=provider,
embeddings=provider,
)
async def main():
await memory.initialize() # creates tables (idempotent)
# Write — extracts facts automatically
result = await memory.write(user_id="user_123", message="I live in São Paulo with my wife Ana")
print(result.facts_added) # [{"fact_text": "Lives in São Paulo", ...}]
# Retrieve — semantic search + keyword + LLM reranking
context = await memory.retrieve(user_id="user_123", query="where does the user live?")
print(context.context) # "## Known facts about the user:\n- Lives in São Paulo ..."
asyncio.run(main())
Requirements
- Python 3.11+
- PostgreSQL with pgvector extension
- An LLM provider (OpenAI included, or implement your own)
Custom Providers
Implement the LLMProvider and EmbeddingProvider protocols to use any backend:
from arandu.protocols import LLMProvider, EmbeddingProvider
class MyProvider:
async def complete(self, messages, temperature=0, response_format=None, max_tokens=None) -> str:
... # your LLM call
async def embed(self, texts: list[str]) -> list[list[float]]:
... # your embedding call
async def embed_one(self, text: str) -> list[float] | None:
... # single text embedding
Configuration
from arandu import MemoryConfig
config = MemoryConfig(
topk_facts=20, # max facts to retrieve
min_similarity=0.20, # cosine similarity threshold
min_confidence=0.55, # minimum fact confidence
enable_reranker=True, # LLM reranking of results
recency_half_life_days=14, # exponential decay half-life
)
memory = MemoryClient(database_url="...", llm=provider, embeddings=provider, config=config)
Architecture
The SDK implements a 4-stage write pipeline and a 3-signal read pipeline:
Write: Message → Extract (LLM) → Entity Resolution (exact/fuzzy/LLM) → Reconcile (ADD/UPDATE/NOOP/DELETE) → Upsert
Read: Query → Semantic Search (pgvector) + Keyword Search (ILIKE) + Recency Scoring → LLM Rerank → Context Formatting
Documentation
For comprehensive documentation including conceptual guides, configuration reference, and cookbook examples:
https://pe-menezes.github.io/arandu/
Contributing
Contributions are welcome! Please read the Contributing Guide before submitting a pull request.
License
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 arandu-0.11.1.tar.gz.
File metadata
- Download URL: arandu-0.11.1.tar.gz
- Upload date:
- Size: 570.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19c6139309f2550435d765df66eead21b34fb448a1f7c8ca4a621fe01368a7dd
|
|
| MD5 |
b1b634f3241c97598bf50723939cf82b
|
|
| BLAKE2b-256 |
ab0918cda8368aa0a30fd988caea8eb20b31abf7c26d07e77fe78a64ae4270cc
|
Provenance
The following attestation bundles were made for arandu-0.11.1.tar.gz:
Publisher:
release.yml on pe-menezes/arandu
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
arandu-0.11.1.tar.gz -
Subject digest:
19c6139309f2550435d765df66eead21b34fb448a1f7c8ca4a621fe01368a7dd - Sigstore transparency entry: 1256117323
- Sigstore integration time:
-
Permalink:
pe-menezes/arandu@cb0e6e1483bb63a8e321a98d023b7ca2bbfa0f9c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pe-menezes
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cb0e6e1483bb63a8e321a98d023b7ca2bbfa0f9c -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file arandu-0.11.1-py3-none-any.whl.
File metadata
- Download URL: arandu-0.11.1-py3-none-any.whl
- Upload date:
- Size: 131.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68dcdfd4552b5fca9f4d489596dce6da3d4d7460c8dda8b8f901eaea7c0a54be
|
|
| MD5 |
17865a036b438e522fca57eaf546341a
|
|
| BLAKE2b-256 |
e983767be7aa1f8998f6fb8963aa52ca2f06d00896177b109b5653e8f32daf71
|
Provenance
The following attestation bundles were made for arandu-0.11.1-py3-none-any.whl:
Publisher:
release.yml on pe-menezes/arandu
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
arandu-0.11.1-py3-none-any.whl -
Subject digest:
68dcdfd4552b5fca9f4d489596dce6da3d4d7460c8dda8b8f901eaea7c0a54be - Sigstore transparency entry: 1256117396
- Sigstore integration time:
-
Permalink:
pe-menezes/arandu@cb0e6e1483bb63a8e321a98d023b7ca2bbfa0f9c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pe-menezes
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cb0e6e1483bb63a8e321a98d023b7ca2bbfa0f9c -
Trigger Event:
workflow_dispatch
-
Statement type: