Engram Documentation
Causal memory for AI agents. Not just what happened โ why.
Quickstart
BYOK (open-source, free)
# Install pip install engram-causal # Set your Anthropic key (only needed for free-text extraction) export ANTHROPIC_API_KEY=sk-ant-... # Install hooks for Claude Code engram install # Extract a causal triple from free text engram extract "WeatherAPI timed out because the server was overloaded" # Query root cause engram why "WeatherAPI"
How it works
Three-track pipeline. LLM only called once per unique text. Everything else is local.
input โ structured JSON event?
YES โ rule_extractor() โ CausalTriple (confidence=EXTRACTED, $0.00)
NO โ SHA256 cache hit?
YES โ cached triples ($0.00)
NO โ claude_extractor() โ CausalTriple + cache result
Confidence tagging โ every triple is tagged:
EXTRACTEDโ found directly in structured event fields (confidence 1.0)INFERREDโ extracted by Claude from free-text (confidence 0.0โ1.0)AMBIGUOUSโ below threshold, kept for exploration
CLI reference
# Extract causal triples from free text engram extract "WeatherAPI timed out because server was overloaded" # Ingest structured event log (zero LLM) engram ingest ./logs/session.json # Query root cause (backward DFS, zero LLM) engram why "WeatherAPI" # Point-in-time causal query engram why "PaymentService" --before 2024-03-01 # Start local API server engram serve # Start MCP stdio server engram serve --mcp # Install hooks for your platform engram install # Claude Code (PreToolUse + PostToolUse) engram install --platform cursor # Cursor rules engram install --platform codex # Codex AGENTS.md + hook
SDK reference
Basic client
import engram
# BYOK โ bring your own Anthropic key
client = engram.Client(anthropic_api_key="sk-ant-...")
# Extract and store
triples = await client.extract("WeatherAPI timed out because server overloaded")
await client.store(triples)
# Why-query
result = await client.why("WeatherAPI")
print(result.explanation)
print(result.top_causes)Agent decorator
import engram
@engram.wrap(entity="PaymentService")
async def my_agent(task: str) -> str:
# Engram auto-injects causal context before execution
# Auto-ingests outcome as structured event after
...Hook setup
Hooks are the core of the agent performance loop. PreToolUse injects causal context before every tool call. PostToolUse ingests the outcome back into the graph.
Claude Code
engram install # Writes .claude/settings.json hooks + CLAUDE.md section # PreToolUse: fires before Bash/Glob/Read โ injects top causal chain (โค500 tokens) # PostToolUse: fires after tool completes โ ingests outcome as structured event
Cursor
engram install --platform cursor # Writes .cursor/rules/engram.mdc with alwaysApply: true
Codex
engram install --platform codex # Writes AGENTS.md + .codex/hooks.json PreToolUse hook
ENGRAM_HOOK_BUDGET=300.MCP server
# Start MCP stdio server
engram serve --mcp
# .mcp.json
{
"mcpServers": {
"engram": {
"type": "stdio",
"command": "engram",
"args": ["serve", "--mcp"]
}
}
}MCP tools exposed:
why_query(entity, max_depth, min_confidence)โ backward DFS causal chainstore_triple(cause, effect, mechanism, confidence)โ persist a causal tripleingest_events(events)โ batch ingest structured event log
API reference
| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/health | Service health + graph stats |
| POST | /v1/extract | Extract triples without storing |
| POST | /v1/store | Persist triples to graph |
| GET | /v1/why/{entity} | Why-query for entity (DFS) |
| POST | /v1/extract-and-store | Extract + persist in one call |
| POST | /v1/events | Ingest structured event log |
| GET | /v1/why/session/{id} | Explain session failure chain |
Token costs
| Event type | LLM cost | Reason |
|---|---|---|
| Structured JSON event | $0.00 | Rule-based extractor |
| Repeated free-text log | $0.00 | SHA256 cache hit |
| New free-text (first time) | ~$0.0003/1K tokens | Claude Haiku โ cached |
| Why-query | $0.00 | Graph DFS, no LLM |
| Explanation synthesis | $0.00 | Template engine |
Changelog
Canonical release history: CHANGELOG.md ยท GitHub release bodies: RELEASE_NOTES.md
v0.1.4 โ Entity normalization improvements
- 40eefcc โ normalization entity added with fallback
v0.1.3 โ Codex integration fix
- 195e91d โ version updated
- 2bc1afc โ fix: codex network access to engram with rule
v0.1.2 โ CI release pipeline update
- ac54283 โ fix: published version updated with CI
v0.1.1 โ PyPI metadata improvements
- b5586f7 โ Add PyPI project description metadata
v0.1.0 โ Initial release
- af3ca1b โ Use PyPI API token for publishing
- 6bf0122 โ causal graph in CLI mode activated
- 4dbba73 โ fix: cache import changed with hosted fastapi app for hosted users
- a2fbf5f โ per org kuzu graph in s3
- f86f7a7 โ engram install hooks for claude code