mnemo-ai 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.
- mnemo_ai-0.1.0/LICENSE +191 -0
- mnemo_ai-0.1.0/PKG-INFO +165 -0
- mnemo_ai-0.1.0/README.md +147 -0
- mnemo_ai-0.1.0/mnemo_client.py +504 -0
- mnemo_ai-0.1.0/pyproject.toml +30 -0
- mnemo_ai-0.1.0/uv.lock +91 -0
mnemo_ai-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2026 Inforge-ai
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
mnemo_ai-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mnemo-ai
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lightweight async Python client for the Mnemo API
|
|
5
|
+
Author: Inforge-ai
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Typing :: Typed
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Requires-Dist: httpx>=0.26.0
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# mnemo-ai
|
|
20
|
+
|
|
21
|
+
Lightweight async Python client for the Mnemo API — persistent memory for AI agents.
|
|
22
|
+
|
|
23
|
+
## Requirements
|
|
24
|
+
|
|
25
|
+
- Python >= 3.12
|
|
26
|
+
- `httpx >= 0.26.0`
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install mnemo-ai
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Or with [uv](https://github.com/astral-sh/uv):
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
uv add mnemo-ai
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
### Async (recommended)
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from mnemo_client import MnemoClient
|
|
46
|
+
|
|
47
|
+
async with MnemoClient(api_key="your-key") as client:
|
|
48
|
+
# Register an agent
|
|
49
|
+
agent = await client.register_agent(
|
|
50
|
+
"my-agent",
|
|
51
|
+
persona="python developer",
|
|
52
|
+
domain_tags=["python"],
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# Store a memory
|
|
56
|
+
result = await client.remember(
|
|
57
|
+
agent_id=agent["id"],
|
|
58
|
+
text="pandas.read_csv silently coerces mixed-type columns. "
|
|
59
|
+
"I discovered this processing client_data.csv. "
|
|
60
|
+
"From now on I should always specify dtype explicitly.",
|
|
61
|
+
domain_tags=["python", "pandas"],
|
|
62
|
+
)
|
|
63
|
+
# result: {"atoms_created": 3, "edges_created": 2, "duplicates_merged": 0}
|
|
64
|
+
|
|
65
|
+
# Retrieve relevant memories
|
|
66
|
+
results = await client.recall(
|
|
67
|
+
agent_id=agent["id"],
|
|
68
|
+
query="loading CSV files with pandas",
|
|
69
|
+
)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Sync
|
|
73
|
+
|
|
74
|
+
For non-async contexts (scripts, sync agent loops, WebSocket handlers):
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from mnemo_client import MnemoClientSync
|
|
78
|
+
|
|
79
|
+
client = MnemoClientSync(api_key="your-key", agent_id="your-uuid")
|
|
80
|
+
|
|
81
|
+
client.remember("pandas.read_csv coerces mixed types")
|
|
82
|
+
results = client.recall("loading CSV files")
|
|
83
|
+
stats = client.stats()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`MnemoClientSync` safely handles the case where an event loop is already running by offloading work to a worker thread.
|
|
87
|
+
|
|
88
|
+
## API Reference
|
|
89
|
+
|
|
90
|
+
### `MnemoClient(api_key, base_url)`
|
|
91
|
+
|
|
92
|
+
Async client. Use as an async context manager or call `.close()` manually.
|
|
93
|
+
|
|
94
|
+
#### Memory
|
|
95
|
+
|
|
96
|
+
| Method | Description |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `remember(agent_id, text, domain_tags=None)` | Store a memory. The server decomposes it into typed atoms and links them. Returns `RememberResult`. |
|
|
99
|
+
| `recall(agent_id, query, ...)` | Semantic search over stored memories. Returns `RecallResult`. |
|
|
100
|
+
|
|
101
|
+
#### Agent Management
|
|
102
|
+
|
|
103
|
+
| Method | Description |
|
|
104
|
+
|---|---|
|
|
105
|
+
| `register_agent(name, persona=None, domain_tags=None, metadata=None)` | Create a new agent. |
|
|
106
|
+
| `me()` | Return info for the authenticated agent. |
|
|
107
|
+
| `find_agent_by_name(name)` | Find active agents by exact name. |
|
|
108
|
+
| `get_agent(agent_id)` | Get agent by ID. |
|
|
109
|
+
| `stats(agent_id)` | Return memory statistics for an agent. |
|
|
110
|
+
| `depart(agent_id)` | Deactivate an agent and cascade-revoke all granted capabilities. |
|
|
111
|
+
|
|
112
|
+
#### Atoms (Power-User)
|
|
113
|
+
|
|
114
|
+
| Method | Description |
|
|
115
|
+
|---|---|
|
|
116
|
+
| `store_atom(agent_id, atom_type, text_content, ...)` | Explicitly create a single memory atom. |
|
|
117
|
+
| `get_atom(agent_id, atom_id)` | Fetch a single atom. |
|
|
118
|
+
| `delete_atom(agent_id, atom_id)` | Delete an atom. |
|
|
119
|
+
| `link(agent_id, source_id, target_id, edge_type, weight=1.0)` | Create a typed edge between two atoms. |
|
|
120
|
+
|
|
121
|
+
#### Views & Skills
|
|
122
|
+
|
|
123
|
+
| Method | Description |
|
|
124
|
+
|---|---|
|
|
125
|
+
| `create_view(agent_id, name, atom_filter, description=None)` | Create a filtered view over an agent's atoms. |
|
|
126
|
+
| `list_views(agent_id)` | List all views for an agent. |
|
|
127
|
+
| `export_skill(agent_id, view_id)` | Export a view as a portable skill bundle. |
|
|
128
|
+
|
|
129
|
+
#### Capability Sharing
|
|
130
|
+
|
|
131
|
+
| Method | Description |
|
|
132
|
+
|---|---|
|
|
133
|
+
| `grant(agent_id, view_id, grantee_id, permissions=None, expires_at=None)` | Grant another agent access to a view. |
|
|
134
|
+
| `revoke(capability_id)` | Revoke a previously granted capability. |
|
|
135
|
+
| `list_shared_views(agent_id)` | List views shared with this agent. |
|
|
136
|
+
| `recall_shared(agent_id, view_id, query, ...)` | Recall memories scoped to a shared view. |
|
|
137
|
+
|
|
138
|
+
#### Other
|
|
139
|
+
|
|
140
|
+
| Method | Description |
|
|
141
|
+
|---|---|
|
|
142
|
+
| `health()` | Check API health. |
|
|
143
|
+
|
|
144
|
+
### `MnemoClientSync(api_key, agent_id, base_url)`
|
|
145
|
+
|
|
146
|
+
Synchronous wrapper. Exposes `remember`, `recall`, and `stats` with the same signatures as the async client.
|
|
147
|
+
|
|
148
|
+
## Response Types
|
|
149
|
+
|
|
150
|
+
- **`RememberResult`** — `atoms_created`, `edges_created`, `duplicates_merged`
|
|
151
|
+
- **`RecallResult`** — `atoms`, `expanded_atoms`, `total_retrieved`
|
|
152
|
+
- **`AgentStats`** — `total_atoms`, `active_atoms`, `atoms_by_type`, `total_edges`, `avg_effective_confidence`, `active_views`, `granted_capabilities`, `received_capabilities`
|
|
153
|
+
|
|
154
|
+
## Exceptions
|
|
155
|
+
|
|
156
|
+
| Exception | Raised when |
|
|
157
|
+
|---|---|
|
|
158
|
+
| `MnemoAuthError` | 401 or 403 response |
|
|
159
|
+
| `MnemoNotFoundError` | 404 response |
|
|
160
|
+
| `MnemoServerError` | 5xx response |
|
|
161
|
+
| `MnemoError` | Base class for all Mnemo errors |
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
Apache 2.0 — see [LICENSE](LICENSE) for details.
|
mnemo_ai-0.1.0/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# mnemo-ai
|
|
2
|
+
|
|
3
|
+
Lightweight async Python client for the Mnemo API — persistent memory for AI agents.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Python >= 3.12
|
|
8
|
+
- `httpx >= 0.26.0`
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install mnemo-ai
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or with [uv](https://github.com/astral-sh/uv):
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
uv add mnemo-ai
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
### Async (recommended)
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from mnemo_client import MnemoClient
|
|
28
|
+
|
|
29
|
+
async with MnemoClient(api_key="your-key") as client:
|
|
30
|
+
# Register an agent
|
|
31
|
+
agent = await client.register_agent(
|
|
32
|
+
"my-agent",
|
|
33
|
+
persona="python developer",
|
|
34
|
+
domain_tags=["python"],
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
# Store a memory
|
|
38
|
+
result = await client.remember(
|
|
39
|
+
agent_id=agent["id"],
|
|
40
|
+
text="pandas.read_csv silently coerces mixed-type columns. "
|
|
41
|
+
"I discovered this processing client_data.csv. "
|
|
42
|
+
"From now on I should always specify dtype explicitly.",
|
|
43
|
+
domain_tags=["python", "pandas"],
|
|
44
|
+
)
|
|
45
|
+
# result: {"atoms_created": 3, "edges_created": 2, "duplicates_merged": 0}
|
|
46
|
+
|
|
47
|
+
# Retrieve relevant memories
|
|
48
|
+
results = await client.recall(
|
|
49
|
+
agent_id=agent["id"],
|
|
50
|
+
query="loading CSV files with pandas",
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Sync
|
|
55
|
+
|
|
56
|
+
For non-async contexts (scripts, sync agent loops, WebSocket handlers):
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from mnemo_client import MnemoClientSync
|
|
60
|
+
|
|
61
|
+
client = MnemoClientSync(api_key="your-key", agent_id="your-uuid")
|
|
62
|
+
|
|
63
|
+
client.remember("pandas.read_csv coerces mixed types")
|
|
64
|
+
results = client.recall("loading CSV files")
|
|
65
|
+
stats = client.stats()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`MnemoClientSync` safely handles the case where an event loop is already running by offloading work to a worker thread.
|
|
69
|
+
|
|
70
|
+
## API Reference
|
|
71
|
+
|
|
72
|
+
### `MnemoClient(api_key, base_url)`
|
|
73
|
+
|
|
74
|
+
Async client. Use as an async context manager or call `.close()` manually.
|
|
75
|
+
|
|
76
|
+
#### Memory
|
|
77
|
+
|
|
78
|
+
| Method | Description |
|
|
79
|
+
|---|---|
|
|
80
|
+
| `remember(agent_id, text, domain_tags=None)` | Store a memory. The server decomposes it into typed atoms and links them. Returns `RememberResult`. |
|
|
81
|
+
| `recall(agent_id, query, ...)` | Semantic search over stored memories. Returns `RecallResult`. |
|
|
82
|
+
|
|
83
|
+
#### Agent Management
|
|
84
|
+
|
|
85
|
+
| Method | Description |
|
|
86
|
+
|---|---|
|
|
87
|
+
| `register_agent(name, persona=None, domain_tags=None, metadata=None)` | Create a new agent. |
|
|
88
|
+
| `me()` | Return info for the authenticated agent. |
|
|
89
|
+
| `find_agent_by_name(name)` | Find active agents by exact name. |
|
|
90
|
+
| `get_agent(agent_id)` | Get agent by ID. |
|
|
91
|
+
| `stats(agent_id)` | Return memory statistics for an agent. |
|
|
92
|
+
| `depart(agent_id)` | Deactivate an agent and cascade-revoke all granted capabilities. |
|
|
93
|
+
|
|
94
|
+
#### Atoms (Power-User)
|
|
95
|
+
|
|
96
|
+
| Method | Description |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `store_atom(agent_id, atom_type, text_content, ...)` | Explicitly create a single memory atom. |
|
|
99
|
+
| `get_atom(agent_id, atom_id)` | Fetch a single atom. |
|
|
100
|
+
| `delete_atom(agent_id, atom_id)` | Delete an atom. |
|
|
101
|
+
| `link(agent_id, source_id, target_id, edge_type, weight=1.0)` | Create a typed edge between two atoms. |
|
|
102
|
+
|
|
103
|
+
#### Views & Skills
|
|
104
|
+
|
|
105
|
+
| Method | Description |
|
|
106
|
+
|---|---|
|
|
107
|
+
| `create_view(agent_id, name, atom_filter, description=None)` | Create a filtered view over an agent's atoms. |
|
|
108
|
+
| `list_views(agent_id)` | List all views for an agent. |
|
|
109
|
+
| `export_skill(agent_id, view_id)` | Export a view as a portable skill bundle. |
|
|
110
|
+
|
|
111
|
+
#### Capability Sharing
|
|
112
|
+
|
|
113
|
+
| Method | Description |
|
|
114
|
+
|---|---|
|
|
115
|
+
| `grant(agent_id, view_id, grantee_id, permissions=None, expires_at=None)` | Grant another agent access to a view. |
|
|
116
|
+
| `revoke(capability_id)` | Revoke a previously granted capability. |
|
|
117
|
+
| `list_shared_views(agent_id)` | List views shared with this agent. |
|
|
118
|
+
| `recall_shared(agent_id, view_id, query, ...)` | Recall memories scoped to a shared view. |
|
|
119
|
+
|
|
120
|
+
#### Other
|
|
121
|
+
|
|
122
|
+
| Method | Description |
|
|
123
|
+
|---|---|
|
|
124
|
+
| `health()` | Check API health. |
|
|
125
|
+
|
|
126
|
+
### `MnemoClientSync(api_key, agent_id, base_url)`
|
|
127
|
+
|
|
128
|
+
Synchronous wrapper. Exposes `remember`, `recall`, and `stats` with the same signatures as the async client.
|
|
129
|
+
|
|
130
|
+
## Response Types
|
|
131
|
+
|
|
132
|
+
- **`RememberResult`** — `atoms_created`, `edges_created`, `duplicates_merged`
|
|
133
|
+
- **`RecallResult`** — `atoms`, `expanded_atoms`, `total_retrieved`
|
|
134
|
+
- **`AgentStats`** — `total_atoms`, `active_atoms`, `atoms_by_type`, `total_edges`, `avg_effective_confidence`, `active_views`, `granted_capabilities`, `received_capabilities`
|
|
135
|
+
|
|
136
|
+
## Exceptions
|
|
137
|
+
|
|
138
|
+
| Exception | Raised when |
|
|
139
|
+
|---|---|
|
|
140
|
+
| `MnemoAuthError` | 401 or 403 response |
|
|
141
|
+
| `MnemoNotFoundError` | 404 response |
|
|
142
|
+
| `MnemoServerError` | 5xx response |
|
|
143
|
+
| `MnemoError` | Base class for all Mnemo errors |
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
Apache 2.0 — see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Lightweight async Python client for the Mnemo API.
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
async with MnemoClient(api_key="your-key") as client:
|
|
6
|
+
agent = await client.register_agent("my-agent",
|
|
7
|
+
persona="python developer", domain_tags=["python"])
|
|
8
|
+
|
|
9
|
+
result = await client.remember(
|
|
10
|
+
agent_id=agent["id"],
|
|
11
|
+
text="pandas.read_csv silently coerces mixed-type columns. "
|
|
12
|
+
"I discovered this processing client_data.csv. "
|
|
13
|
+
"From now on I should always specify dtype explicitly.",
|
|
14
|
+
domain_tags=["python", "pandas"],
|
|
15
|
+
)
|
|
16
|
+
# result: RememberResult {status: "queued", store_id: "uuid"}
|
|
17
|
+
|
|
18
|
+
results = await client.recall(
|
|
19
|
+
agent_id=agent["id"],
|
|
20
|
+
query="loading CSV files with pandas",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
view = await client.create_view(
|
|
24
|
+
agent_id=agent["id"],
|
|
25
|
+
name="pandas-csv-handling",
|
|
26
|
+
atom_filter={"atom_types": ["procedural"], "domain_tags": ["pandas"]},
|
|
27
|
+
)
|
|
28
|
+
skill = await client.export_skill(agent_id=agent["id"], view_id=view["id"])
|
|
29
|
+
|
|
30
|
+
cap = await client.grant(
|
|
31
|
+
agent_id=agent["id"],
|
|
32
|
+
view_id=view["id"],
|
|
33
|
+
grantee_id=other_agent["id"],
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
Sync usage:
|
|
37
|
+
client = MnemoClientSync(api_key="your-key", agent_id="your-uuid")
|
|
38
|
+
client.remember("pandas.read_csv coerces mixed types")
|
|
39
|
+
results = client.recall("loading CSV files")
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
import asyncio
|
|
43
|
+
import concurrent.futures
|
|
44
|
+
from typing import Optional, TypedDict
|
|
45
|
+
from uuid import UUID
|
|
46
|
+
|
|
47
|
+
import httpx
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# ── Exceptions ─────────────────────────────────────────────────────────────────
|
|
51
|
+
|
|
52
|
+
class MnemoError(Exception):
|
|
53
|
+
"""Base exception for all Mnemo client errors."""
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class MnemoAuthError(MnemoError):
|
|
58
|
+
"""Raised on 401 or 403 responses."""
|
|
59
|
+
pass
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class MnemoNotFoundError(MnemoError):
|
|
63
|
+
"""Raised on 404 responses."""
|
|
64
|
+
pass
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class MnemoServerError(MnemoError):
|
|
68
|
+
"""Raised on 5xx responses."""
|
|
69
|
+
pass
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# ── Typed response shapes ──────────────────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
class RememberResult(TypedDict):
|
|
75
|
+
status: str
|
|
76
|
+
store_id: str
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class Atom(TypedDict):
|
|
80
|
+
id: str
|
|
81
|
+
atom_type: str
|
|
82
|
+
text_content: str
|
|
83
|
+
confidence_expected: float
|
|
84
|
+
confidence_effective: float
|
|
85
|
+
domain_tags: list[str]
|
|
86
|
+
source_type: str
|
|
87
|
+
created_at: str
|
|
88
|
+
access_count: int
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class RecallResult(TypedDict):
|
|
92
|
+
atoms: list[Atom]
|
|
93
|
+
expanded_atoms: list[Atom]
|
|
94
|
+
total_retrieved: int
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class AgentStats(TypedDict):
|
|
98
|
+
agent_id: str
|
|
99
|
+
total_atoms: int
|
|
100
|
+
active_atoms: int
|
|
101
|
+
atoms_by_type: dict
|
|
102
|
+
total_edges: int
|
|
103
|
+
avg_effective_confidence: float
|
|
104
|
+
active_views: int
|
|
105
|
+
granted_capabilities: int
|
|
106
|
+
received_capabilities: int
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# ── Helpers ────────────────────────────────────────────────────────────────────
|
|
110
|
+
|
|
111
|
+
def _uid(v) -> str:
|
|
112
|
+
"""Normalise UUID or string to plain string for HTTP."""
|
|
113
|
+
return str(v)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
# ── Async client ───────────────────────────────────────────────────────────────
|
|
117
|
+
|
|
118
|
+
class MnemoClient:
|
|
119
|
+
def __init__(self, base_url: str = "https://api.mnemo.ai",
|
|
120
|
+
api_key: Optional[str] = None):
|
|
121
|
+
if not api_key:
|
|
122
|
+
raise ValueError(
|
|
123
|
+
"api_key is required. Get yours at https://mnemo.ai"
|
|
124
|
+
)
|
|
125
|
+
self.base_url = base_url.rstrip("/")
|
|
126
|
+
self.api_key = api_key
|
|
127
|
+
self._http: httpx.AsyncClient | None = None
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def http(self) -> httpx.AsyncClient:
|
|
131
|
+
if self._http is None or self._http.is_closed:
|
|
132
|
+
self._http = httpx.AsyncClient(
|
|
133
|
+
base_url=self.base_url,
|
|
134
|
+
timeout=30.0,
|
|
135
|
+
headers={"Authorization": f"Bearer {self.api_key}"},
|
|
136
|
+
)
|
|
137
|
+
return self._http
|
|
138
|
+
|
|
139
|
+
async def close(self):
|
|
140
|
+
if self._http and not self._http.is_closed:
|
|
141
|
+
await self._http.aclose()
|
|
142
|
+
|
|
143
|
+
async def __aenter__(self):
|
|
144
|
+
return self
|
|
145
|
+
|
|
146
|
+
async def __aexit__(self, *_):
|
|
147
|
+
await self.close()
|
|
148
|
+
|
|
149
|
+
def _raise_for_status(self, resp: httpx.Response) -> None:
|
|
150
|
+
if resp.status_code == 401:
|
|
151
|
+
raise MnemoAuthError("Invalid or missing API key")
|
|
152
|
+
if resp.status_code == 403:
|
|
153
|
+
raise MnemoAuthError(f"Permission denied: {resp.text}")
|
|
154
|
+
if resp.status_code == 404:
|
|
155
|
+
raise MnemoNotFoundError(resp.text)
|
|
156
|
+
if resp.status_code >= 500:
|
|
157
|
+
raise MnemoServerError(
|
|
158
|
+
f"Mnemo server error {resp.status_code}: {resp.text}"
|
|
159
|
+
)
|
|
160
|
+
resp.raise_for_status()
|
|
161
|
+
|
|
162
|
+
# ── Primary Interface ──────────────────────────────────────────────────────
|
|
163
|
+
|
|
164
|
+
async def remember(
|
|
165
|
+
self,
|
|
166
|
+
agent_id: UUID,
|
|
167
|
+
text: str,
|
|
168
|
+
domain_tags: Optional[list[str]] = None,
|
|
169
|
+
) -> RememberResult:
|
|
170
|
+
"""Store a memory. Just say what happened. Server decomposes and links."""
|
|
171
|
+
resp = await self.http.post(
|
|
172
|
+
f"/v1/agents/{_uid(agent_id)}/remember",
|
|
173
|
+
json={"text": text, "domain_tags": domain_tags or []},
|
|
174
|
+
)
|
|
175
|
+
self._raise_for_status(resp)
|
|
176
|
+
return resp.json()
|
|
177
|
+
|
|
178
|
+
async def recall(
|
|
179
|
+
self,
|
|
180
|
+
agent_id: UUID,
|
|
181
|
+
query: str,
|
|
182
|
+
domain_tags: Optional[list[str]] = None,
|
|
183
|
+
min_confidence: float = 0.1,
|
|
184
|
+
min_similarity: float = 0.2,
|
|
185
|
+
max_results: int = 10,
|
|
186
|
+
expand_graph: bool = True,
|
|
187
|
+
expansion_depth: int = 2,
|
|
188
|
+
include_superseded: bool = False,
|
|
189
|
+
similarity_drop_threshold: Optional[float] = None,
|
|
190
|
+
verbosity: Optional[str] = None,
|
|
191
|
+
max_total_tokens: Optional[int] = None,
|
|
192
|
+
) -> RecallResult:
|
|
193
|
+
"""Retrieve relevant memories by semantic search."""
|
|
194
|
+
body: dict = {
|
|
195
|
+
"query": query,
|
|
196
|
+
"domain_tags": domain_tags,
|
|
197
|
+
"min_confidence": min_confidence,
|
|
198
|
+
"min_similarity": min_similarity,
|
|
199
|
+
"max_results": max_results,
|
|
200
|
+
"expand_graph": expand_graph,
|
|
201
|
+
"expansion_depth": expansion_depth,
|
|
202
|
+
"include_superseded": include_superseded,
|
|
203
|
+
}
|
|
204
|
+
if similarity_drop_threshold is not None:
|
|
205
|
+
body["similarity_drop_threshold"] = similarity_drop_threshold
|
|
206
|
+
if verbosity is not None:
|
|
207
|
+
body["verbosity"] = verbosity
|
|
208
|
+
if max_total_tokens is not None:
|
|
209
|
+
body["max_total_tokens"] = max_total_tokens
|
|
210
|
+
resp = await self.http.post(
|
|
211
|
+
f"/v1/agents/{_uid(agent_id)}/recall",
|
|
212
|
+
json=body,
|
|
213
|
+
)
|
|
214
|
+
self._raise_for_status(resp)
|
|
215
|
+
return resp.json()
|
|
216
|
+
|
|
217
|
+
# ── Agent Management ───────────────────────────────────────────────────────
|
|
218
|
+
|
|
219
|
+
async def register_agent(
|
|
220
|
+
self,
|
|
221
|
+
name: str,
|
|
222
|
+
persona: Optional[str] = None,
|
|
223
|
+
domain_tags: Optional[list[str]] = None,
|
|
224
|
+
metadata: Optional[dict] = None,
|
|
225
|
+
) -> dict:
|
|
226
|
+
resp = await self.http.post(
|
|
227
|
+
"/v1/agents",
|
|
228
|
+
json={
|
|
229
|
+
"name": name,
|
|
230
|
+
"persona": persona,
|
|
231
|
+
"domain_tags": domain_tags or [],
|
|
232
|
+
"metadata": metadata or {},
|
|
233
|
+
},
|
|
234
|
+
)
|
|
235
|
+
self._raise_for_status(resp)
|
|
236
|
+
return resp.json()
|
|
237
|
+
|
|
238
|
+
async def me(self) -> dict:
|
|
239
|
+
"""GET /v1/auth/me — returns current agent info (requires api_key)."""
|
|
240
|
+
resp = await self.http.get("/v1/auth/me")
|
|
241
|
+
self._raise_for_status(resp)
|
|
242
|
+
return resp.json()
|
|
243
|
+
|
|
244
|
+
async def find_agent_by_name(self, name: str) -> list[dict]:
|
|
245
|
+
"""Return active agents with this exact name (empty list if none found)."""
|
|
246
|
+
resp = await self.http.get("/v1/agents", params={"name": name})
|
|
247
|
+
self._raise_for_status(resp)
|
|
248
|
+
return resp.json()
|
|
249
|
+
|
|
250
|
+
async def get_agent(self, agent_id: UUID) -> dict:
|
|
251
|
+
resp = await self.http.get(f"/v1/agents/{_uid(agent_id)}")
|
|
252
|
+
self._raise_for_status(resp)
|
|
253
|
+
return resp.json()
|
|
254
|
+
|
|
255
|
+
async def stats(self, agent_id: UUID) -> AgentStats:
|
|
256
|
+
resp = await self.http.get(f"/v1/agents/{_uid(agent_id)}/stats")
|
|
257
|
+
self._raise_for_status(resp)
|
|
258
|
+
return resp.json()
|
|
259
|
+
|
|
260
|
+
async def depart(self, agent_id: UUID) -> dict:
|
|
261
|
+
"""Initiate agent departure. Cascade-revokes all granted capabilities."""
|
|
262
|
+
resp = await self.http.post(f"/v1/agents/{_uid(agent_id)}/depart")
|
|
263
|
+
self._raise_for_status(resp)
|
|
264
|
+
return resp.json()
|
|
265
|
+
|
|
266
|
+
async def resolve_address(self, address: str) -> str:
|
|
267
|
+
"""Resolve agent address to agent UUID string. Raises MnemoNotFoundError if not found."""
|
|
268
|
+
resp = await self.http.get(f"/v1/agents/resolve/{address}")
|
|
269
|
+
self._raise_for_status(resp)
|
|
270
|
+
return resp.json()["agent_id"]
|
|
271
|
+
|
|
272
|
+
# ── Power-User Atom Operations ─────────────────────────────────────────────
|
|
273
|
+
|
|
274
|
+
async def store_atom(
|
|
275
|
+
self,
|
|
276
|
+
agent_id: UUID,
|
|
277
|
+
atom_type: str,
|
|
278
|
+
text_content: str,
|
|
279
|
+
structured: Optional[dict] = None,
|
|
280
|
+
confidence: Optional[str] = None,
|
|
281
|
+
source_type: str = "direct_experience",
|
|
282
|
+
domain_tags: Optional[list[str]] = None,
|
|
283
|
+
) -> dict:
|
|
284
|
+
"""Explicit atom creation (power-user interface)."""
|
|
285
|
+
resp = await self.http.post(
|
|
286
|
+
f"/v1/agents/{_uid(agent_id)}/atoms",
|
|
287
|
+
json={
|
|
288
|
+
"atom_type": atom_type,
|
|
289
|
+
"text_content": text_content,
|
|
290
|
+
"structured": structured or {},
|
|
291
|
+
"confidence": confidence,
|
|
292
|
+
"source_type": source_type,
|
|
293
|
+
"domain_tags": domain_tags or [],
|
|
294
|
+
},
|
|
295
|
+
)
|
|
296
|
+
self._raise_for_status(resp)
|
|
297
|
+
return resp.json()
|
|
298
|
+
|
|
299
|
+
async def get_atom(self, agent_id: UUID, atom_id: UUID) -> dict:
|
|
300
|
+
resp = await self.http.get(
|
|
301
|
+
f"/v1/agents/{_uid(agent_id)}/atoms/{_uid(atom_id)}"
|
|
302
|
+
)
|
|
303
|
+
self._raise_for_status(resp)
|
|
304
|
+
return resp.json()
|
|
305
|
+
|
|
306
|
+
async def delete_atom(self, agent_id: UUID, atom_id: UUID) -> None:
|
|
307
|
+
resp = await self.http.delete(
|
|
308
|
+
f"/v1/agents/{_uid(agent_id)}/atoms/{_uid(atom_id)}"
|
|
309
|
+
)
|
|
310
|
+
self._raise_for_status(resp)
|
|
311
|
+
|
|
312
|
+
async def link(
|
|
313
|
+
self,
|
|
314
|
+
agent_id: UUID,
|
|
315
|
+
source_id: UUID,
|
|
316
|
+
target_id: UUID,
|
|
317
|
+
edge_type: str,
|
|
318
|
+
weight: float = 1.0,
|
|
319
|
+
) -> dict:
|
|
320
|
+
"""Create a typed edge between two atoms."""
|
|
321
|
+
resp = await self.http.post(
|
|
322
|
+
f"/v1/agents/{_uid(agent_id)}/atoms/link",
|
|
323
|
+
json={
|
|
324
|
+
"source_id": _uid(source_id),
|
|
325
|
+
"target_id": _uid(target_id),
|
|
326
|
+
"edge_type": edge_type,
|
|
327
|
+
"weight": weight,
|
|
328
|
+
},
|
|
329
|
+
)
|
|
330
|
+
self._raise_for_status(resp)
|
|
331
|
+
return resp.json()
|
|
332
|
+
|
|
333
|
+
# ── View Operations ────────────────────────────────────────────────────────
|
|
334
|
+
|
|
335
|
+
async def create_view(
|
|
336
|
+
self,
|
|
337
|
+
agent_id: UUID,
|
|
338
|
+
name: str,
|
|
339
|
+
atom_filter: dict,
|
|
340
|
+
description: Optional[str] = None,
|
|
341
|
+
) -> dict:
|
|
342
|
+
resp = await self.http.post(
|
|
343
|
+
f"/v1/agents/{_uid(agent_id)}/views",
|
|
344
|
+
json={"name": name, "description": description, "atom_filter": atom_filter},
|
|
345
|
+
)
|
|
346
|
+
self._raise_for_status(resp)
|
|
347
|
+
return resp.json()
|
|
348
|
+
|
|
349
|
+
async def list_views(self, agent_id: UUID) -> list[dict]:
|
|
350
|
+
resp = await self.http.get(f"/v1/agents/{_uid(agent_id)}/views")
|
|
351
|
+
self._raise_for_status(resp)
|
|
352
|
+
return resp.json()
|
|
353
|
+
|
|
354
|
+
async def export_skill(self, agent_id: UUID, view_id: UUID) -> dict:
|
|
355
|
+
resp = await self.http.get(
|
|
356
|
+
f"/v1/agents/{_uid(agent_id)}/views/{_uid(view_id)}/export_skill"
|
|
357
|
+
)
|
|
358
|
+
self._raise_for_status(resp)
|
|
359
|
+
return resp.json()
|
|
360
|
+
|
|
361
|
+
# ── Capability Operations ──────────────────────────────────────────────────
|
|
362
|
+
|
|
363
|
+
async def grant(
|
|
364
|
+
self,
|
|
365
|
+
agent_id: UUID,
|
|
366
|
+
view_id: UUID,
|
|
367
|
+
grantee_id: UUID,
|
|
368
|
+
permissions: Optional[list[str]] = None,
|
|
369
|
+
expires_at: Optional[str] = None,
|
|
370
|
+
) -> dict:
|
|
371
|
+
resp = await self.http.post(
|
|
372
|
+
f"/v1/agents/{_uid(agent_id)}/grant",
|
|
373
|
+
json={
|
|
374
|
+
"view_id": _uid(view_id),
|
|
375
|
+
"grantee_id": _uid(grantee_id),
|
|
376
|
+
"permissions": permissions or ["read"],
|
|
377
|
+
"expires_at": expires_at,
|
|
378
|
+
},
|
|
379
|
+
)
|
|
380
|
+
self._raise_for_status(resp)
|
|
381
|
+
return resp.json()
|
|
382
|
+
|
|
383
|
+
async def revoke(self, capability_id: UUID) -> dict:
|
|
384
|
+
resp = await self.http.post(
|
|
385
|
+
f"/v1/capabilities/{_uid(capability_id)}/revoke"
|
|
386
|
+
)
|
|
387
|
+
self._raise_for_status(resp)
|
|
388
|
+
return resp.json()
|
|
389
|
+
|
|
390
|
+
async def list_shared_views(self, agent_id: UUID) -> list[dict]:
|
|
391
|
+
resp = await self.http.get(f"/v1/agents/{_uid(agent_id)}/shared_views")
|
|
392
|
+
self._raise_for_status(resp)
|
|
393
|
+
return resp.json()
|
|
394
|
+
|
|
395
|
+
async def recall_shared(
|
|
396
|
+
self,
|
|
397
|
+
agent_id: UUID,
|
|
398
|
+
view_id: UUID,
|
|
399
|
+
query: str,
|
|
400
|
+
min_confidence: float = 0.1,
|
|
401
|
+
max_results: int = 10,
|
|
402
|
+
expand_graph: bool = True,
|
|
403
|
+
expansion_depth: int = 2,
|
|
404
|
+
) -> dict:
|
|
405
|
+
"""Recall through a shared view (scope-bounded to snapshot atoms)."""
|
|
406
|
+
resp = await self.http.post(
|
|
407
|
+
f"/v1/agents/{_uid(agent_id)}/shared_views/{_uid(view_id)}/recall",
|
|
408
|
+
json={
|
|
409
|
+
"query": query,
|
|
410
|
+
"min_confidence": min_confidence,
|
|
411
|
+
"max_results": max_results,
|
|
412
|
+
"expand_graph": expand_graph,
|
|
413
|
+
"expansion_depth": expansion_depth,
|
|
414
|
+
},
|
|
415
|
+
)
|
|
416
|
+
self._raise_for_status(resp)
|
|
417
|
+
return resp.json()
|
|
418
|
+
|
|
419
|
+
async def recall_all_shared(
|
|
420
|
+
self,
|
|
421
|
+
agent_id: UUID,
|
|
422
|
+
query: str,
|
|
423
|
+
from_agent: str | None = None,
|
|
424
|
+
min_similarity: float = 0.15,
|
|
425
|
+
max_results: int = 5,
|
|
426
|
+
verbosity: str = "summary",
|
|
427
|
+
max_total_tokens: int | None = None,
|
|
428
|
+
) -> dict:
|
|
429
|
+
"""Recall across all shared views (cross-view endpoint)."""
|
|
430
|
+
body: dict = {
|
|
431
|
+
"query": query,
|
|
432
|
+
"min_similarity": min_similarity,
|
|
433
|
+
"max_results": max_results,
|
|
434
|
+
"verbosity": verbosity,
|
|
435
|
+
}
|
|
436
|
+
if from_agent:
|
|
437
|
+
body["from_agent"] = from_agent
|
|
438
|
+
if max_total_tokens is not None:
|
|
439
|
+
body["max_total_tokens"] = max_total_tokens
|
|
440
|
+
resp = await self.http.post(
|
|
441
|
+
f"/v1/agents/{_uid(agent_id)}/shared_views/recall",
|
|
442
|
+
json=body,
|
|
443
|
+
)
|
|
444
|
+
self._raise_for_status(resp)
|
|
445
|
+
return resp.json()
|
|
446
|
+
|
|
447
|
+
# ── Health ─────────────────────────────────────────────────────────────────
|
|
448
|
+
|
|
449
|
+
async def health(self) -> dict:
|
|
450
|
+
resp = await self.http.get("/v1/health")
|
|
451
|
+
self._raise_for_status(resp)
|
|
452
|
+
return resp.json()
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
# ── Sync wrapper ───────────────────────────────────────────────────────────────
|
|
456
|
+
|
|
457
|
+
class MnemoClientSync:
|
|
458
|
+
"""
|
|
459
|
+
Synchronous wrapper around MnemoClient.
|
|
460
|
+
|
|
461
|
+
Use this in non-async contexts (e.g. inside a synchronous agent loop,
|
|
462
|
+
a WebSocket handler, or a script). Handles the case where an event
|
|
463
|
+
loop is already running by offloading to a worker thread.
|
|
464
|
+
|
|
465
|
+
Example:
|
|
466
|
+
client = MnemoClientSync(api_key="your-key", agent_id="your-uuid")
|
|
467
|
+
client.remember("pandas.read_csv coerces mixed types")
|
|
468
|
+
results = client.recall("loading CSV files")
|
|
469
|
+
"""
|
|
470
|
+
|
|
471
|
+
def __init__(self, api_key: str, agent_id: str,
|
|
472
|
+
base_url: str = "https://api.mnemo.ai"):
|
|
473
|
+
if not api_key:
|
|
474
|
+
raise ValueError("api_key is required")
|
|
475
|
+
self._api_key = api_key
|
|
476
|
+
self._agent_id = agent_id
|
|
477
|
+
self._base_url = base_url
|
|
478
|
+
|
|
479
|
+
def _run(self, coro):
|
|
480
|
+
try:
|
|
481
|
+
asyncio.get_running_loop()
|
|
482
|
+
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool:
|
|
483
|
+
return pool.submit(asyncio.run, coro).result()
|
|
484
|
+
except RuntimeError:
|
|
485
|
+
return asyncio.run(coro)
|
|
486
|
+
|
|
487
|
+
def remember(self, text: str,
|
|
488
|
+
domain_tags: list[str] | None = None) -> RememberResult:
|
|
489
|
+
async def _():
|
|
490
|
+
async with MnemoClient(self._base_url, self._api_key) as c:
|
|
491
|
+
return await c.remember(self._agent_id, text, domain_tags)
|
|
492
|
+
return self._run(_())
|
|
493
|
+
|
|
494
|
+
def recall(self, query: str, **kwargs) -> RecallResult:
|
|
495
|
+
async def _():
|
|
496
|
+
async with MnemoClient(self._base_url, self._api_key) as c:
|
|
497
|
+
return await c.recall(self._agent_id, query, **kwargs)
|
|
498
|
+
return self._run(_())
|
|
499
|
+
|
|
500
|
+
def stats(self) -> AgentStats:
|
|
501
|
+
async def _():
|
|
502
|
+
async with MnemoClient(self._base_url, self._api_key) as c:
|
|
503
|
+
return await c.stats(self._agent_id)
|
|
504
|
+
return self._run(_())
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mnemo-ai"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Lightweight async Python client for the Mnemo API"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
requires-python = ">=3.12"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Inforge-ai" },
|
|
10
|
+
]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 3 - Alpha",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"License :: OSI Approved :: Apache Software License",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3.12",
|
|
17
|
+
"Programming Language :: Python :: 3.13",
|
|
18
|
+
"Typing :: Typed",
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"httpx>=0.26.0",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[build-system]
|
|
25
|
+
requires = ["hatchling"]
|
|
26
|
+
build-backend = "hatchling.build"
|
|
27
|
+
|
|
28
|
+
[tool.hatch.build.targets.wheel]
|
|
29
|
+
packages = ["."]
|
|
30
|
+
include = ["mnemo_client.py"]
|
mnemo_ai-0.1.0/uv.lock
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
version = 1
|
|
2
|
+
revision = 3
|
|
3
|
+
requires-python = ">=3.12"
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "anyio"
|
|
7
|
+
version = "4.12.1"
|
|
8
|
+
source = { registry = "https://pypi.org/simple" }
|
|
9
|
+
dependencies = [
|
|
10
|
+
{ name = "idna" },
|
|
11
|
+
{ name = "typing-extensions", marker = "python_full_version < '3.13'" },
|
|
12
|
+
]
|
|
13
|
+
sdist = { url = "https://files.pythonhosted.org/packages/96/f0/5eb65b2bb0d09ac6776f2eb54adee6abe8228ea05b20a5ad0e4945de8aac/anyio-4.12.1.tar.gz", hash = "sha256:41cfcc3a4c85d3f05c932da7c26d0201ac36f72abd4435ba90d0464a3ffed703", size = 228685, upload-time = "2026-01-06T11:45:21.246Z" }
|
|
14
|
+
wheels = [
|
|
15
|
+
{ url = "https://files.pythonhosted.org/packages/38/0e/27be9fdef66e72d64c0cdc3cc2823101b80585f8119b5c112c2e8f5f7dab/anyio-4.12.1-py3-none-any.whl", hash = "sha256:d405828884fc140aa80a3c667b8beed277f1dfedec42ba031bd6ac3db606ab6c", size = 113592, upload-time = "2026-01-06T11:45:19.497Z" },
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[[package]]
|
|
19
|
+
name = "certifi"
|
|
20
|
+
version = "2026.2.25"
|
|
21
|
+
source = { registry = "https://pypi.org/simple" }
|
|
22
|
+
sdist = { url = "https://files.pythonhosted.org/packages/af/2d/7bf41579a8986e348fa033a31cdd0e4121114f6bce2457e8876010b092dd/certifi-2026.2.25.tar.gz", hash = "sha256:e887ab5cee78ea814d3472169153c2d12cd43b14bd03329a39a9c6e2e80bfba7", size = 155029, upload-time = "2026-02-25T02:54:17.342Z" }
|
|
23
|
+
wheels = [
|
|
24
|
+
{ url = "https://files.pythonhosted.org/packages/9a/3c/c17fb3ca2d9c3acff52e30b309f538586f9f5b9c9cf454f3845fc9af4881/certifi-2026.2.25-py3-none-any.whl", hash = "sha256:027692e4402ad994f1c42e52a4997a9763c646b73e4096e4d5d6db8af1d6f0fa", size = 153684, upload-time = "2026-02-25T02:54:15.766Z" },
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[[package]]
|
|
28
|
+
name = "h11"
|
|
29
|
+
version = "0.16.0"
|
|
30
|
+
source = { registry = "https://pypi.org/simple" }
|
|
31
|
+
sdist = { url = "https://files.pythonhosted.org/packages/01/ee/02a2c011bdab74c6fb3c75474d40b3052059d95df7e73351460c8588d963/h11-0.16.0.tar.gz", hash = "sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1", size = 101250, upload-time = "2025-04-24T03:35:25.427Z" }
|
|
32
|
+
wheels = [
|
|
33
|
+
{ url = "https://files.pythonhosted.org/packages/04/4b/29cac41a4d98d144bf5f6d33995617b185d14b22401f75ca86f384e87ff1/h11-0.16.0-py3-none-any.whl", hash = "sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86", size = 37515, upload-time = "2025-04-24T03:35:24.344Z" },
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[[package]]
|
|
37
|
+
name = "httpcore"
|
|
38
|
+
version = "1.0.9"
|
|
39
|
+
source = { registry = "https://pypi.org/simple" }
|
|
40
|
+
dependencies = [
|
|
41
|
+
{ name = "certifi" },
|
|
42
|
+
{ name = "h11" },
|
|
43
|
+
]
|
|
44
|
+
sdist = { url = "https://files.pythonhosted.org/packages/06/94/82699a10bca87a5556c9c59b5963f2d039dbd239f25bc2a63907a05a14cb/httpcore-1.0.9.tar.gz", hash = "sha256:6e34463af53fd2ab5d807f399a9b45ea31c3dfa2276f15a2c3f00afff6e176e8", size = 85484, upload-time = "2025-04-24T22:06:22.219Z" }
|
|
45
|
+
wheels = [
|
|
46
|
+
{ url = "https://files.pythonhosted.org/packages/7e/f5/f66802a942d491edb555dd61e3a9961140fd64c90bce1eafd741609d334d/httpcore-1.0.9-py3-none-any.whl", hash = "sha256:2d400746a40668fc9dec9810239072b40b4484b640a8c38fd654a024c7a1bf55", size = 78784, upload-time = "2025-04-24T22:06:20.566Z" },
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[[package]]
|
|
50
|
+
name = "httpx"
|
|
51
|
+
version = "0.28.1"
|
|
52
|
+
source = { registry = "https://pypi.org/simple" }
|
|
53
|
+
dependencies = [
|
|
54
|
+
{ name = "anyio" },
|
|
55
|
+
{ name = "certifi" },
|
|
56
|
+
{ name = "httpcore" },
|
|
57
|
+
{ name = "idna" },
|
|
58
|
+
]
|
|
59
|
+
sdist = { url = "https://files.pythonhosted.org/packages/b1/df/48c586a5fe32a0f01324ee087459e112ebb7224f646c0b5023f5e79e9956/httpx-0.28.1.tar.gz", hash = "sha256:75e98c5f16b0f35b567856f597f06ff2270a374470a5c2392242528e3e3e42fc", size = 141406, upload-time = "2024-12-06T15:37:23.222Z" }
|
|
60
|
+
wheels = [
|
|
61
|
+
{ url = "https://files.pythonhosted.org/packages/2a/39/e50c7c3a983047577ee07d2a9e53faf5a69493943ec3f6a384bdc792deb2/httpx-0.28.1-py3-none-any.whl", hash = "sha256:d909fcccc110f8c7faf814ca82a9a4d816bc5a6dbfea25d6591d6985b8ba59ad", size = 73517, upload-time = "2024-12-06T15:37:21.509Z" },
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
[[package]]
|
|
65
|
+
name = "idna"
|
|
66
|
+
version = "3.11"
|
|
67
|
+
source = { registry = "https://pypi.org/simple" }
|
|
68
|
+
sdist = { url = "https://files.pythonhosted.org/packages/6f/6d/0703ccc57f3a7233505399edb88de3cbd678da106337b9fcde432b65ed60/idna-3.11.tar.gz", hash = "sha256:795dafcc9c04ed0c1fb032c2aa73654d8e8c5023a7df64a53f39190ada629902", size = 194582, upload-time = "2025-10-12T14:55:20.501Z" }
|
|
69
|
+
wheels = [
|
|
70
|
+
{ url = "https://files.pythonhosted.org/packages/0e/61/66938bbb5fc52dbdf84594873d5b51fb1f7c7794e9c0f5bd885f30bc507b/idna-3.11-py3-none-any.whl", hash = "sha256:771a87f49d9defaf64091e6e6fe9c18d4833f140bd19464795bc32d966ca37ea", size = 71008, upload-time = "2025-10-12T14:55:18.883Z" },
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
[[package]]
|
|
74
|
+
name = "mnemo-client"
|
|
75
|
+
version = "0.1.0"
|
|
76
|
+
source = { editable = "." }
|
|
77
|
+
dependencies = [
|
|
78
|
+
{ name = "httpx" },
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
[package.metadata]
|
|
82
|
+
requires-dist = [{ name = "httpx", specifier = ">=0.26.0" }]
|
|
83
|
+
|
|
84
|
+
[[package]]
|
|
85
|
+
name = "typing-extensions"
|
|
86
|
+
version = "4.15.0"
|
|
87
|
+
source = { registry = "https://pypi.org/simple" }
|
|
88
|
+
sdist = { url = "https://files.pythonhosted.org/packages/72/94/1a15dd82efb362ac84269196e94cf00f187f7ed21c242792a923cdb1c61f/typing_extensions-4.15.0.tar.gz", hash = "sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466", size = 109391, upload-time = "2025-08-25T13:49:26.313Z" }
|
|
89
|
+
wheels = [
|
|
90
|
+
{ url = "https://files.pythonhosted.org/packages/18/67/36e9267722cc04a6b9f15c7f3441c2363321a3ea07da7ae0c0707beb2a9c/typing_extensions-4.15.0-py3-none-any.whl", hash = "sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548", size = 44614, upload-time = "2025-08-25T13:49:24.86Z" },
|
|
91
|
+
]
|