Skip to main content

Long-term memory for AI agents — wisdom acquired through experience. Extraction, entity resolution, reconciliation, and retrieval.

Project description

arandu

CI PyPI License: MIT Documentation llms.txt

Long-term memory system for AI agents. Extract facts from conversations, resolve entities, reconcile updates, and retrieve relevant context — works with any LLM provider.

Read the full documentation →

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

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arandu-0.11.7.tar.gz (597.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arandu-0.11.7-py3-none-any.whl (132.7 kB view details)

Uploaded Python 3

File details

Details for the file arandu-0.11.7.tar.gz.

File metadata

  • Download URL: arandu-0.11.7.tar.gz
  • Upload date:
  • Size: 597.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for arandu-0.11.7.tar.gz
Algorithm Hash digest
SHA256 5c7c2eb74fcee05bcd552952e8e174498cec3fefc39e5626bc3d082f5f0a2eb5
MD5 02b5c895993f183d8b8c73a1a56b141a
BLAKE2b-256 354fa25d6f4bdd2d845a9fd87661a9e681cb43f48664ddd4259715a4c7743570

See more details on using hashes here.

Provenance

The following attestation bundles were made for arandu-0.11.7.tar.gz:

Publisher: release.yml on pe-menezes/arandu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file arandu-0.11.7-py3-none-any.whl.

File metadata

  • Download URL: arandu-0.11.7-py3-none-any.whl
  • Upload date:
  • Size: 132.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for arandu-0.11.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d1508d49b614603e80dfbe10539b67eb8b7b7e83d10c2f6c035f8b78c4078ed3
MD5 b4252bdfc693de7a46b69c60fd396576
BLAKE2b-256 a0dc280033e3fc5d3b9e9694c7a5c7c3f8d8fe99af7401cf8e19efdb0f8b6561

See more details on using hashes here.

Provenance

The following attestation bundles were made for arandu-0.11.7-py3-none-any.whl:

Publisher: release.yml on pe-menezes/arandu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page