Framework Integrations
Engram is framework-agnostic, but adapters and patterns are available for common agent stacks.
LangChain Pattern
Use Engram tool wrappers to persist and recover intermediate decisions.
ts
import { EngramStoreTool, EngramRetrieveTool } from 'engramjs/adapters/langchain'
const tools = [new EngramStoreTool(sdk), new EngramRetrieveTool(sdk)]Best practice:
- persist decision snapshots at stable checkpoints
- store CID references in your agent state machine
LlamaIndex Pattern
Use reader/writer abstractions for document or memory flow.
ts
import { EngramWriter, EngramReader } from 'engramjs/adapters/llamaindex'
const writer = new EngramWriter(sdk)
const cid = await writer.store(document)
const reader = new EngramReader(sdk)
const reloaded = await reader.loadData(cid)MCP-First Integration
When your host supports MCP natively, you can integrate without writing SDK glue code:
- run
@engram-sdk/mcp - register server URL in client config
- call
engram_*tools from your AI runtime
This is often the quickest path to production experiments.
Context Window Offload Pattern
A practical integration pattern from the reference agent loop is to offload context once token usage crosses a threshold:
ts
const MAX_TOKENS = 8192
const OFFLOAD_THRESHOLD = 0.8
if (tokenCount / MAX_TOKENS >= OFFLOAD_THRESHOLD) {
const receipt = await sdk.store(
{ messages, iteration },
{ priority: 'standard' }
)
messages = [{
role: 'system',
content: `Previous context was offloaded to CID ${receipt.cid}.`
}]
}Why this helps:
- prevents runaway prompt growth
- preserves recoverability with explicit CID references
- gives deterministic points for renew/prune policies later