Skip to main content

Framework-agnostic memory infrastructure for AI agents

Project description

memharness

Framework-agnostic memory infrastructure for AI agents

PyPI version Python 3.10+ License: MIT Tests

Overview

memharness is a complete memory infrastructure layer for AI agents. It provides:

  • 10 Memory Types: Conversational, Knowledge Base, Entity, Workflow, Toolbox, Summary, Tool Log, Skills, File, Persona
  • Multiple Backends: PostgreSQL + pgvector, SQLite + sqlite-vss, In-memory
  • Framework Agnostic: Works with LangChain, LangGraph, CrewAI, or any custom agent
  • Deterministic + AI Operations: Simple ops are deterministic, complex ops use embedded agents
  • Self-Exploration Tools: Agents can explore and manage their own memory
  • Fully Configurable: All thresholds, schedules, TTLs configurable via YAML or code

Installation

# Core (SQLite backend)
pip install memharness

# With PostgreSQL support
pip install memharness[postgres]

# With embedding support
pip install memharness[embeddings]

# Everything
pip install memharness[all]

Quick Start

from memharness import MemoryHarness

# Initialize with SQLite (development)
memory = MemoryHarness("sqlite:///memory.db")

# Or PostgreSQL (production)
memory = MemoryHarness("postgresql://user:pass@localhost/db")

# Write conversational memory (deterministic)
await memory.add_conversational(
    thread_id="chat_001",
    role="user",
    content="How do I deploy to Kubernetes?"
)

# Write knowledge base (deterministic)
await memory.add_knowledge(
    content="Kubernetes deployment guide...",
    source="k8s-docs",
    metadata={"category": "devops"}
)

# Search knowledge base (semantic search)
results = await memory.search_knowledge(
    query="container orchestration",
    k=5
)

# Get curated context for LLM
context = await memory.assemble_context(
    query="deploy my app",
    thread_id="chat_001",
    max_tokens=4000
)

Memory Types

Type Storage Purpose
Conversational SQL Chat history per thread
Knowledge Base Vector Documents, facts, reference material
Entity Vector People, organizations, systems, concepts
Workflow Vector Reusable step-by-step patterns
Toolbox Vector Tool definitions with VFS discovery
Summary Vector Compressed conversations (expandable)
Tool Log SQL Tool execution audit trail
Skills Vector Learned agent capabilities
File Hybrid Document references
Persona Vector Agent identity blocks

Embedded Agents

memharness includes specialized agents for complex memory operations:

from memharness import MemoryHarness
from memharness.agents import AgentConfig

memory = MemoryHarness(
    backend="postgresql://...",
    llm=your_llm,  # Optional: for AI-powered operations
    agents=AgentConfig(
        summarizer={"enabled": True, "triggers": [{"condition": "age > 7d"}]},
        entity_extractor={"enabled": True, "on_write": True},
        consolidator={"enabled": True, "schedule": "0 3 * * *"},
        gc={"enabled": True, "schedule": "0 4 * * 0"},
    )
)

Memory Tools (Self-Exploration)

Agents can explore their own memory using built-in tools:

# Get tools for your agent
tools = memory.get_memory_tools()

# Tools include:
# - memory_search: Search across memory types
# - memory_read: Read specific memory by ID
# - memory_write: Write new memory
# - memory_stats: Get memory statistics
# - toolbox_tree: Explore tool VFS
# - toolbox_grep: Search tools by pattern

Configuration

# memharness.yaml
backend: postgresql://localhost/memharness

summarization:
  enabled: true
  triggers:
    - condition: "age > 7d"
      memory_type: conversational
  keep_originals: true
  originals_ttl: 365d

consolidation:
  enabled: true
  schedule: "0 3 * * *"
  similarity_threshold: 0.9

gc:
  enabled: true
  schedule: "0 4 * * 0"
  archive_after: 90d
  delete_after: 365d
memory = MemoryHarness.from_config("memharness.yaml")

Framework Integrations

LangChain

from memharness.integrations.langchain import MemharnessMemory

memory = MemharnessMemory(backend="postgresql://...")
chain = ConversationChain(llm=llm, memory=memory)

LangGraph

from memharness.integrations.langgraph import MemharnessCheckpointer

checkpointer = MemharnessCheckpointer(backend="postgresql://...")
graph = builder.compile(checkpointer=checkpointer)

Documentation

Full documentation: https://ayushsonuu.github.io/memharness

License

MIT License - see LICENSE for details.

Contributing

Contributions welcome! Please read our Contributing Guide.

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

memharness-0.3.0.tar.gz (102.0 kB view details)

Uploaded Source

Built Distribution

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

memharness-0.3.0-py3-none-any.whl (107.9 kB view details)

Uploaded Python 3

File details

Details for the file memharness-0.3.0.tar.gz.

File metadata

  • Download URL: memharness-0.3.0.tar.gz
  • Upload date:
  • Size: 102.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for memharness-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c957874a6ed7259f58d03b10988c2d473a3b25c5051a4652cf6b1c0cb589b01e
MD5 2363cfc0ff656e54ebeef00c0047d306
BLAKE2b-256 6d9511a5bf96d6b8edff4dab2bff3cf7e4312d15ad56d69e5ef305510df33d3f

See more details on using hashes here.

File details

Details for the file memharness-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: memharness-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 107.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for memharness-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c3300678a69cdb6df080bbd96ee60e5b9a4a397b4ffe6ea513936892d97d5f7
MD5 99eddf2b7459b9bd8c23bdad3f44c326
BLAKE2b-256 dd107fc94b7b4fb28b7314e4448ef18cd271f798c13aa85ae5b413c93447d897

See more details on using hashes here.

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