Skip to main content
Prefetch pulls relevant long-term memories into the system prompt at the start of every turn — the agent answers with context it never had to ask for.

Quick Start

1

Enable with three lines

Set prefetch=True on MemoryConfig and the agent recalls relevant memories before its first model call.
2

Tune the budget

Cap how many memories are injected and how large the block can grow.
3

Cross-agent recall

Store facts with one agent and recall them in another by sharing the same backend and user_id.

How It Works

Prefetch searches long-term memory with the user prompt, dedupes and budgets the matches, then appends them to the system prompt before the first LLM call.
Prefetch is default-off. When prefetch is False (or there is no memory instance), the backend is never queried and the prompt is unchanged. Backend errors are swallowed at debug level — the turn continues without recalled context.

Configuration Options

Full list of options, types, and defaults — MemoryConfig
Identity scoping (user_id, session_id) is inherited from the same MemoryConfig.

Common Patterns

Pattern 1 — Personal assistant with recalled preferences

Pattern 2 — Tight budget for cost control


Best Practices

Enable prefetch per agent, not globally, so you pay the backend query only on the turns that benefit from recalled context.
Without user_id, prefetch searches the per-instance store — a fresh agent-<uuid> on every process. Set user_id so recalled memories persist across runs.
prefetch_token_budget=512 is the ceiling, not the target. Large recalled blocks push out user context — start small and raise only when needed.
The async path awaits async backends; sync backends are offloaded off the event loop. No extra configuration required.
Any backend error is logged at debug level and the agent proceeds without recalled context — prefetch never fails a turn.

Memory

Memory backends and the remember/recall API

Knowledge

Add documents and URLs as agent knowledge