CodebaseMemory is a thin client over the rb-api /findings/... endpoints. It lets an agent persist observations during a run — bug locations, behavioral notes, architectural patterns — and recall them semantically on future runs. All transport errors are caught and surface as empty results / None / 0, so a missing rb-api never breaks the agent loop.
Initialize
Required. Identifier the findings are scoped under. Common patterns:
org/repo, repo@sha:abc123. All findings stored under the same id are searchable together.Sent as
Authorization: Bearer <api_key> on every request.Override to point at a self-hosted rb-api. Trailing slashes are stripped.
HTTP timeout passed to the underlying
httpx.Client.Store and recall
Store a finding
None on transport error. Content is truncated server-side at 8000 chars; file_path at 512; finding_type at 64.
Recall by query
{content, file_path, finding_type, score, ...} dicts ordered by descending score. Raise score_threshold for tighter matches; lower it for more recall.
Pre-formatted recall (for tool outputs)
format_recall combines recall with a human-readable renderer. Use it when a tool needs to return findings as a string.
"(no relevant findings in cache yet)" when nothing matches.
Other operations
List every finding
Batch store
content. file_path, finding_type, and metadata are optional. Returns the count actually stored (entries that fail or have empty content are skipped).
Coverage check
coverage_for returns the fraction of a file list that has at least one stored finding. A soft suffix-match means a stored pydantic/main.py covers a query for bare main.py.
Invalidate stale findings
When files change, drop their findings:Clear the entire cache
Release the HTTP client
CodebaseMemory holds a persistent httpx.Client to keep TCP connections warm across calls. Call close() when you’re done if your process needs to release sockets cleanly.
Pair with ImportGraph for blast-radius invalidation
When a file changes, you usually want to invalidate every file that imports it.ImportGraph (see Import graph) gives you the blast radius:
ImportGraph.build_from_files requires networkx. Install with pip install networkx.Wire into your agent
Each framework has a tool factory wrappingCodebaseMemory (and optionally ImportGraph). See:
- LangChain tools via
make_langchain_tools - OpenAI Agents tools via
make_openai_tools reasonblocks.integrations.claude_tools.make_claude_toolsfor the Anthropic Messages API

