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.0.tar.gz (78.8 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.0-py3-none-any.whl (41.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cortexgit-0.2.0.tar.gz
  • Upload date:
  • Size: 78.8 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.0.tar.gz
Algorithm Hash digest
SHA256 04496281239ca7acc4181a18cb12cbdee15bee430ea9a904155c3990bbce546d
MD5 160b1c7eff7d8b6d1919b9fbe650586e
BLAKE2b-256 4c1105409bec58b91d14043debda65ec158ea7610f39cf40a7b48d871a120b46

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cortexgit-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 41.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 371add3216534be849e67716af512ebaa539c2cd73af7e6a3ea13895bb860774
MD5 9e6ee7fe636dcfdad0acdec19e8f8baa
BLAKE2b-256 2d04707e2fb3cd06261cc80524d7f1392e4c881f522cfdb297c862b8b1a7d18a

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