recallix-adk 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
+
3
+ # dependencies
4
+ /node_modules
5
+ /.pnp
6
+ .pnp.*
7
+ .yarn/*
8
+ !.yarn/patches
9
+ !.yarn/plugins
10
+ !.yarn/releases
11
+ !.yarn/versions
12
+
13
+ # testing
14
+ /coverage
15
+
16
+ # next.js
17
+ /.next/
18
+ /out/
19
+
20
+ # production
21
+ /build
22
+
23
+ # misc
24
+ .DS_Store
25
+ *.pem
26
+
27
+ # debug
28
+ npm-debug.log*
29
+ yarn-debug.log*
30
+ yarn-error.log*
31
+ .pnpm-debug.log*
32
+
33
+ # env files (can opt-in for committing if needed)
34
+ .env*
35
+
36
+ # vercel
37
+ .vercel
38
+
39
+ # typescript
40
+ *.tsbuildinfo
41
+ next-env.d.ts
42
+
43
+ # python
44
+ venv/
45
+ .venv/
46
+ __pycache__/
47
+ *.pyc
48
+ *.pyo
49
+ *.pyd
50
+ .Python
51
+ env/
52
+ pip-log.txt
53
+ pip-delete-this-directory.txt
54
+
55
+ # Databases and Local Models
56
+ *.db
57
+ *.sqlite
58
+ *.sqlite3
59
+ backend/models/
60
+ storage/
61
+
62
+ # Build and IDE
63
+ **/build/
64
+ .vscode/
65
+ .idea/
66
+ *.log
67
+
68
+ # Phase 6 training data (some sources are CC BY-SA; never committed)
69
+ .phase6_data/
@@ -0,0 +1,80 @@
1
+ Metadata-Version: 2.5
2
+ Name: recallix-adk
3
+ Version: 0.1.0
4
+ Summary: Recallix as the memory service of Google ADK agents: self-hosted, no LLM calls for memory, says when it has no record.
5
+ Project-URL: Homepage, https://github.com/AyishikD/Recallix/tree/main/integrations/google-adk
6
+ License-Expression: Apache-2.0
7
+ Requires-Python: >=3.10
8
+ Requires-Dist: google-adk>=2.0
9
+ Requires-Dist: recallix>=0.2.5
10
+ Description-Content-Type: text/markdown
11
+
12
+ # recallix-adk: Recallix memory for Google ADK agents
13
+
14
+ `RecallixMemoryService` plugs a self-hosted [Recallix](https://github.com/AyishikD/Recallix) server into
15
+ [Google's Agent Development Kit](https://google.github.io/adk-docs/) as the agent's memory service.
16
+
17
+ * **No LLM calls for memory.** Storing and searching use Recallix's local models; your agent's model is the
18
+ only one you pay for.
19
+ * **Honest search.** When Recallix finds nothing that answers the query, `search_memory` returns no memories,
20
+ so the agent is not handed near-misses to guess from.
21
+ * **Real dates.** Each event is stored with the time it happened, even when ADK hands over a session later.
22
+ * **Your data stays on your server**, separated per ADK user and per app.
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ pip install recallix-adk # brings google-adk and the recallix SDK
28
+ ```
29
+
30
+ Run Recallix ([quickstart](../../docs/quickstart.md)) and create one key with role `service`, which acts for
31
+ each of your ADK users:
32
+
33
+ ```bash
34
+ python -m backend.tools.keys create --user my-adk-app --role service
35
+ ```
36
+
37
+ ## Use
38
+
39
+ ```python
40
+ import os
41
+
42
+ from google.adk.agents import Agent
43
+ from google.adk.runners import Runner
44
+ from google.adk.sessions import InMemorySessionService
45
+ from google.adk.tools import load_memory
46
+ from recallix_adk import RecallixMemoryService
47
+
48
+ memory = RecallixMemoryService(api_key=os.environ["RECALLIX_SERVICE_KEY"],
49
+ base_url="http://localhost:8000",
50
+ mode="balanced") # or "cautious" / "helpful"
51
+ agent = Agent(name="assistant", model="gemini-2.5-flash", instruction="...", tools=[load_memory])
52
+ runner = Runner(agent=agent, app_name="my_app", session_service=InMemorySessionService(), memory_service=memory)
53
+
54
+ # after a conversation (or after each turn):
55
+ await memory.add_session_to_memory(session)
56
+ ```
57
+
58
+ | Argument | Default | What it does |
59
+ |---|---|---|
60
+ | `mode` | server's `recall.mode` | How readily search answers: `cautious` checks every answer twice; `helpful` answers more counting, ordering and "how long between" questions and adds a worked-out result as the first memory. |
61
+ | `limit` | 10 | Memories per search. |
62
+ | `store_authors` | `("user",)` | Which event authors are stored. The default stores what users said; `None` stores every author, including the agent's replies. |
63
+
64
+ What maps to what:
65
+
66
+ | ADK | Recallix |
67
+ |---|---|
68
+ | `user_id` | user (a service key acts for each user) |
69
+ | `app_name` | agent id, so each app reads back what it wrote |
70
+ | `add_session_to_memory` / `add_events_to_memory` / `add_memory` | `store`, one memory per text event, with its original time; storing a session again stores nothing twice |
71
+ | `search_memory` | `recall`; `MemoryEntry.custom_metadata` carries the relevance, trust and receipt |
72
+ | `delete_memory` | `delete`, with a deletion receipt in Recallix |
73
+
74
+ Needs Recallix server 0.2.5 or newer (for `mode` and original timestamps).
75
+
76
+ ## Tests
77
+
78
+ Against a running Recallix: `RECALLIX_URL=http://127.0.0.1:8000 RECALLIX_SERVICE_KEY=rx_... pytest tests`.
79
+
80
+ Licence: Apache-2.0.
@@ -0,0 +1,69 @@
1
+ # recallix-adk: Recallix memory for Google ADK agents
2
+
3
+ `RecallixMemoryService` plugs a self-hosted [Recallix](https://github.com/AyishikD/Recallix) server into
4
+ [Google's Agent Development Kit](https://google.github.io/adk-docs/) as the agent's memory service.
5
+
6
+ * **No LLM calls for memory.** Storing and searching use Recallix's local models; your agent's model is the
7
+ only one you pay for.
8
+ * **Honest search.** When Recallix finds nothing that answers the query, `search_memory` returns no memories,
9
+ so the agent is not handed near-misses to guess from.
10
+ * **Real dates.** Each event is stored with the time it happened, even when ADK hands over a session later.
11
+ * **Your data stays on your server**, separated per ADK user and per app.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pip install recallix-adk # brings google-adk and the recallix SDK
17
+ ```
18
+
19
+ Run Recallix ([quickstart](../../docs/quickstart.md)) and create one key with role `service`, which acts for
20
+ each of your ADK users:
21
+
22
+ ```bash
23
+ python -m backend.tools.keys create --user my-adk-app --role service
24
+ ```
25
+
26
+ ## Use
27
+
28
+ ```python
29
+ import os
30
+
31
+ from google.adk.agents import Agent
32
+ from google.adk.runners import Runner
33
+ from google.adk.sessions import InMemorySessionService
34
+ from google.adk.tools import load_memory
35
+ from recallix_adk import RecallixMemoryService
36
+
37
+ memory = RecallixMemoryService(api_key=os.environ["RECALLIX_SERVICE_KEY"],
38
+ base_url="http://localhost:8000",
39
+ mode="balanced") # or "cautious" / "helpful"
40
+ agent = Agent(name="assistant", model="gemini-2.5-flash", instruction="...", tools=[load_memory])
41
+ runner = Runner(agent=agent, app_name="my_app", session_service=InMemorySessionService(), memory_service=memory)
42
+
43
+ # after a conversation (or after each turn):
44
+ await memory.add_session_to_memory(session)
45
+ ```
46
+
47
+ | Argument | Default | What it does |
48
+ |---|---|---|
49
+ | `mode` | server's `recall.mode` | How readily search answers: `cautious` checks every answer twice; `helpful` answers more counting, ordering and "how long between" questions and adds a worked-out result as the first memory. |
50
+ | `limit` | 10 | Memories per search. |
51
+ | `store_authors` | `("user",)` | Which event authors are stored. The default stores what users said; `None` stores every author, including the agent's replies. |
52
+
53
+ What maps to what:
54
+
55
+ | ADK | Recallix |
56
+ |---|---|
57
+ | `user_id` | user (a service key acts for each user) |
58
+ | `app_name` | agent id, so each app reads back what it wrote |
59
+ | `add_session_to_memory` / `add_events_to_memory` / `add_memory` | `store`, one memory per text event, with its original time; storing a session again stores nothing twice |
60
+ | `search_memory` | `recall`; `MemoryEntry.custom_metadata` carries the relevance, trust and receipt |
61
+ | `delete_memory` | `delete`, with a deletion receipt in Recallix |
62
+
63
+ Needs Recallix server 0.2.5 or newer (for `mode` and original timestamps).
64
+
65
+ ## Tests
66
+
67
+ Against a running Recallix: `RECALLIX_URL=http://127.0.0.1:8000 RECALLIX_SERVICE_KEY=rx_... pytest tests`.
68
+
69
+ Licence: Apache-2.0.
@@ -0,0 +1,18 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "recallix-adk"
7
+ version = "0.1.0"
8
+ description = "Recallix as the memory service of Google ADK agents: self-hosted, no LLM calls for memory, says when it has no record."
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ requires-python = ">=3.10"
12
+ dependencies = ["google-adk>=2.0", "recallix>=0.2.5"]
13
+
14
+ [project.urls]
15
+ Homepage = "https://github.com/AyishikD/Recallix/tree/main/integrations/google-adk"
16
+
17
+ [tool.hatch.build.targets.wheel]
18
+ packages = ["src/recallix_adk"]
@@ -0,0 +1,5 @@
1
+ """Recallix memory for Google ADK agents."""
2
+ from .memory_service import RecallixMemoryService
3
+
4
+ __all__ = ["RecallixMemoryService"]
5
+ __version__ = "0.1.0"
@@ -0,0 +1,135 @@
1
+ """
2
+ RecallixMemoryService: Recallix as the memory of a Google ADK agent.
3
+
4
+ from recallix_adk import RecallixMemoryService
5
+ memory = RecallixMemoryService(api_key="rx_...") # a Recallix key with role "service"
6
+ runner = Runner(agent=agent, app_name="my_app", session_service=..., memory_service=memory)
7
+
8
+ ADK hands over sessions (add_session_to_memory) or the latest turn (add_events_to_memory); this stores each text
9
+ event in Recallix with its original time. search_memory recalls with Recallix and returns ADK MemoryEntry items.
10
+ When Recallix finds nothing that answers the query it returns no memories, so the agent is not handed
11
+ near-misses to guess from. No LLM is called to store or search memory.
12
+
13
+ Scope: Recallix user = the ADK user_id; Recallix agent = the ADK app_name, so each app reads back what it wrote.
14
+ """
15
+ from __future__ import annotations
16
+
17
+ import asyncio
18
+ from collections.abc import Mapping, Sequence
19
+ from datetime import datetime, timezone
20
+ from typing import TYPE_CHECKING, Any, Optional
21
+
22
+ from google.adk.memory.base_memory_service import BaseMemoryService, SearchMemoryResponse
23
+ from google.adk.memory.memory_entry import MemoryEntry
24
+ from google.genai import types
25
+ from recallix import Memory
26
+
27
+ if TYPE_CHECKING:
28
+ from google.adk.events.event import Event
29
+ from google.adk.sessions.session import Session
30
+
31
+
32
+ def _event_text(event: "Event") -> str:
33
+ content = getattr(event, "content", None)
34
+ parts = getattr(content, "parts", None) or []
35
+ return "\n".join(p.text for p in parts if getattr(p, "text", None) and not getattr(p, "thought", False)).strip()
36
+
37
+
38
+ def _iso(ts: Any) -> Optional[str]:
39
+ try:
40
+ return datetime.fromtimestamp(float(ts), tz=timezone.utc).isoformat()
41
+ except (TypeError, ValueError):
42
+ return None
43
+
44
+
45
+ class RecallixMemoryService(BaseMemoryService):
46
+ """
47
+ api_key: a Recallix key with role "service" (it acts for each ADK user_id).
48
+ base_url: the Recallix API.
49
+ mode: "cautious" | "balanced" | "helpful" for every search (None: the server's recall.mode).
50
+ limit: memories per search.
51
+ store_authors: which event authors to store: ("user",) by default, so memories are what users said. Pass None
52
+ to store every author, including the agent's own replies.
53
+ """
54
+
55
+ def __init__(self, api_key: str, base_url: str = "http://localhost:8000", *, mode: Optional[str] = None,
56
+ limit: int = 10, store_authors: Optional[Sequence[str]] = ("user",), timeout: float = 30.0,
57
+ client: Optional[Memory] = None):
58
+ self.memory = client or Memory(api_key=api_key, base_url=base_url, timeout=timeout)
59
+ self.mode = mode
60
+ self.limit = limit
61
+ self.store_authors = tuple(store_authors) if store_authors is not None else None
62
+
63
+ # ---------------------------------------------------------------- writing
64
+
65
+ def _store_events(self, app_name: str, user_id: str, events: Sequence["Event"],
66
+ custom_metadata: Optional[Mapping[str, object]] = None) -> None:
67
+ for event in events:
68
+ author = getattr(event, "author", None) or "user"
69
+ if self.store_authors is not None and author not in self.store_authors:
70
+ continue
71
+ text = _event_text(event)
72
+ if not text:
73
+ continue
74
+ metadata = {"speaker": "User" if author == "user" else author}
75
+ if custom_metadata:
76
+ metadata["adk"] = dict(custom_metadata)
77
+ # Recallix skips a message it already holds for this user and agent, so re-adding a session is safe
78
+ self.memory.store(text[:20000], agent_id=app_name, user_id=user_id, metadata=metadata,
79
+ timestamp=getattr(event, "timestamp", None))
80
+
81
+ async def add_session_to_memory(self, session: "Session") -> None:
82
+ await asyncio.to_thread(self._store_events, session.app_name, session.user_id, list(session.events or []))
83
+
84
+ async def add_events_to_memory(self, *, app_name: str, user_id: str, events: Sequence["Event"],
85
+ session_id: Optional[str] = None,
86
+ custom_metadata: Optional[Mapping[str, object]] = None) -> None:
87
+ await asyncio.to_thread(self._store_events, app_name, user_id, list(events), custom_metadata)
88
+
89
+ async def add_memory(self, *, app_name: str, user_id: str, memories: Sequence[MemoryEntry],
90
+ custom_metadata: Optional[Mapping[str, object]] = None) -> None:
91
+ def write():
92
+ for entry in memories:
93
+ text = "\n".join(p.text for p in (entry.content.parts or []) if getattr(p, "text", None)).strip()
94
+ if not text:
95
+ continue
96
+ ts = None
97
+ if entry.timestamp:
98
+ try:
99
+ ts = datetime.fromisoformat(entry.timestamp).timestamp()
100
+ except ValueError:
101
+ ts = None
102
+ self.memory.store(text[:20000], agent_id=app_name, user_id=user_id, timestamp=ts,
103
+ metadata={"speaker": entry.author or "User", **({"adk": dict(custom_metadata)} if custom_metadata else {})})
104
+ await asyncio.to_thread(write)
105
+
106
+ # ---------------------------------------------------------------- reading
107
+
108
+ async def search_memory(self, *, app_name: str, user_id: str, query: str) -> SearchMemoryResponse:
109
+ out = await asyncio.to_thread(lambda: self.memory.recall(query[:2000], limit=self.limit, agent_id=app_name,
110
+ user_id=user_id, mode=self.mode))
111
+ if out.get("status") != "CONSISTENT":
112
+ return SearchMemoryResponse(memories=[]) # Recallix found nothing that answers it: no near-misses
113
+ entries = []
114
+ computed = out.get("computed_answer")
115
+ if computed and computed.get("text"):
116
+ entries.append(MemoryEntry(
117
+ id="recallix-computed", author="recallix", timestamp=None,
118
+ content=types.Content(role="user", parts=[types.Part(text=f"Worked out from the memories below: {computed['text']}"
119
+ f" ({out.get('receipt', {}).get('computed', '')})")]),
120
+ custom_metadata={"computed_answer": computed}))
121
+ for m in (out.get("memories") or [])[: self.limit]:
122
+ speaker = ((m.get("metadata") or {}).get("client") or {}).get("speaker") if isinstance(m.get("metadata"), dict) else None
123
+ entries.append(MemoryEntry(
124
+ id=str(m.get("id")),
125
+ author="user" if speaker in (None, "User") else speaker,
126
+ timestamp=_iso(m.get("timestamp")),
127
+ content=types.Content(role="user", parts=[types.Part(text=m.get("content_resolved") or m.get("content", ""))]),
128
+ custom_metadata={"relevance": m.get("relevance"), "trust": m.get("trust"),
129
+ "receipt": m.get("receipt"), "recallix_recall_id": out.get("recall_id")}))
130
+ return SearchMemoryResponse(memories=entries)
131
+
132
+ async def delete_memory(self, *, app_name: str, user_id: str, memory_id: Optional[str] = None) -> None:
133
+ if memory_id is None or memory_id == "recallix-computed":
134
+ return
135
+ await asyncio.to_thread(self.memory.delete, int(memory_id), user_id)
@@ -0,0 +1,71 @@
1
+ """
2
+ Against a running Recallix server (skipped otherwise):
3
+ RECALLIX_URL=http://127.0.0.1:8000 RECALLIX_SERVICE_KEY=rx_... pytest integrations/google-adk/tests
4
+ """
5
+ import asyncio
6
+ import os
7
+ import time
8
+ import uuid
9
+
10
+ import pytest
11
+
12
+ URL, KEY = os.environ.get("RECALLIX_URL"), os.environ.get("RECALLIX_SERVICE_KEY")
13
+ pytestmark = pytest.mark.skipif(not (URL and KEY), reason="needs a running Recallix (RECALLIX_URL, RECALLIX_SERVICE_KEY)")
14
+
15
+
16
+ def run(coro):
17
+ return asyncio.run(coro)
18
+
19
+
20
+ def session_with(app, user, turns):
21
+ from google.adk.events.event import Event
22
+ from google.adk.sessions import InMemorySessionService
23
+ from google.genai import types
24
+ svc = InMemorySessionService()
25
+ s = run(svc.create_session(app_name=app, user_id=user))
26
+ for author, text, ts in turns:
27
+ run(svc.append_event(s, Event(author=author, timestamp=ts, invocation_id="i",
28
+ content=types.Content(role="user" if author == "user" else "model",
29
+ parts=[types.Part(text=text)]))))
30
+ return run(svc.get_session(app_name=app, user_id=user, session_id=s.id))
31
+
32
+
33
+ @pytest.fixture
34
+ def memory():
35
+ from recallix_adk import RecallixMemoryService
36
+ return RecallixMemoryService(api_key=KEY, base_url=URL)
37
+
38
+
39
+ def test_a_session_is_stored_with_its_dates_and_found_again(memory):
40
+ app, user = "adk-test", f"u-{uuid.uuid4().hex[:8]}"
41
+ month_ago = time.time() - 30 * 86400
42
+ s = session_with(app, user, [("user", "I moved to Pune in March for my new job.", month_ago),
43
+ ("assistant_agent", "Congratulations on the move!", month_ago + 5)])
44
+ run(memory.add_session_to_memory(s))
45
+ run(memory.add_session_to_memory(s)) # adding a session again stores nothing twice
46
+ out = run(memory.search_memory(app_name=app, user_id=user, query="Where did I move?"))
47
+ texts = [m.content.parts[0].text for m in out.memories]
48
+ assert any("Pune" in t for t in texts)
49
+ assert sum("Pune" in t for t in texts) == 1
50
+ assert not any("Congratulations" in t for t in texts) # only what the user said is stored by default
51
+ pune = next(m for m in out.memories if "Pune" in m.content.parts[0].text)
52
+ assert pune.timestamp.startswith(time.strftime("%Y-%m-%d", time.gmtime(month_ago)))
53
+
54
+
55
+ def test_no_record_means_no_memories_and_users_and_apps_are_separate(memory):
56
+ app, user = "adk-test", f"u-{uuid.uuid4().hex[:8]}"
57
+ run(memory.add_events_to_memory(app_name=app, user_id=user,
58
+ events=session_with(app, user, [("user", "I moved to Pune in March for my new job.", time.time())]).events))
59
+ assert run(memory.search_memory(app_name=app, user_id=f"other-{user}", query="Where did I move?")).memories == []
60
+ assert run(memory.search_memory(app_name="other-app", user_id=user, query="Where did I move?")).memories == []
61
+ assert run(memory.search_memory(app_name=app, user_id=user, query="What is my sister's name?")).memories == []
62
+
63
+
64
+ def test_delete_a_memory(memory):
65
+ app, user = "adk-test", f"u-{uuid.uuid4().hex[:8]}"
66
+ run(memory.add_events_to_memory(app_name=app, user_id=user,
67
+ events=session_with(app, user, [("user", "My locker code is 4417.", time.time())]).events))
68
+ found = run(memory.search_memory(app_name=app, user_id=user, query="What is my locker code?")).memories
69
+ assert found
70
+ run(memory.delete_memory(app_name=app, user_id=user, memory_id=found[0].id))
71
+ assert run(memory.search_memory(app_name=app, user_id=user, query="What is my locker code?")).memories == []