You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: llm.txt
+187Lines changed: 187 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -8305,6 +8305,114 @@ if response.provider != "openai":
8305
8305
8306
8306
---
8307
8307
8308
+
FILE: docs/core-concepts/long-term memory.md
8309
+
8310
+
# Long-Term Memory with Mem0
8311
+
8312
+
Spoon-core ships a lightweight Mem0 wrapper (`SpoonMem0`) that lets agents persist and recall user context across sessions. This page shows the key API and a minimal end-to-end demo.
8313
+
8314
+
## What SpoonMem0 does
8315
+
- Wraps `mem0.MemoryClient` with safe defaults and fallbacks.
8316
+
- Builds metadata/filters with `user_id`/`agent_id` so memories stay scoped per user (injects `user_id` into filters/metadata if absent, and passes collection when set).
8317
+
- Provides sync/async helpers to add, search, and list memories.
8318
+
- Gracefully disables itself if `mem0ai` or `MEM0_API_KEY` is missing; when the client isn’t ready or a call fails, helpers return empty results rather than raising.
"async_mode": False, # sync writes so next query sees the data
8387
+
}
8388
+
8389
+
# Create an LLM with long-term memory enabled
8390
+
llm = ChatBot(
8391
+
llm_provider="openrouter",
8392
+
model_name="openai/gpt-5.1",
8393
+
enable_long_term_memory=True,
8394
+
mem0_config=mem0_config,
8395
+
)
8396
+
```
8397
+
8398
+
Flow:
8399
+
1) **Session 1** – capture preferences: user says they are a high-risk Solana meme trader; model replies; Mem0 stores the interaction.
8400
+
2) **Session 2** – reload a fresh ChatBot with the same `mem0_config`; the agent recalls past preferences (via Mem0 search) before answering.
8401
+
3) **Session 3** – user pivots to safe Arbitrum yield; new info is stored; subsequent queries reflect updated preferences.
8402
+
8403
+
Run the demo:
8404
+
```bash
8405
+
python examples/mem0_agent_demo.py
8406
+
```
8407
+
8408
+
## Notes & Best Practices
8409
+
- Always set `MEM0_API_KEY` or pass `api_key` in `mem0_config`.
8410
+
- Use a stable `user_id` (or `agent_id`) so memories stay scoped; include `collection`/`filters` if you want stricter isolation. The wrapper injects `user_id` into filters and metadata if missing.
8411
+
- Keep `async_mode=False` during demos/tests to avoid read-after-write delays; the wrapper always uses `mem0_config.get("async_mode", False)` for adds (no per-call override).
8412
+
- Handle absence gracefully: `SpoonMem0.is_ready()` lets you disable LTM if Mem0 isn’t installed or configured; helpers will otherwise return empty results when the client is unavailable.
8413
+
8414
+
---
8415
+
8308
8416
FILE: docs/core-concepts/mcp-protocol.md
8309
8417
8310
8418
# MCP Protocol
@@ -15311,6 +15419,85 @@ Navigate the sidebar on the left to dive into any module. Each page documents th
15311
15419
15312
15420
---
15313
15421
15422
+
FILE: Toolkit/memory/mem0.md
15423
+
15424
+
# Memory Tools (Mem0)
15425
+
15426
+
Spoon-toolkit provides Mem0-powered tools that plug into spoon-core agents for long-term memory. They wrap `spoon_ai.memory.mem0_client.SpoonMem0` and expose a consistent tool interface. `ToolResult.output` carries the raw Mem0 response (not a formatted string); validation failures or an unready client return `ToolResult.error` (e.g., “Client not ready”, “No content provided.”) instead of raising.
15427
+
15428
+
## Available tools
15429
+
- `AddMemoryTool` — store text or conversation snippets.
15430
+
- `SearchMemoryTool` — semantic/natural-language search over stored memories.
15431
+
- `GetAllMemoryTool` — list memories (with paging/filters).
15432
+
- `UpdateMemoryTool` — update an existing memory by id.
15433
+
- `DeleteMemoryTool` — delete a memory by id.
15434
+
15435
+
All tools accept `mem0_config` (api_key/user_id/collection/metadata/filters/etc.) or an injected `SpoonMem0` client. If `mem0ai` or `MEM0_API_KEY` is missing, client initialization may fail; otherwise an unready client yields `ToolResult.error` rather than an exception.
15436
+
15437
+
Parameter merging behavior:
15438
+
- `user_id` defaults to `mem0_config.user_id`/`agent_id` (or the client’s user_id) and is also injected into filters if missing.
15439
+
- `collection`, `metadata`, and `filters` from the injected client/config are merged into each call; per-call metadata/filters override on conflict.
15440
+
- `async_mode` is only forwarded when passed to `AddMemoryTool.execute`; it is not auto-propagated from `mem0_config` by these wrappers (rely on `SpoonMem0` defaults if needed).
15441
+
15442
+
## Quick usage (agent-side)
15443
+
```python
15444
+
from spoon_ai.agents.spoon_react import SpoonReactAI
15445
+
from spoon_ai.chat import ChatBot
15446
+
from spoon_ai.tools.tool_manager import ToolManager
The example walks through capture → recall → update → delete:
15475
+
15476
+
1) **Capture**: `add_memory` with user preferences. Immediately verify with `get_all_memory` (same `user_id`) and then `search_memory` to show stored content.
15477
+
2) **Recall**: Build a fresh agent with the same `mem0_config` and `search_memory` to retrieve prior preferences.
15478
+
3) **Update**: `add_memory` new preference + `update_memory` a specific record (by id) to reflect the pivot; then `search_memory` again to confirm recency.
15479
+
4) **Delete**: `delete_memory` the updated record; `get_all_memory` to show remaining memories.
15480
+
15481
+
Run the example:
15482
+
```bash
15483
+
python spoon-core/examples/mem0_tool_agent.py
15484
+
```
15485
+
15486
+
## Tool parameters (summary)
15487
+
- Shared: `user_id`, `metadata`, `filters`, `collection` inherited via `mem0_config` or passed per-call.
15488
+
- Add: `content` or `messages`, `role` (default `user`), `async_mode`.
0 commit comments