recallic 0.3.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.
recallic-0.3.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,81 @@
1
+ Metadata-Version: 2.4
2
+ Name: recallic
3
+ Version: 0.3.0
4
+ Summary: Python client and MCP server for Recallic, an LLM-free memory layer for AI agents
5
+ License: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/Recallic/Recallic
7
+ Project-URL: Source, https://github.com/Recallic/Recallic
8
+ Keywords: memory,ai-agents,llm,mcp,rag
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: requests>=2.33.0
13
+ Dynamic: license-file
14
+
15
+ # recallic (Python)
16
+
17
+ Client and MCP server for [Recallic](https://github.com/Recallic/Recallic): an LLM-free memory
18
+ layer for AI agents. Recallic runs on your own machine, needs no LLM calls, and declines
19
+ instead of guessing.
20
+
21
+ ```bash
22
+ pip install recallic
23
+ ```
24
+
25
+ You need a running Recallic server. The quickest way is
26
+ `docker compose up -d` in the [repository](https://github.com/Recallic/Recallic); see the quickstart there.
27
+
28
+ ```python
29
+ from recallic import Memory
30
+
31
+ mem = Memory(api_key="rx_...") # base_url defaults to http://localhost:8000
32
+ mem.store("I moved to Pune last month for a job at Infosys.")
33
+ out = mem.recall("Where do I live?")
34
+ print(out["status"], [m["content"] for m in out["memories"]]) # CONSISTENT ['I moved to Pune ...']
35
+ print(mem.recall("What is my brother's name?")["status"]) # ABSTAINED: nothing answers it
36
+ mem.used(out) # one line of feedback: Recallic learns from it on its own
37
+ ```
38
+
39
+ How readily recall answers is one option (server 0.2.5 or newer; default `"balanced"`):
40
+
41
+ ```python
42
+ mem.recall("Which came first, the Goa trip or the Pune workshop?", mode="helpful") # fewer refusals, computed_answer
43
+ mem.recall("What dose did the doctor prescribe?", mode="cautious") # checks every answer twice
44
+ ```
45
+
46
+ Storing a whole conversation at once (server 0.2.6 or newer; an older server gets one store per message):
47
+
48
+ ```python
49
+ mem.store_many(["I moved to Pune in March.", {"content": "Mira got married.", "timestamp": 1717200000}])
50
+ ```
51
+
52
+ Correcting a memory keeps when it was said; the memory gets a new id (server 0.2.7 or newer):
53
+
54
+ ```python
55
+ mem.update(memory_id, "I moved to Mumbai in March.")
56
+ ```
57
+
58
+ ## Changes
59
+
60
+ * **0.3.0**: renamed from `recallix` to **`recallic`**: `pip install recallic`, `from recallic import Memory`, `recallic-mcp`.
61
+ Nothing else changed; `RECALLIX_API_KEY` / `RECALLIX_URL` and the `recallix-mcp` command still work.
62
+ * **0.2.7**: `update(memory_id, content)` corrects a memory (`PUT /memory/{id}`); the MCP server has an `update_memory` tool.
63
+ * **0.2.6**: `store_many(items)` stores many messages in one request per 100 (`POST /memory/store_batch`).
64
+ * **0.2.5**: `recall(..., mode="cautious" | "balanced" | "helpful")`; `store(..., timestamp=...)` keeps when a message was originally said.
65
+ * **0.2.4**: `requests>=2.33.0`.
66
+
67
+ ## MCP (Claude Desktop, Cursor, any MCP client)
68
+
69
+ ```json
70
+ "mcpServers": {
71
+ "recallic": {
72
+ "command": "recallic-mcp",
73
+ "env": {"RECALLIC_API_KEY": "rx_...", "RECALLIC_AGENT_ID": "claude-desktop"}
74
+ }
75
+ }
76
+ ```
77
+
78
+ Environment: `RECALLIC_API_KEY` (required), `RECALLIC_URL` (default `http://localhost:8000`),
79
+ `RECALLIC_AGENT_ID` (default `mcp`).
80
+
81
+ License: Apache-2.0.
@@ -0,0 +1,67 @@
1
+ # recallic (Python)
2
+
3
+ Client and MCP server for [Recallic](https://github.com/Recallic/Recallic): an LLM-free memory
4
+ layer for AI agents. Recallic runs on your own machine, needs no LLM calls, and declines
5
+ instead of guessing.
6
+
7
+ ```bash
8
+ pip install recallic
9
+ ```
10
+
11
+ You need a running Recallic server. The quickest way is
12
+ `docker compose up -d` in the [repository](https://github.com/Recallic/Recallic); see the quickstart there.
13
+
14
+ ```python
15
+ from recallic import Memory
16
+
17
+ mem = Memory(api_key="rx_...") # base_url defaults to http://localhost:8000
18
+ mem.store("I moved to Pune last month for a job at Infosys.")
19
+ out = mem.recall("Where do I live?")
20
+ print(out["status"], [m["content"] for m in out["memories"]]) # CONSISTENT ['I moved to Pune ...']
21
+ print(mem.recall("What is my brother's name?")["status"]) # ABSTAINED: nothing answers it
22
+ mem.used(out) # one line of feedback: Recallic learns from it on its own
23
+ ```
24
+
25
+ How readily recall answers is one option (server 0.2.5 or newer; default `"balanced"`):
26
+
27
+ ```python
28
+ mem.recall("Which came first, the Goa trip or the Pune workshop?", mode="helpful") # fewer refusals, computed_answer
29
+ mem.recall("What dose did the doctor prescribe?", mode="cautious") # checks every answer twice
30
+ ```
31
+
32
+ Storing a whole conversation at once (server 0.2.6 or newer; an older server gets one store per message):
33
+
34
+ ```python
35
+ mem.store_many(["I moved to Pune in March.", {"content": "Mira got married.", "timestamp": 1717200000}])
36
+ ```
37
+
38
+ Correcting a memory keeps when it was said; the memory gets a new id (server 0.2.7 or newer):
39
+
40
+ ```python
41
+ mem.update(memory_id, "I moved to Mumbai in March.")
42
+ ```
43
+
44
+ ## Changes
45
+
46
+ * **0.3.0**: renamed from `recallix` to **`recallic`**: `pip install recallic`, `from recallic import Memory`, `recallic-mcp`.
47
+ Nothing else changed; `RECALLIX_API_KEY` / `RECALLIX_URL` and the `recallix-mcp` command still work.
48
+ * **0.2.7**: `update(memory_id, content)` corrects a memory (`PUT /memory/{id}`); the MCP server has an `update_memory` tool.
49
+ * **0.2.6**: `store_many(items)` stores many messages in one request per 100 (`POST /memory/store_batch`).
50
+ * **0.2.5**: `recall(..., mode="cautious" | "balanced" | "helpful")`; `store(..., timestamp=...)` keeps when a message was originally said.
51
+ * **0.2.4**: `requests>=2.33.0`.
52
+
53
+ ## MCP (Claude Desktop, Cursor, any MCP client)
54
+
55
+ ```json
56
+ "mcpServers": {
57
+ "recallic": {
58
+ "command": "recallic-mcp",
59
+ "env": {"RECALLIC_API_KEY": "rx_...", "RECALLIC_AGENT_ID": "claude-desktop"}
60
+ }
61
+ }
62
+ ```
63
+
64
+ Environment: `RECALLIC_API_KEY` (required), `RECALLIC_URL` (default `http://localhost:8000`),
65
+ `RECALLIC_AGENT_ID` (default `mcp`).
66
+
67
+ License: Apache-2.0.
@@ -0,0 +1,24 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "recallic"
7
+ version = "0.3.0"
8
+ description = "Python client and MCP server for Recallic, an LLM-free memory layer for AI agents"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ dependencies = ["requests>=2.33.0"]
12
+ license = { text = "Apache-2.0" }
13
+ keywords = ["memory", "ai-agents", "llm", "mcp", "rag"]
14
+
15
+ [project.urls]
16
+ Homepage = "https://github.com/Recallic/Recallic"
17
+ Source = "https://github.com/Recallic/Recallic"
18
+
19
+ [project.scripts]
20
+ recallic-mcp = "recallic.mcp_server:main"
21
+ recallix-mcp = "recallic.mcp_server:main" # name before the rename; old MCP client configs keep working
22
+
23
+ [tool.setuptools]
24
+ packages = ["recallic"]
@@ -0,0 +1,4 @@
1
+ from .client import MemoryClient, RecallicError
2
+ from .memory import Memory
3
+
4
+ __all__ = ["Memory", "MemoryClient", "RecallicError"]
@@ -0,0 +1,33 @@
1
+ from typing import Any, Dict, Optional
2
+
3
+ import requests
4
+
5
+
6
+ class RecallicError(RuntimeError):
7
+ def __init__(self, status: int, detail: str):
8
+ super().__init__(f"HTTP {status}: {detail}")
9
+ self.status = status
10
+ self.detail = detail
11
+
12
+
13
+ class MemoryClient:
14
+ def __init__(self, api_key: str, base_url: str = "http://localhost:8000", timeout: float = 30):
15
+ if not api_key:
16
+ raise ValueError("api_key is required")
17
+ self.base_url = base_url.rstrip("/")
18
+ self.timeout = timeout
19
+ self.session = requests.Session()
20
+ self.session.headers.update({"X-API-Key": api_key, "Content-Type": "application/json"})
21
+
22
+ def request(self, method: str, endpoint: str, data: Optional[Dict] = None,
23
+ params: Optional[Dict] = None) -> Dict[str, Any]:
24
+ """Returns the response's `data`. Raises RecallicError on HTTP errors."""
25
+ body = {k: v for k, v in data.items() if v is not None} if data else None
26
+ res = self.session.request(method, f"{self.base_url}{endpoint}", json=body, params=params, timeout=self.timeout)
27
+ if res.status_code >= 400:
28
+ try:
29
+ detail = res.json().get("detail", res.text)
30
+ except ValueError:
31
+ detail = res.text
32
+ raise RecallicError(res.status_code, str(detail))
33
+ return res.json().get("data")
@@ -0,0 +1,198 @@
1
+ """
2
+ Recallic as an MCP server: give Claude Desktop, Cursor, or any Model Context Protocol
3
+ client a memory that you own and that works with every model.
4
+
5
+ RECALLIC_API_KEY=rx_... python -m recallic.mcp_server
6
+
7
+ Environment:
8
+ RECALLIC_API_KEY your Recallic API key (required)
9
+ RECALLIC_URL API base URL (default http://localhost:8000)
10
+ RECALLIC_AGENT_ID agent name for memories written through this client (default "mcp")
11
+
12
+ Claude Desktop / Cursor configuration (mcpServers):
13
+
14
+ "recallic": {
15
+ "command": "python", "args": ["-m", "recallic.mcp_server"],
16
+ "env": {"RECALLIC_API_KEY": "rx_...", "RECALLIC_AGENT_ID": "claude-desktop"}
17
+ }
18
+
19
+ Memories written by one client with memory_type "shared" are visible to every client and
20
+ agent of the same user; "private" ones only to the agent that wrote them.
21
+
22
+ Implementation: JSON-RPC 2.0 over stdio, one message per line (the MCP stdio transport);
23
+ no dependencies beyond the SDK. Logs go to stderr — stdout carries only protocol messages.
24
+ """
25
+ import json
26
+ import os
27
+ import sys
28
+
29
+ SERVER_INFO = {"name": "recallic", "version": "1.0.0"}
30
+ SUPPORTED_VERSIONS = ("2025-06-18", "2025-03-26", "2024-11-05")
31
+
32
+ INSTRUCTIONS = (
33
+ "Recallic is the user's long-term memory. Call recall_memory before answering questions that may "
34
+ "depend on what the user told you earlier; if its status is ABSTAINED or NO_MATCH, say you don't know "
35
+ "rather than guessing. Call store_memory when the user shares a durable fact, preference or decision. "
36
+ "When a recalled memory was what answered the user, call confirm_answer. When the user corrects something "
37
+ "you recalled, call update_memory on that memory instead of storing a second, contradicting one."
38
+ )
39
+
40
+ TOOLS = [
41
+ {"name": "recall_memory",
42
+ "description": "Search the user's memory. Returns status (CONSISTENT = an answer was found, ABSTAINED = "
43
+ "nothing answers it, NO_MATCH = nothing related), the matching memories with the extracted "
44
+ "answer, and the reason for the decision.",
45
+ "inputSchema": {"type": "object", "properties": {
46
+ "query": {"type": "string", "description": "The question, in natural language."},
47
+ "limit": {"type": "integer", "minimum": 1, "maximum": 20, "default": 5},
48
+ "deep": {"type": "boolean", "default": False,
49
+ "description": "Read the candidates more carefully (slower). Use when the answer is spread over "
50
+ "several things the user said, e.g. 'what are all the places I've visited?'."}},
51
+ "required": ["query"]}},
52
+ {"name": "store_memory",
53
+ "description": "Remember something the user said: a fact, preference, plan or decision. Write it as the "
54
+ "user would say it, e.g. \"I'm allergic to peanuts.\"",
55
+ "inputSchema": {"type": "object", "properties": {
56
+ "content": {"type": "string"},
57
+ "memory_type": {"type": "string", "enum": ["shared", "private"], "default": "shared",
58
+ "description": "shared: visible to all of the user's agents; private: only this one."}},
59
+ "required": ["content"]}},
60
+ {"name": "confirm_answer",
61
+ "description": "Tell Recallic which recalled memories actually answered the question (improves ranking and "
62
+ "makes similar future questions find them).",
63
+ "inputSchema": {"type": "object", "properties": {
64
+ "recall_id": {"type": "string"},
65
+ "memory_ids": {"type": "array", "items": {"type": "integer"}}},
66
+ "required": ["recall_id", "memory_ids"]}},
67
+ {"name": "relevant_memories",
68
+ "description": "Given what the user just said, return memories worth keeping in mind even though they did not "
69
+ "ask (e.g. an allergy when they mention a restaurant), each with the reason.",
70
+ "inputSchema": {"type": "object", "properties": {"message": {"type": "string"}}, "required": ["message"]}},
71
+ {"name": "update_memory",
72
+ "description": "Correct a memory the user says is wrong or out of date (e.g. 'it was Mumbai, not Pune'): find "
73
+ "it with recall_memory, then replace its text. It keeps the date it was originally said; the old "
74
+ "version is deleted.",
75
+ "inputSchema": {"type": "object", "properties": {
76
+ "memory_id": {"type": "integer"},
77
+ "content": {"type": "string", "description": "The corrected memory, written as the user would say it."}},
78
+ "required": ["memory_id", "content"]}},
79
+ {"name": "forget_memory",
80
+ "description": "Delete a memory permanently (its vector, long-term copy and timeline entry too).",
81
+ "inputSchema": {"type": "object", "properties": {"memory_id": {"type": "integer"}},
82
+ "required": ["memory_id"]}},
83
+ {"name": "export_memories",
84
+ "description": "Export all of the user's memories in the open recallic-memory format.",
85
+ "inputSchema": {"type": "object", "properties": {}}},
86
+ ]
87
+
88
+
89
+ def _log(*args):
90
+ print(*args, file=sys.stderr, flush=True)
91
+
92
+
93
+ class RecallicMCP:
94
+ def __init__(self, memory, agent_id="mcp"):
95
+ self.memory, self.agent_id = memory, agent_id
96
+
97
+ # -- tools ------------------------------------------------------------
98
+ def _recall(self, query, limit=5, deep=False):
99
+ out = self.memory.recall(query, limit=int(limit), agent_id=self.agent_id, **({"deep": True} if deep else {}))
100
+ lines = [f"status: {out.get('status')}", f"reason: {(out.get('receipt') or {}).get('reason', '')}",
101
+ f"recall_id: {out.get('recall_id')}"]
102
+ for m in out.get("memories", []):
103
+ answer = f" | answer: {m['answer']}" if m.get("answer") else ""
104
+ lines.append(f"- [memory {m.get('id')}] {m.get('content')}{answer} (relevance {m.get('relevance')})")
105
+ return "\n".join(lines)
106
+
107
+ def _store(self, content, memory_type="shared"):
108
+ out = self.memory.store(content, agent_id=self.agent_id, memory_type=memory_type)
109
+ return f"{out.get('status')}: memory {out.get('memory_id')}"
110
+
111
+ def _confirm(self, recall_id, memory_ids):
112
+ out = self.memory.feedback(recall_id, [int(i) for i in memory_ids])
113
+ return f"confirmed ({out.get('labelled_candidates')} candidates labelled)"
114
+
115
+ def _relevant(self, message):
116
+ rows = self.memory.proactive(message, agent_id=self.agent_id)
117
+ return "\n".join(f"- [memory {r['memory_id']}] {r['content']} ({r['why']})" for r in rows) or "nothing relevant"
118
+
119
+ def _update(self, memory_id, content):
120
+ out = self.memory.update(int(memory_id), content)
121
+ return f"{out.get('status')}: memory {memory_id} is now memory {out.get('memory_id')}"
122
+
123
+ def _forget(self, memory_id):
124
+ self.memory.delete(int(memory_id))
125
+ return f"memory {memory_id} deleted"
126
+
127
+ def _export(self):
128
+ return json.dumps(self.memory.export(), ensure_ascii=False)
129
+
130
+ def call_tool(self, name, args):
131
+ handlers = {"recall_memory": self._recall, "store_memory": self._store, "confirm_answer": self._confirm,
132
+ "forget_memory": self._forget, "update_memory": self._update, "relevant_memories": self._relevant, "export_memories": self._export}
133
+ if name not in handlers:
134
+ raise KeyError(name)
135
+ return handlers[name](**(args or {}))
136
+
137
+ # -- protocol ---------------------------------------------------------
138
+ def handle(self, msg):
139
+ """Response dict for a request, or None for a notification."""
140
+ method, mid, params = msg.get("method"), msg.get("id"), msg.get("params") or {}
141
+ if mid is None: # notification (e.g. notifications/initialized): no reply
142
+ return None
143
+ try:
144
+ if method == "initialize":
145
+ asked = params.get("protocolVersion")
146
+ version = asked if asked in SUPPORTED_VERSIONS else SUPPORTED_VERSIONS[0]
147
+ result = {"protocolVersion": version, "capabilities": {"tools": {"listChanged": False}},
148
+ "serverInfo": SERVER_INFO, "instructions": INSTRUCTIONS}
149
+ elif method == "ping":
150
+ result = {}
151
+ elif method == "tools/list":
152
+ result = {"tools": TOOLS}
153
+ elif method == "tools/call":
154
+ try:
155
+ text = self.call_tool(params.get("name"), params.get("arguments"))
156
+ result = {"content": [{"type": "text", "text": text}], "isError": False}
157
+ except KeyError:
158
+ return {"jsonrpc": "2.0", "id": mid, "error": {"code": -32602, "message": f"unknown tool {params.get('name')!r}"}}
159
+ except Exception as e: # tool failures are reported to the model, not as protocol errors
160
+ result = {"content": [{"type": "text", "text": f"Recallic error: {e}"}], "isError": True}
161
+ else:
162
+ return {"jsonrpc": "2.0", "id": mid, "error": {"code": -32601, "message": f"method not found: {method}"}}
163
+ except Exception as e:
164
+ return {"jsonrpc": "2.0", "id": mid, "error": {"code": -32603, "message": str(e)}}
165
+ return {"jsonrpc": "2.0", "id": mid, "result": result}
166
+
167
+ def serve(self, stdin=sys.stdin, stdout=sys.stdout):
168
+ for line in stdin:
169
+ line = line.strip()
170
+ if not line:
171
+ continue
172
+ try:
173
+ msg = json.loads(line)
174
+ except ValueError:
175
+ stdout.write(json.dumps({"jsonrpc": "2.0", "id": None,
176
+ "error": {"code": -32700, "message": "parse error"}}) + "\n")
177
+ stdout.flush()
178
+ continue
179
+ reply = self.handle(msg)
180
+ if reply is not None:
181
+ stdout.write(json.dumps(reply, ensure_ascii=False) + "\n")
182
+ stdout.flush()
183
+
184
+
185
+ def main():
186
+ from .memory import Memory
187
+ key = (os.environ.get("RECALLIC_API_KEY") or os.environ.get("RECALLIX_API_KEY"))
188
+ if not key:
189
+ _log("RECALLIC_API_KEY is not set")
190
+ return 1
191
+ memory = Memory(api_key=key, base_url=(os.environ.get("RECALLIC_URL") or os.environ.get("RECALLIX_URL") or "http://localhost:8000"))
192
+ _log(f"recallic MCP server ready ({os.environ.get('RECALLIC_URL') or os.environ.get('RECALLIX_URL') or 'http://localhost:8000'})")
193
+ RecallicMCP(memory, (os.environ.get("RECALLIC_AGENT_ID") or os.environ.get("RECALLIX_AGENT_ID") or "mcp")).serve()
194
+ return 0
195
+
196
+
197
+ if __name__ == "__main__":
198
+ sys.exit(main())
@@ -0,0 +1,160 @@
1
+ from typing import Any, Dict, List, Optional
2
+
3
+ from .client import MemoryClient, RecallicError
4
+
5
+
6
+ class Memory:
7
+ """
8
+ Recallic client.
9
+
10
+ mem = Memory(api_key=os.environ["RECALLIC_API_KEY"])
11
+ mem.store("I live in Pune.")
12
+ hits = mem.recall("Where do I live?")
13
+
14
+ `user_id` may only be passed with a service/admin key (multi-user apps);
15
+ a user key always acts as its own user.
16
+ """
17
+
18
+ def __init__(self, api_key: str, base_url: str = "http://localhost:8000", timeout: float = 30):
19
+ self.client = MemoryClient(api_key, base_url, timeout)
20
+
21
+ def store(self, content: str, agent_id: str = "default_agent", memory_type: str = "private",
22
+ user_id: Optional[str] = None, metadata: Optional[Dict] = None,
23
+ timestamp: Optional[float] = None) -> Dict[str, Any]:
24
+ """
25
+ memory_type: "private" (only this agent) or "shared" (all of the user's agents).
26
+ timestamp: when the message was originally said (Unix seconds; server 0.2.5+). Default: now.
27
+ """
28
+ return self.client.request("POST", "/memory/store", data={
29
+ "content": content, "agent_id": agent_id, "memory_type": memory_type,
30
+ "user_id": user_id, "metadata": metadata, "timestamp": timestamp})
31
+
32
+ BATCH_SIZE = 100 # server api.max_batch_items
33
+
34
+ def store_many(self, items: List[Any], agent_id: str = "default_agent", memory_type: str = "private",
35
+ user_id: Optional[str] = None) -> Dict[str, Any]:
36
+ """
37
+ Stores several messages in as few requests as possible (server 0.2.6+; an older server gets one store
38
+ per message). Each item is a string or {"content", "timestamp"?, "metadata"?, "memory_type"?}.
39
+ Same result as storing them one by one in time order; repeats are skipped.
40
+ Returns {"stored", "skipped_duplicates", "results"}, with `results` in the order of `items`.
41
+ """
42
+ rows = [{"content": it} if isinstance(it, str) else dict(it) for it in items]
43
+ results: List[Dict[str, Any]] = []
44
+ for start in range(0, len(rows), self.BATCH_SIZE):
45
+ chunk = rows[start:start + self.BATCH_SIZE]
46
+ try:
47
+ out = self.client.request("POST", "/memory/store_batch", data={
48
+ "items": chunk, "agent_id": agent_id, "memory_type": memory_type, "user_id": user_id})
49
+ results.extend(out["results"])
50
+ except RecallicError as e:
51
+ if e.status not in (404, 405):
52
+ raise
53
+ for row in sorted(chunk, key=lambda r: (r.get("timestamp") is None, r.get("timestamp") or 0)):
54
+ row["_result"] = self.store(row["content"], agent_id=agent_id,
55
+ memory_type=row.get("memory_type") or memory_type, user_id=user_id,
56
+ metadata=row.get("metadata"), timestamp=row.get("timestamp"))
57
+ results.extend(row.pop("_result") for row in chunk)
58
+ stored = sum(r.get("status") == "stored" for r in results)
59
+ return {"stored": stored, "skipped_duplicates": len(results) - stored, "results": results}
60
+
61
+ def recall(self, query: str, limit: int = 10, agent_id: str = "default_agent",
62
+ user_id: Optional[str] = None, deep: Optional[bool] = None,
63
+ keep_on_decline: Optional[bool] = None, mode: Optional[str] = None) -> Dict[str, Any]:
64
+ """
65
+ mode: how readily recall answers. "cautious" verifies every answer (more "I don't know", fewer wrong
66
+ answers), "balanced" is the default, "helpful" answers more counting / ordering / time questions (fewer
67
+ refusals). Default: server setting (recall.mode).
68
+
69
+ deep=True re-reads the candidates with a re-ranker: better when the answer is spread over
70
+ several memories ("what activities has she done with her kids?"), but slower. Default: server setting.
71
+
72
+ keep_on_decline=True: when recall declines (status "ABSTAINED"), still return the results it
73
+ found, as low-confidence ("answer" stays None). Check out["status"] before using them as an
74
+ answer. Default: server setting (off).
75
+ """
76
+ data = {"query": query, "limit": limit, "agent_id": agent_id, "user_id": user_id}
77
+ if deep is not None:
78
+ data["deep"] = deep
79
+ if keep_on_decline is not None:
80
+ data["keep_on_decline"] = keep_on_decline
81
+ if mode is not None:
82
+ data["mode"] = mode
83
+ return self.client.request("POST", "/memory/recall", data=data)
84
+
85
+ def feedback(self, recall_id: str, relevant_memory_ids: List[int], user_id: Optional[str] = None) -> Dict[str, Any]:
86
+ """Tell Recallic which recalled memories were useful (trains the ranker)."""
87
+ return self.client.request("POST", "/memory/feedback", data={
88
+ "recall_id": recall_id, "relevant_memory_ids": relevant_memory_ids, "user_id": user_id})
89
+
90
+ def used(self, recall: Dict[str, Any], *memories: Any, user_id: Optional[str] = None) -> Dict[str, Any]:
91
+ """
92
+ One-line feedback after a recall, so Recallic learns from use:
93
+
94
+ out = mem.recall("Where do I live?")
95
+ mem.used(out) # the first memory answered it
96
+ mem.used(out, out["memories"][2]) # or name the memories (or ids) your app actually used
97
+
98
+ Recallic refits its ranking from this on a schedule and keeps a new fit only if it is better.
99
+ """
100
+ chosen = memories or recall.get("memories", [])[:1]
101
+ ids = [int(m["id"] if isinstance(m, dict) else m) for m in chosen]
102
+ return self.feedback(recall["recall_id"], ids, user_id=user_id)
103
+
104
+ def none_used(self, recall: Dict[str, Any], user_id: Optional[str] = None) -> Dict[str, Any]:
105
+ """Feedback that nothing in this recall was useful."""
106
+ return self.feedback(recall["recall_id"], [], user_id=user_id)
107
+
108
+ def proactive(self, message: str, agent_id: str = "default_agent", limit: int = 5,
109
+ user_id: Optional[str] = None) -> List[Dict[str, Any]]:
110
+ """Memories worth keeping in mind for a new message (no question needed), each with the reason."""
111
+ return self.client.request("POST", "/memory/proactive", data={
112
+ "message": message, "agent_id": agent_id, "limit": limit, "user_id": user_id})
113
+
114
+ def export(self, user_id: Optional[str] = None) -> Dict[str, Any]:
115
+ """All memories in the open "recallic-memory" format (portable to another Recallic)."""
116
+ return self.client.request("GET", "/memory/export", params=_params(user_id=user_id))
117
+
118
+ def import_memories(self, data: Any, format: str = "recallic", agent_id: str = "default_agent",
119
+ memory_type: str = "private", user_id: Optional[str] = None) -> Dict[str, Any]:
120
+ """Import a Recallic export, a Mem0 export (format="mem0") or text, one memory per line (format="text")."""
121
+ return self.client.request("POST", "/memory/import", data={
122
+ "format": format, "data": data, "agent_id": agent_id, "memory_type": memory_type, "user_id": user_id})
123
+
124
+ def update(self, memory_id: int, content: str, user_id: Optional[str] = None, metadata: Optional[Dict] = None,
125
+ timestamp: Optional[float] = None) -> Dict[str, Any]:
126
+ """
127
+ Replaces a memory's text (server 0.2.7+). It is re-processed like a new store with its original time
128
+ (or `timestamp`) and metadata (or `metadata`); the old version is deleted with a receipt.
129
+ Returns {"status": "edited" | "unchanged" | "merged", "memory_id" (new), "previous_memory_id", ...}.
130
+ """
131
+ return self.client.request("PUT", f"/memory/{memory_id}", data={
132
+ "content": content, "user_id": user_id, "metadata": metadata, "timestamp": timestamp})
133
+
134
+ def delete(self, memory_id: int, user_id: Optional[str] = None) -> Dict[str, Any]:
135
+ return self.client.request("DELETE", f"/memory/{memory_id}", params={"user_id": user_id} if user_id else None)
136
+
137
+ def timeline(self, limit: int = 50, user_id: Optional[str] = None) -> Dict[str, Any]:
138
+ return self.client.request("GET", "/memory/timeline", params=_params(limit=limit, user_id=user_id))
139
+
140
+ def insights(self, user_id: Optional[str] = None) -> Dict[str, Any]:
141
+ return self.client.request("GET", "/memory/insights", params=_params(user_id=user_id))
142
+
143
+ def world_state(self, user_id: Optional[str] = None) -> Dict[str, Any]:
144
+ return self.client.request("GET", "/memory/world-state", params=_params(user_id=user_id))
145
+
146
+ def prediction(self, user_id: Optional[str] = None) -> Dict[str, Any]:
147
+ return self.client.request("GET", "/memory/prediction", params=_params(user_id=user_id))
148
+
149
+ def plan(self, user_id: Optional[str] = None) -> Dict[str, Any]:
150
+ return self.client.request("GET", "/memory/plan", params=_params(user_id=user_id))
151
+
152
+ def profile(self, user_id: Optional[str] = None) -> Dict[str, Any]:
153
+ return self.client.request("GET", "/memory/profile", params=_params(user_id=user_id))
154
+
155
+ def stats(self, user_id: Optional[str] = None) -> Dict[str, Any]:
156
+ return self.client.request("GET", "/memory/stats", params=_params(user_id=user_id))
157
+
158
+
159
+ def _params(**kw):
160
+ return {k: v for k, v in kw.items() if v is not None} or None
@@ -0,0 +1,81 @@
1
+ Metadata-Version: 2.4
2
+ Name: recallic
3
+ Version: 0.3.0
4
+ Summary: Python client and MCP server for Recallic, an LLM-free memory layer for AI agents
5
+ License: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/Recallic/Recallic
7
+ Project-URL: Source, https://github.com/Recallic/Recallic
8
+ Keywords: memory,ai-agents,llm,mcp,rag
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: requests>=2.33.0
13
+ Dynamic: license-file
14
+
15
+ # recallic (Python)
16
+
17
+ Client and MCP server for [Recallic](https://github.com/Recallic/Recallic): an LLM-free memory
18
+ layer for AI agents. Recallic runs on your own machine, needs no LLM calls, and declines
19
+ instead of guessing.
20
+
21
+ ```bash
22
+ pip install recallic
23
+ ```
24
+
25
+ You need a running Recallic server. The quickest way is
26
+ `docker compose up -d` in the [repository](https://github.com/Recallic/Recallic); see the quickstart there.
27
+
28
+ ```python
29
+ from recallic import Memory
30
+
31
+ mem = Memory(api_key="rx_...") # base_url defaults to http://localhost:8000
32
+ mem.store("I moved to Pune last month for a job at Infosys.")
33
+ out = mem.recall("Where do I live?")
34
+ print(out["status"], [m["content"] for m in out["memories"]]) # CONSISTENT ['I moved to Pune ...']
35
+ print(mem.recall("What is my brother's name?")["status"]) # ABSTAINED: nothing answers it
36
+ mem.used(out) # one line of feedback: Recallic learns from it on its own
37
+ ```
38
+
39
+ How readily recall answers is one option (server 0.2.5 or newer; default `"balanced"`):
40
+
41
+ ```python
42
+ mem.recall("Which came first, the Goa trip or the Pune workshop?", mode="helpful") # fewer refusals, computed_answer
43
+ mem.recall("What dose did the doctor prescribe?", mode="cautious") # checks every answer twice
44
+ ```
45
+
46
+ Storing a whole conversation at once (server 0.2.6 or newer; an older server gets one store per message):
47
+
48
+ ```python
49
+ mem.store_many(["I moved to Pune in March.", {"content": "Mira got married.", "timestamp": 1717200000}])
50
+ ```
51
+
52
+ Correcting a memory keeps when it was said; the memory gets a new id (server 0.2.7 or newer):
53
+
54
+ ```python
55
+ mem.update(memory_id, "I moved to Mumbai in March.")
56
+ ```
57
+
58
+ ## Changes
59
+
60
+ * **0.3.0**: renamed from `recallix` to **`recallic`**: `pip install recallic`, `from recallic import Memory`, `recallic-mcp`.
61
+ Nothing else changed; `RECALLIX_API_KEY` / `RECALLIX_URL` and the `recallix-mcp` command still work.
62
+ * **0.2.7**: `update(memory_id, content)` corrects a memory (`PUT /memory/{id}`); the MCP server has an `update_memory` tool.
63
+ * **0.2.6**: `store_many(items)` stores many messages in one request per 100 (`POST /memory/store_batch`).
64
+ * **0.2.5**: `recall(..., mode="cautious" | "balanced" | "helpful")`; `store(..., timestamp=...)` keeps when a message was originally said.
65
+ * **0.2.4**: `requests>=2.33.0`.
66
+
67
+ ## MCP (Claude Desktop, Cursor, any MCP client)
68
+
69
+ ```json
70
+ "mcpServers": {
71
+ "recallic": {
72
+ "command": "recallic-mcp",
73
+ "env": {"RECALLIC_API_KEY": "rx_...", "RECALLIC_AGENT_ID": "claude-desktop"}
74
+ }
75
+ }
76
+ ```
77
+
78
+ Environment: `RECALLIC_API_KEY` (required), `RECALLIC_URL` (default `http://localhost:8000`),
79
+ `RECALLIC_AGENT_ID` (default `mcp`).
80
+
81
+ License: Apache-2.0.
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ recallic/__init__.py
5
+ recallic/client.py
6
+ recallic/mcp_server.py
7
+ recallic/memory.py
8
+ recallic.egg-info/PKG-INFO
9
+ recallic.egg-info/SOURCES.txt
10
+ recallic.egg-info/dependency_links.txt
11
+ recallic.egg-info/entry_points.txt
12
+ recallic.egg-info/requires.txt
13
+ recallic.egg-info/top_level.txt
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ recallic-mcp = recallic.mcp_server:main
3
+ recallix-mcp = recallic.mcp_server:main
@@ -0,0 +1 @@
1
+ requests>=2.33.0
@@ -0,0 +1 @@
1
+ recallic
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+