|
1 | | -# @wbx-modified copilot-a3f7·MTN | 2026-04-24 | minimal Recall agent-memory example |
| 1 | +# @wbx-modified copilot-b1c4 | 2026-04-28 03:38 MTN | v0.2 | rewrote using requests after recall-client SDK pkg deleted from PyPI | prev: copilot-a3f7@2026-04-24 |
2 | 2 | """End-to-end agent memory: remember, recall, checkpoint. |
3 | 3 |
|
4 | 4 | Run a server first: |
5 | 5 | docker run -d -p 8787:8787 -e API_KEY=changeme \ |
6 | 6 | -v recall-data:/data ghcr.io/recallworks/recall:latest |
7 | 7 |
|
8 | 8 | Then: |
9 | | - pip install recall-client |
| 9 | + pip install requests |
10 | 10 | python agent_memory.py |
11 | 11 | """ |
12 | 12 | from __future__ import annotations |
13 | 13 |
|
14 | 14 | import os |
15 | 15 |
|
16 | | -from recall_client import RecallClient |
| 16 | +import requests |
17 | 17 |
|
18 | 18 | URL = os.environ.get("RECALL_URL", "http://localhost:8787") |
19 | 19 | KEY = os.environ.get("RECALL_KEY", "changeme") |
| 20 | +H = {"X-API-Key": KEY, "Content-Type": "application/json"} |
| 21 | + |
| 22 | + |
| 23 | +def call(tool: str, **payload) -> dict: |
| 24 | + r = requests.post(f"{URL}/tool/{tool}", headers=H, json=payload, timeout=30) |
| 25 | + r.raise_for_status() |
| 26 | + return r.json() |
20 | 27 |
|
21 | 28 |
|
22 | 29 | def main() -> None: |
23 | | - with RecallClient(URL, api_key=KEY) as c: |
24 | | - # 0. Health |
25 | | - print("server:", c.health()) |
26 | | - |
27 | | - # 1. Store a few facts the agent should remember across sessions. |
28 | | - c.remember("user prefers dark mode", source="prefs", tags="ui,dark-mode") |
29 | | - c.remember("project deadline is 2026-05-15", source="project", tags="deadline") |
30 | | - c.remember("lead engineer is Jamie (jamie@example.com)", source="people", tags="contact") |
31 | | - |
32 | | - # 2. Pull them back semantically. |
33 | | - hits = c.recall("when is the deadline", n=3) |
34 | | - print("\nrecall: when is the deadline") |
35 | | - print(hits.result) |
36 | | - |
37 | | - # 3. End-of-session checkpoint so the next agent can pick up. |
38 | | - cp = c.checkpoint( |
39 | | - intent="onboard new agent to the project", |
40 | | - established="user prefers dark mode; deadline 2026-05-15; lead is Jamie", |
41 | | - pursuing="prepare kickoff doc draft", |
42 | | - open_questions="which team channel does Jamie use?", |
43 | | - session="e0a1", |
44 | | - ) |
45 | | - print("\ncheckpoint:", cp.result.splitlines()[0]) |
| 30 | + # 0. Health |
| 31 | + print("server:", requests.get(f"{URL}/health", headers=H, timeout=10).json()) |
| 32 | + |
| 33 | + # 1. Store a few facts the agent should remember across sessions. |
| 34 | + call("remember", content="user prefers dark mode", source="prefs", tags="ui,dark-mode") |
| 35 | + call("remember", content="project deadline is 2026-05-15", source="project", tags="deadline") |
| 36 | + call("remember", content="lead engineer is Jamie (jamie@example.com)", source="people", tags="contact") |
| 37 | + |
| 38 | + # 2. Pull them back semantically. |
| 39 | + hits = call("recall", query="when is the deadline", n=3) |
| 40 | + print("\nrecall: when is the deadline") |
| 41 | + print(hits["result"]) |
| 42 | + |
| 43 | + # 3. End-of-session checkpoint so the next agent can pick up. |
| 44 | + cp = call( |
| 45 | + "checkpoint", |
| 46 | + intent="onboard new agent to the project", |
| 47 | + established="user prefers dark mode; deadline 2026-05-15; lead is Jamie", |
| 48 | + pursuing="prepare kickoff doc draft", |
| 49 | + open_questions="which team channel does Jamie use?", |
| 50 | + session="e0a1", |
| 51 | + ) |
| 52 | + print("\ncheckpoint:", cp["result"].splitlines()[0]) |
46 | 53 |
|
47 | 54 |
|
48 | 55 | if __name__ == "__main__": |
|
0 commit comments