Persistent memory for LLM agents. Event sourcing + semantic retrieval.
LLM agents are stateless. They forget context between sessions. They can't coordinate without explicit message passing. They have no audit trail.
CortexGit is an in-process memory system. Write events, retrieve context, persist facts. Works with any LLM, any agent framework.
pip install cortexgitimport 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?")))By default, CortexGit uses SQLite (sqlite+aiosqlite:///cortexgit.db) which requires no external server or setup.
To use PostgreSQL in production:
- Install PostgreSQL and create a database (e.g.
cortexgit). - Set the
DATABASE_URLenvironment variable:DATABASE_URL="postgresql+asyncpg://postgres:password@localhost:5432/cortexgit"
- ✅ 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
MIT