Skip to content

Commit 4f6ca57

Browse files
helloissarielgithub-actions[bot]
authored andcommitted
chore: update llm bundle
1 parent babedae commit 4f6ca57

File tree

1 file changed

+187
-0
lines changed

1 file changed

+187
-0
lines changed

llm.txt

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8305,6 +8305,114 @@ if response.provider != "openai":
83058305

83068306
---
83078307

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.
8319+
8320+
Core class: `spoon_ai.memory.mem0_client.SpoonMem0`
8321+
8322+
### Initialization
8323+
```python
8324+
from spoon_ai.memory.mem0_client import SpoonMem0
8325+
8326+
mem0 = SpoonMem0(
8327+
{
8328+
"api_key": "YOUR_MEM0_API_KEY", # or set MEM0_API_KEY env var
8329+
"user_id": "user_123", # or agent_id
8330+
"collection": "my_namespace", # optional namespace/collection
8331+
"metadata": {"project": "demo"}, # merged into every write
8332+
"filters": {"project": "demo"}, # merged into every query
8333+
"async_mode": False, # sync writes by default
8334+
}
8335+
)
8336+
if not mem0.is_ready():
8337+
print("Mem0 not available")
8338+
```
8339+
8340+
### Add memory
8341+
```python
8342+
# add a conversation (sync)
8343+
mem0.add_memory([
8344+
{"role": "user", "content": "I love Solana meme coins"},
8345+
{"role": "assistant", "content": "Got it, will focus on Solana"},
8346+
], user_id="user_123") # async_mode is taken from mem0_config (defaults to False)
8347+
8348+
# add a single text helper
8349+
mem0.add_text("Prefers low gas fees") # same async_mode default applies
8350+
```
8351+
8352+
Async variant: `await mem0.aadd_memory(messages, user_id=...)`
8353+
8354+
### Search memory
8355+
```python
8356+
results = mem0.search_memory(
8357+
"Solana meme coins high risk",
8358+
user_id="user_123",
8359+
limit=5,
8360+
)
8361+
for r in results: # results is a list of strings extracted from Mem0 responses
8362+
print("-", r)
8363+
```
8364+
8365+
Async variant: `await mem0.asearch_memory(query, user_id=...)`
8366+
8367+
### Get all memory
8368+
```python
8369+
all_memories = mem0.get_all_memory(user_id="user_123", limit=20) # returns [] if client is not ready or call fails
8370+
```
8371+
8372+
## Demo: Intelligent Web3 Portfolio Assistant
8373+
Path: `examples/mem0_agent_demo.py`
8374+
8375+
Key idea: The agent (ChatBot) is configured with Mem0 so it can recall user preferences after restart.
8376+
8377+
```python
8378+
from spoon_ai.chat import ChatBot
8379+
8380+
USER_ID = "crypto_whale_001"
8381+
SYSTEM_PROMPT = "...portfolio assistant..."
8382+
8383+
mem0_config = {
8384+
"user_id": USER_ID,
8385+
"metadata": {"project": "web3-portfolio-assistant"},
8386+
"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+
83088416
FILE: docs/core-concepts/mcp-protocol.md
83098417

83108418
# MCP Protocol
@@ -15311,6 +15419,85 @@ Navigate the sidebar on the left to dive into any module. Each page documents th
1531115419

1531215420
---
1531315421

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
15447+
from spoon_toolkits.memory import (
15448+
AddMemoryTool, SearchMemoryTool, GetAllMemoryTool, UpdateMemoryTool, DeleteMemoryTool
15449+
)
15450+
15451+
MEM0_CFG = {
15452+
"user_id": "defi_user_001",
15453+
"metadata": {"project": "demo"},
15454+
"async_mode": False, # sync writes to avoid read-after-write delays
15455+
"collection": "demo_mem",
15456+
}
15457+
15458+
class MemoryAgent(SpoonReactAI):
15459+
mem0_config = MEM0_CFG
15460+
available_tools = ToolManager([
15461+
AddMemoryTool(mem0_config=MEM0_CFG),
15462+
SearchMemoryTool(mem0_config=MEM0_CFG),
15463+
GetAllMemoryTool(mem0_config=MEM0_CFG),
15464+
UpdateMemoryTool(mem0_config=MEM0_CFG),
15465+
DeleteMemoryTool(mem0_config=MEM0_CFG),
15466+
])
15467+
15468+
agent = MemoryAgent(
15469+
llm=ChatBot(llm_provider="openrouter", model_name="anthropic/claude-3.5-sonnet", enable_long_term_memory=False),
15470+
)
15471+
```
15472+
15473+
## Demo flow (from `spoon-core/examples/mem0_tool_agent.py`)
15474+
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`.
15489+
- Search: `query`, `limit`/`top_k`, optional filters.
15490+
- GetAll: `page`, `page_size`/`limit`/`top_k`, filters.
15491+
- Update: `memory_id` (required), `text`, `metadata`.
15492+
- Delete: `memory_id` (required).
15493+
15494+
## Best practices
15495+
- Keep a stable `user_id`/`collection` for scoping; pass it explicitly on each call for consistency.
15496+
- Use `async_mode=False` when you need immediate read-after-write in demos/tests.
15497+
- If you pass a custom `SpoonMem0` via `mem0_client`, you can reuse a single client across tools to avoid repeated pings/initialization.
15498+
15499+
---
15500+
1531415501
FILE: Toolkit/social-media/index.md
1531515502

1531615503
---

0 commit comments

Comments
 (0)