clickhouse-loom 1.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.
- clickhouse_loom-1.1.0/LICENSE +201 -0
- clickhouse_loom-1.1.0/PKG-INFO +191 -0
- clickhouse_loom-1.1.0/README.md +162 -0
- clickhouse_loom-1.1.0/examples/README.md +38 -0
- clickhouse_loom-1.1.0/examples/agent_memory.py +97 -0
- clickhouse_loom-1.1.0/loom/__init__.py +77 -0
- clickhouse_loom-1.1.0/loom/__main__.py +8 -0
- clickhouse_loom-1.1.0/loom/_logging.py +112 -0
- clickhouse_loom-1.1.0/loom/_version.py +4 -0
- clickhouse_loom-1.1.0/loom/account.py +82 -0
- clickhouse_loom-1.1.0/loom/admin_routes.py +208 -0
- clickhouse_loom-1.1.0/loom/agent.py +542 -0
- clickhouse_loom-1.1.0/loom/audit.py +45 -0
- clickhouse_loom-1.1.0/loom/blacklist.py +94 -0
- clickhouse_loom-1.1.0/loom/briefs.py +129 -0
- clickhouse_loom-1.1.0/loom/calibration.py +33 -0
- clickhouse_loom-1.1.0/loom/capabilities.py +66 -0
- clickhouse_loom-1.1.0/loom/cli.py +271 -0
- clickhouse_loom-1.1.0/loom/client.py +3359 -0
- clickhouse_loom-1.1.0/loom/code.py +872 -0
- clickhouse_loom-1.1.0/loom/conflicts.py +109 -0
- clickhouse_loom-1.1.0/loom/context.py +286 -0
- clickhouse_loom-1.1.0/loom/conversations.py +244 -0
- clickhouse_loom-1.1.0/loom/cost.py +53 -0
- clickhouse_loom-1.1.0/loom/credentials.py +817 -0
- clickhouse_loom-1.1.0/loom/datapack.py +81 -0
- clickhouse_loom-1.1.0/loom/decision.py +153 -0
- clickhouse_loom-1.1.0/loom/deployment.py +97 -0
- clickhouse_loom-1.1.0/loom/erasure.py +126 -0
- clickhouse_loom-1.1.0/loom/errors.py +223 -0
- clickhouse_loom-1.1.0/loom/facts.py +190 -0
- clickhouse_loom-1.1.0/loom/grants.py +94 -0
- clickhouse_loom-1.1.0/loom/integrations/__init__.py +3 -0
- clickhouse_loom-1.1.0/loom/integrations/langgraph.py +592 -0
- clickhouse_loom-1.1.0/loom/integrations/strands.py +137 -0
- clickhouse_loom-1.1.0/loom/knowledge.py +292 -0
- clickhouse_loom-1.1.0/loom/learnings.py +88 -0
- clickhouse_loom-1.1.0/loom/machine.py +272 -0
- clickhouse_loom-1.1.0/loom/memory.py +2345 -0
- clickhouse_loom-1.1.0/loom/namespace.py +244 -0
- clickhouse_loom-1.1.0/loom/ops.py +19768 -0
- clickhouse_loom-1.1.0/loom/policy.py +140 -0
- clickhouse_loom-1.1.0/loom/procedure.py +265 -0
- clickhouse_loom-1.1.0/loom/profile.py +246 -0
- clickhouse_loom-1.1.0/loom/py.typed +0 -0
- clickhouse_loom-1.1.0/loom/records.py +218 -0
- clickhouse_loom-1.1.0/loom/reference_client.py +658 -0
- clickhouse_loom-1.1.0/loom/retry.py +149 -0
- clickhouse_loom-1.1.0/loom/run.py +525 -0
- clickhouse_loom-1.1.0/loom/session.py +243 -0
- clickhouse_loom-1.1.0/loom/sync.py +436 -0
- clickhouse_loom-1.1.0/loom/tasks.py +437 -0
- clickhouse_loom-1.1.0/loom/token.py +113 -0
- clickhouse_loom-1.1.0/loom/tools.py +320 -0
- clickhouse_loom-1.1.0/loom/tracker.py +245 -0
- clickhouse_loom-1.1.0/loom/transport.py +852 -0
- clickhouse_loom-1.1.0/loom/working_memory.py +227 -0
- clickhouse_loom-1.1.0/pyproject.toml +61 -0
|
@@ -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 describing the origin of the Work and
|
|
141
|
+
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 directory 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 2026 ClickHouse, Inc.
|
|
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,191 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: clickhouse-loom
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Python SDK for Loom — shared-production agent memory, knowledge, conflict, and observability plane on ClickHouse.
|
|
5
|
+
Project-URL: Homepage, https://github.com/ClickHouse/loom
|
|
6
|
+
Project-URL: Repository, https://github.com/ClickHouse/loom
|
|
7
|
+
Project-URL: Issues, https://github.com/ClickHouse/loom/issues
|
|
8
|
+
Author: ClickHouse, Inc.
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agent,ai,clickhouse,llm,loom,mcp,memory
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Requires-Dist: httpx[http2]>=0.27
|
|
23
|
+
Provides-Extra: aws
|
|
24
|
+
Requires-Dist: boto3>=1.28; extra == 'aws'
|
|
25
|
+
Requires-Dist: pyjwt[crypto]>=2.8; extra == 'aws'
|
|
26
|
+
Provides-Extra: machine
|
|
27
|
+
Requires-Dist: pyjwt[crypto]>=2.8; extra == 'machine'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# clickhouse-loom
|
|
31
|
+
|
|
32
|
+
Python SDK for [Loom](https://github.com/ClickHouse/loom) — the shared-production memory, knowledge, conflict, and observability data plane for AI agents, built on ClickHouse.
|
|
33
|
+
|
|
34
|
+
This package contains the **client SDK only**. Loom is designed for shared production deployment: an operator runs the server (Docker image at `ghcr.io/clickhouse/loom`) against a real ClickHouse instance (Cloud or self-hosted OSS), then application developers like you use this SDK to talk to it.
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
Not on PyPI yet, so install from source — pure Python, no build step — or from
|
|
39
|
+
the wheel attached to a GitHub Release
|
|
40
|
+
([docs/development/release-process.md](https://github.com/ClickHouse/loom/blob/main/docs/development/release-process.md#installing-from-a-github-release)):
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install ./sdk/python # from a clone of ClickHouse/loom
|
|
44
|
+
# without a clone (needs the same GitHub access as `git clone`):
|
|
45
|
+
pip install "clickhouse-loom @ git+https://github.com/ClickHouse/loom#subdirectory=sdk/python"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
<!-- restore `pip install clickhouse-loom` when release.yml publishes -->
|
|
49
|
+
|
|
50
|
+
Python 3.11+. Runtime deps: `httpx[http2]` (HTTP/2 via `h2`).
|
|
51
|
+
|
|
52
|
+
## Use
|
|
53
|
+
|
|
54
|
+
You'll need:
|
|
55
|
+
|
|
56
|
+
- A `base_url` pointing at your team's Loom deployment.
|
|
57
|
+
- A credential. Either sign in once with `python -m loom login --server <url>` (or `loom.login(url)` in a notebook), approving on any browser with your password or SSO; every `Agent` you point at that server (`base_url=` or `LOOM_BASE_URL`) then uses that session and refreshes it. Or use a JWT your operator mints (`POST /v1/admin/token.mint`, `loom mint-token`), passed as `api_key=` or `LOOM_API_KEY` — the right choice for CI and services.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from loom import Datapack
|
|
61
|
+
import os
|
|
62
|
+
|
|
63
|
+
dp = Datapack(
|
|
64
|
+
org="clickhouse",
|
|
65
|
+
namespace="eng-tooling",
|
|
66
|
+
base_url=os.environ["LOOM_BASE_URL"], # e.g. https://loom.example.com
|
|
67
|
+
api_key=os.environ["LOOM_API_KEY"], # JWT from your operator
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
agent = dp.agent("claude-desktop")
|
|
71
|
+
|
|
72
|
+
# Save a memory
|
|
73
|
+
await agent.memory.set(
|
|
74
|
+
memory_key="deploy_window",
|
|
75
|
+
value="Deploy Tue/Thu, never Friday",
|
|
76
|
+
memory_type="preference",
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
# Recall by key
|
|
80
|
+
got = await agent.memory.get(memory_key="deploy_window")
|
|
81
|
+
|
|
82
|
+
# Or semantic search
|
|
83
|
+
hits = await agent.memory.search("when do we deploy")
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The `Agent` exposes 27 client modules: `client`, `account`, `deployment`, `memory`, `working_memory`, `knowledge`, `conversations`, `profile`, `context`, `facts`, `learnings`, `conflicts`, `blacklist`, `grants`, `erasure`, `cost`, `audit`, `namespaces`, `procedure`, `run`, `tasks`, `policy`, `decision`, `calibration`, `briefs`, `code`, `tracker`. Each of the named ones is the hand-written layer over a wire-op group on the Loom server (`account` and `deployment` cover the routes outside the op registry: service accounts, MCP setup, model settings, worker health); `client` holds every served op as a generated method (below).
|
|
87
|
+
|
|
88
|
+
Full guide: [docs/reference/python-sdk.md](https://github.com/ClickHouse/loom/blob/main/docs/reference/python-sdk.md). Deployment paths (how an operator stands up the server): [docs/operations/deployment.md](https://github.com/ClickHouse/loom/blob/main/docs/operations/deployment.md).
|
|
89
|
+
|
|
90
|
+
## Every op by name, any op by call, a probe before you rely
|
|
91
|
+
|
|
92
|
+
`loom.ops` is generated from the server's operation registry: `OPS` (name → idempotency, required role, maturity, latency budget), `OpName`, and one `TypedDict` per request / response (`MemorySearchInput`, …) with `Required[...]` on the fields the server requires — names for your editor and type checker while the SDK stays dict-in / dict-out. `MemorySearchBody` is the same shape with the identity keys (`org`, `namespace`, `agent`, `user_id`, `session_id`, `run_id`) optional: what you write when `agent.call` stamps the identity for you.
|
|
93
|
+
|
|
94
|
+
`agent.client` has one method per served op, generated from the same registry: the group is the op name's first segment and the method the rest with `.` → `_`, so `tracker.source.add` is `agent.client.tracker.source_add({...})`. It takes the op's `<Op>Body`, returns its `<Op>Output`, and passes `user_id=`, `session_id=`, `timeout_s=` and the other `agent.call` options through. The TypeScript SDK exposes the same ops at the same group, camel-cased: `loom.tracker.sourceAdd({...})`; a unit test fails when the two differ.
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from loom.ops import OPS, MemorySearchBody
|
|
98
|
+
|
|
99
|
+
body: MemorySearchBody = {"query": "deploy window", "top_k": 5, "exclude_keys": ["seen_1"]}
|
|
100
|
+
out = await agent.call(
|
|
101
|
+
"memory.search", body, user_id="u-42"
|
|
102
|
+
) # identity stamped; Idempotency-Key when OPS says idempotent
|
|
103
|
+
p = await agent.probe(
|
|
104
|
+
ops=["memory.ask", "context.pack"], fields={"memory.search": ["exclude_keys"]}
|
|
105
|
+
)
|
|
106
|
+
assert p["ok"], (p["missing_ops"], p["missing_fields"])
|
|
107
|
+
print(OPS["memory.search"].idempotent, OPS["memory.search"].role)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`agent.memory.search(...)` and `agent.knowledge.search(...)` also accept `**extra`, so a field the server shipped this week rides the body without an SDK release. Errors are typed by the server's `detail.code`, and by HTTP status when a body carries none: `NotFound`, `ValidationError`, `AuthInvalid`, `AuthInsufficient`, `PreconditionFailed`, `RateLimited`, `BackendUnavailable` — every one carries `.request_id` (the `X-Request-Id` the server echoed) and `.status`.
|
|
111
|
+
|
|
112
|
+
`await agent.capabilities()` pairs `ops.capabilities` with what the bearer token itself says (`roles` / `ns_roles`, decoded, not verified) so an integration does not poll ops its token cannot call: `caps.can_call("conflicts.list")` is `True` / `False` when known and `None` when the SDK cannot tell — then make the call; `await agent.can_call(op)` answers for the Agent's namespace; `caps.callable()` lists every served op the token may call. Cached 60 s.
|
|
113
|
+
|
|
114
|
+
`agent.call_with_meta(...)` is the same call returning a `CallResult`: `.data`, `.request_id` (finds the call in the server's ledger), `.schema_version`, `.server_timing_ms`, `.rate_limit` and `.attempts`. Every request identifies itself (`User-Agent` / `X-Loom-SDK: loom-py/<version>`, `X-Loom-Runtime`, `X-Loom-Retry-Count`); `Retry-After` is honoured as seconds or an HTTP-date. The credential never appears in `repr(agent.transport)` (it shows `api_key=…1234`), and a blank `LOOM_API_KEY` is treated as unset. The package ships `py.typed` and passes `mypy --strict`.
|
|
115
|
+
|
|
116
|
+
## Give your agent the guide
|
|
117
|
+
|
|
118
|
+
`await agent.guide()` returns how to use Loom, written for a model: the loop,
|
|
119
|
+
where each kind of state goes and how to read what comes back
|
|
120
|
+
(the experimental `mentor.guide`, the `loom` skill in `skills/loom/`). Put it in the system
|
|
121
|
+
prompt of an agent that has no plugin to carry it; `part="reference"` returns
|
|
122
|
+
every plane with its ops.
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
system_prompt = "You triage support tickets.\n\n" + await agent.guide()
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Ask the mentor
|
|
129
|
+
|
|
130
|
+
The store reads what your agent actually calls and names the planes it never
|
|
131
|
+
uses — the code index, the tracker source, documents, records, offload,
|
|
132
|
+
the entity graph — with the counts behind each hint. Two channels need nothing
|
|
133
|
+
from you: every successful response may carry one `X-Loom-Hint`, which the
|
|
134
|
+
transport logs at INFO once per distinct text and exposes as
|
|
135
|
+
`CallResult.hint`, and a `context.pack` at session start carries up to three
|
|
136
|
+
hints. A bot that never renders a pack asks once at startup:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
async with Agent(org="acme", namespace="support", agent="triage-bot") as bot:
|
|
140
|
+
brief = await bot.mentor() # logs up to three hints; returns the brief
|
|
141
|
+
for h in brief["hints"]:
|
|
142
|
+
print(h["code"], h["severity"], h["text"], h["evidence"])
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`mentor_brief=True` (or `LOOM_MENTOR_BRIEF=on`) runs it in the background on
|
|
146
|
+
the first call instead. Name your agent: `""`, `"-"` and `"*"` default to
|
|
147
|
+
`sdk-python:<script>` with a warning, because an anonymous agent is every
|
|
148
|
+
other anonymous caller to the ledger, the mentor and the cost views.
|
|
149
|
+
|
|
150
|
+
## Sessions and tools: what an agent framework holds
|
|
151
|
+
|
|
152
|
+
`agent.session(id, user_id=...)` binds one (user, session) scope to the verbs an agent loop needs between turns: `resume()` returns the context pack as `system` plus the transcript tail as `messages`; `append(*turns)` writes the transcript now and runs `memory.set_from_messages` every `flush_every` turns; `offload()` / `fetch()` park a large tool result and read it back by pattern; `note()` appends to working memory; `close()` flushes. It is an async context manager; `SyncAgent.session()` blocks.
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
async with agent.session("thread-42", user_id="u1") as s:
|
|
156
|
+
resumed = await s.resume(query="resume the billing migration")
|
|
157
|
+
system_prompt, history = resumed.system, resumed.messages
|
|
158
|
+
await s.append({"role": "user", "content": text}, {"role": "assistant", "content": reply})
|
|
159
|
+
blob = await s.offload(build_log, summary="pytest run 812")
|
|
160
|
+
await s.note(blob["pointer"])
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
`agent.tools(user_id=..., session_id=...)` gives a model six loom verbs — `loom_remember`, `loom_recall`, `loom_ask`, `loom_offload`, `loom_fetch`, `loom_note` — as `definitions("openai" | "anthropic" | "generic")` and one `await execute(name, arguments)` that returns the string the model reads. The schemas are the same as the TypeScript SDK's.
|
|
164
|
+
|
|
165
|
+
## Retries and logging
|
|
166
|
+
|
|
167
|
+
The retry policy is one frozen dataclass, set on the Agent and overridable per call with a `RetryPolicy` or a dict of its fields; every field is validated and named when wrong. Defaults: 3 attempts; 0.1 s backoff doubling to 5 s with ±25 % jitter; 408 and 5xx retried for registry-idempotent ops (any other op only on a 408 or a 503 `AUTH_UNAVAILABLE`, which the server answers before running it); connection errors retried; a read timeout retried only when the registry marks the op idempotent (the server dedups its `Idempotency-Key`); a `Retry-After` on a retried status honoured up to 60 s. A 429 is paced, not retried.
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from loom import Agent, RetryPolicy
|
|
171
|
+
|
|
172
|
+
agent = Agent(
|
|
173
|
+
"acme",
|
|
174
|
+
"support",
|
|
175
|
+
"bot",
|
|
176
|
+
retry=RetryPolicy(max_attempts=5, total_backoff_budget_s=30),
|
|
177
|
+
consumer="support-bot",
|
|
178
|
+
) # the label every ledger row carries
|
|
179
|
+
await agent.call("memory.get", memory_key="k", retry={"max_attempts": 1}) # this call: no retries
|
|
180
|
+
await agent.call("memory.set_from_messages", messages=msgs, retry={"retry_timeouts": "always"})
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The SDK logs through the stdlib logger `loom` (a `NullHandler` by default; your logging config routes it): one line per completed call at INFO (`/v1/memory.get 200 12 ms attempts=2 rid=…`), retries and rate-limit waits at WARNING, the final failure at ERROR, the request headers at DEBUG. `LOOM_LOG_LEVEL` (any stdlib level name — `debug`, `info`, `warning`, `error`, `critical` — or `off`) sets the logger's level when your application has not; a value it cannot read is a warning, not an import error. Credential headers are redacted to their scheme and last four characters, and a filter on the logger rewrites any bearer token that reaches a record anyway.
|
|
184
|
+
|
|
185
|
+
## Examples
|
|
186
|
+
|
|
187
|
+
[`examples/agent_memory.py`](./examples/agent_memory.py) — probe → remember ×3 → recall → ask with citations → outcome → typed errors, with its actual run in [`examples/README.md`](./examples/README.md). The TypeScript SDK ships the same example.
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
Apache-2.0. See [LICENSE](https://github.com/ClickHouse/loom/blob/main/LICENSE).
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# clickhouse-loom
|
|
2
|
+
|
|
3
|
+
Python SDK for [Loom](https://github.com/ClickHouse/loom) — the shared-production memory, knowledge, conflict, and observability data plane for AI agents, built on ClickHouse.
|
|
4
|
+
|
|
5
|
+
This package contains the **client SDK only**. Loom is designed for shared production deployment: an operator runs the server (Docker image at `ghcr.io/clickhouse/loom`) against a real ClickHouse instance (Cloud or self-hosted OSS), then application developers like you use this SDK to talk to it.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Not on PyPI yet, so install from source — pure Python, no build step — or from
|
|
10
|
+
the wheel attached to a GitHub Release
|
|
11
|
+
([docs/development/release-process.md](https://github.com/ClickHouse/loom/blob/main/docs/development/release-process.md#installing-from-a-github-release)):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install ./sdk/python # from a clone of ClickHouse/loom
|
|
15
|
+
# without a clone (needs the same GitHub access as `git clone`):
|
|
16
|
+
pip install "clickhouse-loom @ git+https://github.com/ClickHouse/loom#subdirectory=sdk/python"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
<!-- restore `pip install clickhouse-loom` when release.yml publishes -->
|
|
20
|
+
|
|
21
|
+
Python 3.11+. Runtime deps: `httpx[http2]` (HTTP/2 via `h2`).
|
|
22
|
+
|
|
23
|
+
## Use
|
|
24
|
+
|
|
25
|
+
You'll need:
|
|
26
|
+
|
|
27
|
+
- A `base_url` pointing at your team's Loom deployment.
|
|
28
|
+
- A credential. Either sign in once with `python -m loom login --server <url>` (or `loom.login(url)` in a notebook), approving on any browser with your password or SSO; every `Agent` you point at that server (`base_url=` or `LOOM_BASE_URL`) then uses that session and refreshes it. Or use a JWT your operator mints (`POST /v1/admin/token.mint`, `loom mint-token`), passed as `api_key=` or `LOOM_API_KEY` — the right choice for CI and services.
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from loom import Datapack
|
|
32
|
+
import os
|
|
33
|
+
|
|
34
|
+
dp = Datapack(
|
|
35
|
+
org="clickhouse",
|
|
36
|
+
namespace="eng-tooling",
|
|
37
|
+
base_url=os.environ["LOOM_BASE_URL"], # e.g. https://loom.example.com
|
|
38
|
+
api_key=os.environ["LOOM_API_KEY"], # JWT from your operator
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
agent = dp.agent("claude-desktop")
|
|
42
|
+
|
|
43
|
+
# Save a memory
|
|
44
|
+
await agent.memory.set(
|
|
45
|
+
memory_key="deploy_window",
|
|
46
|
+
value="Deploy Tue/Thu, never Friday",
|
|
47
|
+
memory_type="preference",
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# Recall by key
|
|
51
|
+
got = await agent.memory.get(memory_key="deploy_window")
|
|
52
|
+
|
|
53
|
+
# Or semantic search
|
|
54
|
+
hits = await agent.memory.search("when do we deploy")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The `Agent` exposes 27 client modules: `client`, `account`, `deployment`, `memory`, `working_memory`, `knowledge`, `conversations`, `profile`, `context`, `facts`, `learnings`, `conflicts`, `blacklist`, `grants`, `erasure`, `cost`, `audit`, `namespaces`, `procedure`, `run`, `tasks`, `policy`, `decision`, `calibration`, `briefs`, `code`, `tracker`. Each of the named ones is the hand-written layer over a wire-op group on the Loom server (`account` and `deployment` cover the routes outside the op registry: service accounts, MCP setup, model settings, worker health); `client` holds every served op as a generated method (below).
|
|
58
|
+
|
|
59
|
+
Full guide: [docs/reference/python-sdk.md](https://github.com/ClickHouse/loom/blob/main/docs/reference/python-sdk.md). Deployment paths (how an operator stands up the server): [docs/operations/deployment.md](https://github.com/ClickHouse/loom/blob/main/docs/operations/deployment.md).
|
|
60
|
+
|
|
61
|
+
## Every op by name, any op by call, a probe before you rely
|
|
62
|
+
|
|
63
|
+
`loom.ops` is generated from the server's operation registry: `OPS` (name → idempotency, required role, maturity, latency budget), `OpName`, and one `TypedDict` per request / response (`MemorySearchInput`, …) with `Required[...]` on the fields the server requires — names for your editor and type checker while the SDK stays dict-in / dict-out. `MemorySearchBody` is the same shape with the identity keys (`org`, `namespace`, `agent`, `user_id`, `session_id`, `run_id`) optional: what you write when `agent.call` stamps the identity for you.
|
|
64
|
+
|
|
65
|
+
`agent.client` has one method per served op, generated from the same registry: the group is the op name's first segment and the method the rest with `.` → `_`, so `tracker.source.add` is `agent.client.tracker.source_add({...})`. It takes the op's `<Op>Body`, returns its `<Op>Output`, and passes `user_id=`, `session_id=`, `timeout_s=` and the other `agent.call` options through. The TypeScript SDK exposes the same ops at the same group, camel-cased: `loom.tracker.sourceAdd({...})`; a unit test fails when the two differ.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from loom.ops import OPS, MemorySearchBody
|
|
69
|
+
|
|
70
|
+
body: MemorySearchBody = {"query": "deploy window", "top_k": 5, "exclude_keys": ["seen_1"]}
|
|
71
|
+
out = await agent.call(
|
|
72
|
+
"memory.search", body, user_id="u-42"
|
|
73
|
+
) # identity stamped; Idempotency-Key when OPS says idempotent
|
|
74
|
+
p = await agent.probe(
|
|
75
|
+
ops=["memory.ask", "context.pack"], fields={"memory.search": ["exclude_keys"]}
|
|
76
|
+
)
|
|
77
|
+
assert p["ok"], (p["missing_ops"], p["missing_fields"])
|
|
78
|
+
print(OPS["memory.search"].idempotent, OPS["memory.search"].role)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`agent.memory.search(...)` and `agent.knowledge.search(...)` also accept `**extra`, so a field the server shipped this week rides the body without an SDK release. Errors are typed by the server's `detail.code`, and by HTTP status when a body carries none: `NotFound`, `ValidationError`, `AuthInvalid`, `AuthInsufficient`, `PreconditionFailed`, `RateLimited`, `BackendUnavailable` — every one carries `.request_id` (the `X-Request-Id` the server echoed) and `.status`.
|
|
82
|
+
|
|
83
|
+
`await agent.capabilities()` pairs `ops.capabilities` with what the bearer token itself says (`roles` / `ns_roles`, decoded, not verified) so an integration does not poll ops its token cannot call: `caps.can_call("conflicts.list")` is `True` / `False` when known and `None` when the SDK cannot tell — then make the call; `await agent.can_call(op)` answers for the Agent's namespace; `caps.callable()` lists every served op the token may call. Cached 60 s.
|
|
84
|
+
|
|
85
|
+
`agent.call_with_meta(...)` is the same call returning a `CallResult`: `.data`, `.request_id` (finds the call in the server's ledger), `.schema_version`, `.server_timing_ms`, `.rate_limit` and `.attempts`. Every request identifies itself (`User-Agent` / `X-Loom-SDK: loom-py/<version>`, `X-Loom-Runtime`, `X-Loom-Retry-Count`); `Retry-After` is honoured as seconds or an HTTP-date. The credential never appears in `repr(agent.transport)` (it shows `api_key=…1234`), and a blank `LOOM_API_KEY` is treated as unset. The package ships `py.typed` and passes `mypy --strict`.
|
|
86
|
+
|
|
87
|
+
## Give your agent the guide
|
|
88
|
+
|
|
89
|
+
`await agent.guide()` returns how to use Loom, written for a model: the loop,
|
|
90
|
+
where each kind of state goes and how to read what comes back
|
|
91
|
+
(the experimental `mentor.guide`, the `loom` skill in `skills/loom/`). Put it in the system
|
|
92
|
+
prompt of an agent that has no plugin to carry it; `part="reference"` returns
|
|
93
|
+
every plane with its ops.
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
system_prompt = "You triage support tickets.\n\n" + await agent.guide()
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Ask the mentor
|
|
100
|
+
|
|
101
|
+
The store reads what your agent actually calls and names the planes it never
|
|
102
|
+
uses — the code index, the tracker source, documents, records, offload,
|
|
103
|
+
the entity graph — with the counts behind each hint. Two channels need nothing
|
|
104
|
+
from you: every successful response may carry one `X-Loom-Hint`, which the
|
|
105
|
+
transport logs at INFO once per distinct text and exposes as
|
|
106
|
+
`CallResult.hint`, and a `context.pack` at session start carries up to three
|
|
107
|
+
hints. A bot that never renders a pack asks once at startup:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
async with Agent(org="acme", namespace="support", agent="triage-bot") as bot:
|
|
111
|
+
brief = await bot.mentor() # logs up to three hints; returns the brief
|
|
112
|
+
for h in brief["hints"]:
|
|
113
|
+
print(h["code"], h["severity"], h["text"], h["evidence"])
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`mentor_brief=True` (or `LOOM_MENTOR_BRIEF=on`) runs it in the background on
|
|
117
|
+
the first call instead. Name your agent: `""`, `"-"` and `"*"` default to
|
|
118
|
+
`sdk-python:<script>` with a warning, because an anonymous agent is every
|
|
119
|
+
other anonymous caller to the ledger, the mentor and the cost views.
|
|
120
|
+
|
|
121
|
+
## Sessions and tools: what an agent framework holds
|
|
122
|
+
|
|
123
|
+
`agent.session(id, user_id=...)` binds one (user, session) scope to the verbs an agent loop needs between turns: `resume()` returns the context pack as `system` plus the transcript tail as `messages`; `append(*turns)` writes the transcript now and runs `memory.set_from_messages` every `flush_every` turns; `offload()` / `fetch()` park a large tool result and read it back by pattern; `note()` appends to working memory; `close()` flushes. It is an async context manager; `SyncAgent.session()` blocks.
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
async with agent.session("thread-42", user_id="u1") as s:
|
|
127
|
+
resumed = await s.resume(query="resume the billing migration")
|
|
128
|
+
system_prompt, history = resumed.system, resumed.messages
|
|
129
|
+
await s.append({"role": "user", "content": text}, {"role": "assistant", "content": reply})
|
|
130
|
+
blob = await s.offload(build_log, summary="pytest run 812")
|
|
131
|
+
await s.note(blob["pointer"])
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
`agent.tools(user_id=..., session_id=...)` gives a model six loom verbs — `loom_remember`, `loom_recall`, `loom_ask`, `loom_offload`, `loom_fetch`, `loom_note` — as `definitions("openai" | "anthropic" | "generic")` and one `await execute(name, arguments)` that returns the string the model reads. The schemas are the same as the TypeScript SDK's.
|
|
135
|
+
|
|
136
|
+
## Retries and logging
|
|
137
|
+
|
|
138
|
+
The retry policy is one frozen dataclass, set on the Agent and overridable per call with a `RetryPolicy` or a dict of its fields; every field is validated and named when wrong. Defaults: 3 attempts; 0.1 s backoff doubling to 5 s with ±25 % jitter; 408 and 5xx retried for registry-idempotent ops (any other op only on a 408 or a 503 `AUTH_UNAVAILABLE`, which the server answers before running it); connection errors retried; a read timeout retried only when the registry marks the op idempotent (the server dedups its `Idempotency-Key`); a `Retry-After` on a retried status honoured up to 60 s. A 429 is paced, not retried.
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from loom import Agent, RetryPolicy
|
|
142
|
+
|
|
143
|
+
agent = Agent(
|
|
144
|
+
"acme",
|
|
145
|
+
"support",
|
|
146
|
+
"bot",
|
|
147
|
+
retry=RetryPolicy(max_attempts=5, total_backoff_budget_s=30),
|
|
148
|
+
consumer="support-bot",
|
|
149
|
+
) # the label every ledger row carries
|
|
150
|
+
await agent.call("memory.get", memory_key="k", retry={"max_attempts": 1}) # this call: no retries
|
|
151
|
+
await agent.call("memory.set_from_messages", messages=msgs, retry={"retry_timeouts": "always"})
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The SDK logs through the stdlib logger `loom` (a `NullHandler` by default; your logging config routes it): one line per completed call at INFO (`/v1/memory.get 200 12 ms attempts=2 rid=…`), retries and rate-limit waits at WARNING, the final failure at ERROR, the request headers at DEBUG. `LOOM_LOG_LEVEL` (any stdlib level name — `debug`, `info`, `warning`, `error`, `critical` — or `off`) sets the logger's level when your application has not; a value it cannot read is a warning, not an import error. Credential headers are redacted to their scheme and last four characters, and a filter on the logger rewrites any bearer token that reaches a record anyway.
|
|
155
|
+
|
|
156
|
+
## Examples
|
|
157
|
+
|
|
158
|
+
[`examples/agent_memory.py`](./examples/agent_memory.py) — probe → remember ×3 → recall → ask with citations → outcome → typed errors, with its actual run in [`examples/README.md`](./examples/README.md). The TypeScript SDK ships the same example.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
Apache-2.0. See [LICENSE](https://github.com/ClickHouse/loom/blob/main/LICENSE).
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
Runnable, self-contained scripts for `clickhouse-loom`; each was executed against a live Loom before it landed here and the output below is the actual run. Every script reads `LOOM_BASE_URL`, `LOOM_API_KEY` and `LOOM_ORG` from the environment and registers a throwaway namespace. The TypeScript SDK ships the twin of `agent_memory.py` (and a session-resume example) under `sdk/typescript/examples/`.
|
|
4
|
+
|
|
5
|
+
## agent_memory.py
|
|
6
|
+
|
|
7
|
+
An agent that remembers what a user said, recalls it by meaning, answers with citations (or abstains), and tells loom which memories it used.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
LOOM_BASE_URL=https://loom.example LOOM_API_KEY=… LOOM_ORG=acme python agent_memory.py
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`Agent(org, namespace, agent)` stamps the identity tuple on every call; `user_id` is the per-call scope.
|
|
14
|
+
|
|
15
|
+
1. `Agent.probe()` — the deployment serves `memory.set/search/ask/outcome`, and whether it has ops this SDK version does not know.
|
|
16
|
+
2. `namespace.register` — the throwaway namespace; a refusal because it already exists is ignored.
|
|
17
|
+
3. `memory.set` ×3 — three facts from two conversations; dedup, conflict detection and validity are the server's job.
|
|
18
|
+
4. `memory.search` — semantic search with similarity per hit.
|
|
19
|
+
5. `Agent.call("memory.ask", …)` — a grounded answer that cites `[memory_key]`, or `abstain=True` when the memories do not say.
|
|
20
|
+
6. `memory.outcome_by_key` — the feedback loop: cited memories are marked `used`.
|
|
21
|
+
7. `loom.ops.OPS` names every op; a missing key reads as `found=False`; an unknown op is a `NotFound`.
|
|
22
|
+
8. `memory.delete` ×3 — in a `finally`, so the three memories are gone even when a step fails. The namespace stays registered: dropping it takes an admin.
|
|
23
|
+
|
|
24
|
+
A run against an isolated Loom server on ClickHouse Cloud, gpt-4o-mini as the synthesis model. The server build, the similarities (they depend on the embedder) and the answer text (written by the model) differ from run to run; the rest of the output does not:
|
|
25
|
+
|
|
26
|
+
```text
|
|
27
|
+
server 2688e2476: ok=True, ops the SDK does not know: 0
|
|
28
|
+
recall 0.51 [seat_pref] "The user prefers an aisle seat on flights over three hours." (#seat_pref)
|
|
29
|
+
recall 0.23 [meal_pref] "The user asked for a vegetarian meal on their last two bookings." (#meal_pref)
|
|
30
|
+
recall 0.21 [airline_status] "The user holds gold status with Lufthansa (as of 2026-08)." (#airline_status)
|
|
31
|
+
ask → abstain=False cited=['meal_pref', 'seat_pref', 'airline_status']
|
|
32
|
+
Request an aisle seat, since the user prefers an aisle seat on flights over three hours and a flight to Tokyo well exceeds that [seat_pref]. For the meal, request a vegetarian meal, matching what the user asked for on their last two bookings [meal_pref].
|
|
33
|
+
|
|
34
|
+
Also note the user holds gold status with Lufthansa (as of 2026-08), which may help with seat selection [airline_status].
|
|
35
|
+
memory.search is idempotent: True; role viewer
|
|
36
|
+
memory.get of a missing key → found=False
|
|
37
|
+
unknown op → NotFound (RESOURCE_NOT_FOUND)
|
|
38
|
+
```
|