Agents & the cachly Brain
TL;DR Autonomous AI agents — LangChain, CrewAI, AutoGen, custom REST loops — can use the cachly Brain MCP server to persist memory across runs, so every agent instance learns from past attempts and never repeats the same mistake.
Why agents need persistent memory#
Benefit
What it means
No re-research
The agent recalls past solutions in under 10 ms, skipping re-run searches, API calls, or reasoning chains
Cross-run learning
Lessons from run #1 are available in run #2, across machines and instances
Fewer failures
Known pitfalls are stored; the agent avoids repeating failed approaches automatically
Setup — one command#
# Detects your editor and writes all configs automatically
npx @cachly-dev/mcp-server@latest autopilot
Or add manually to your agent's MCP config:
{
"mcpServers" : {
"cachly" : {
"command" : "npx" ,
"args" : [ "-y" , "@cachly-dev/mcp-server@latest" ],
"env" : {
"CACHLY_JWT" : "your-api-key" ,
"CACHLY_BRAIN_INSTANCE_ID" : "your-instance-uuid"
}
}
}
}
Example: Python agent with Brain memory#
import anthropic, os
client = anthropic.Anthropic()
# Brain MCP server — memory persists across every run
server_params = {
"command" : "npx" ,
"args" : [ "-y" , "@cachly-dev/mcp-server@latest" ],
"env" : {
"CACHLY_JWT" : os.environ[ "CACHLY_JWT" ],
"CACHLY_BRAIN_INSTANCE_ID" : os.environ[ "CACHLY_BRAIN_INSTANCE_ID" ],
},
}
with client.beta.messages.stream(
model = "claude-opus-4-5" ,
max_tokens = 4096 ,
tools = [{ "type" : "mcp" , "server" : server_params}],
messages = [{
"role" : "user" ,
"content" : "Fix the flaky Stripe webhook test. Check what worked before first." ,
}],
) as stream:
for text in stream.text_stream:
print (text, end = "" , flush = True )
# The agent automatically:
# 1. Calls recall_best_solution("fix:stripe-webhook") before writing code
# 2. Calls learn_from_attempts(...) after the fix — stored forever
Tool
Use case
What it does
recall_best_solution(topic)
Most impactful
Before attempting a task, retrieve the best known solution — what worked, what failed, exact commands, severity
learn_from_attempts(...)
After every run
Store what the agent learned — outcome, approach, commands, file paths — for all future runs
smart_recall(query)
Semantic search
Natural-language search over stored lessons, e.g. "docker healthcheck IPv6 error"
remember_context(key, value)
State
Persist arbitrary agent state between runs — last processed record ID, config values, intermediate results
recall_context(key)
State
Retrieve stored context by key; supports glob patterns like file:* for namespace retrieval
Framework compatibility#
Framework
Integration
Claude Code / Claude API
Native MCP
LangChain
MCP tool adapter
CrewAI
MCP tool adapter
AutoGen
MCP tool adapter
OpenAI Agents SDK
MCP tool adapter
Google ADK
MCP tool adapter
See MCP Integration for the underlying session lifecycle and Ambient Recall hooks, or Model-Neutral Brain for how the same memory travels between an editor session and an autonomous agent run.
← Back to all docs