Skip to main content

Persistent memory for LLM agents

Project description

CortexGit

Persistent memory for LLM agents. Event sourcing + semantic retrieval.

The Problem

LLM agents are stateless. They forget context between sessions. They can't coordinate without explicit message passing. They have no audit trail.

The Solution

CortexGit is an in-process memory system. Write events, retrieve context, persist facts. Works with any LLM, any agent framework.

Installation

pip install cortexgit

Quick Start

import asyncio
from cortexgit import CortexGit
from anthropic import Anthropic

# Initialize memory (creates local SQLite database)
memory = CortexGit()
client = Anthropic()

async def my_agent(user_query):
    session_id = "session-1"
    agent_id = "my-agent"
    
    # Retrieve relevant context from memory
    context = await memory.get_context(
        goal=user_query,
        budget_tokens=4000,
        session_id=session_id
    )
    
    # Call Claude with context
    response = await client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=1024,
        system=f"You are a helpful agent. Memory: {context}",
        messages=[{"role": "user", "content": user_query}]
    )
    
    # Remember what happened
    await memory.log_event(
        session_id=session_id,
        agent_id=agent_id,
        event_type="agent",
        payload={"query": user_query, "response": response.content[0].text}
    )
    
    return response.content[0].text

# Use it
print(asyncio.run(my_agent("What is 2+2?")))

Documentation

Configuration

By default, CortexGit uses SQLite (sqlite+aiosqlite:///cortexgit.db) which requires no external server or setup.

To use PostgreSQL in production:

  1. Install PostgreSQL and create a database (e.g. cortexgit).
  2. Set the DATABASE_URL environment variable:
    DATABASE_URL="postgresql+asyncpg://postgres:password@localhost:5432/cortexgit"
    

Features

  • ✅ Append-only event log (source of truth)
  • ✅ Persistent entity registry with conflict detection
  • ✅ Automatic snapshot generation
  • ✅ Semantic retrieval over compressed memory
  • ✅ Works with any LLM (Claude, GPT, local models)
  • ✅ Single import, no server needed

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

cortexgit-0.2.1.tar.gz (84.2 kB view details)

Uploaded Source

Built Distribution

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

cortexgit-0.2.1-py3-none-any.whl (42.6 kB view details)

Uploaded Python 3

File details

Details for the file cortexgit-0.2.1.tar.gz.

File metadata

  • Download URL: cortexgit-0.2.1.tar.gz
  • Upload date:
  • Size: 84.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for cortexgit-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7cc3237be0501c91e90852b12584bd8fa221f01ddc0ca9b7d087239ab898721c
MD5 1e6fffcfc54ae1ae968356dca093b4d0
BLAKE2b-256 9914ee3faa8e9f4ee55431b18cf36dfff02c99a46826ddc24c05437ceab375aa

See more details on using hashes here.

File details

Details for the file cortexgit-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: cortexgit-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 42.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for cortexgit-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0e4e85be3f5c4ba6573bcf5249b88ba6cfc23fde4e68f298158e9d366f1689bd
MD5 ed58307640d65db3baad2fce212dd0ff
BLAKE2b-256 9a46dbcd8d871849957b60f9000853d5517b078aa919f3f160f5d9c1e3f133db

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