cilow 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.
cilow-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Generalized Labs
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.
cilow-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,161 @@
1
+ Metadata-Version: 2.4
2
+ Name: cilow
3
+ Version: 0.1.0
4
+ Summary: Python client SDK for Cilow — the verifiable context layer for AI agents.
5
+ License: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/Generalized-Labs/cilow
7
+ Project-URL: Repository, https://github.com/Generalized-Labs/cilow
8
+ Keywords: cilow,ai,agents,memory,context,bitemporal,abstention
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Libraries
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Provides-Extra: httpx
18
+ Requires-Dist: httpx>=0.27; extra == "httpx"
19
+ Dynamic: license-file
20
+
21
+ # cilow — Python
22
+
23
+ The Python client for **Cilow**, the verifiable context layer for AI agents. Point it at a
24
+ running [`cilow-serve`](../../docs/user_guide/mcp_server.md) and call **four core verbs** —
25
+ `ingest`, `context_pack`, `forget`, `explain` — the same four the MCP core profile advertises.
26
+ The headline feature is **calibrated deferral**: every read tells you when the engine
27
+ *doesn't know* instead of fabricating an answer.
28
+
29
+ ## Install
30
+
31
+ ```sh
32
+ cd sdk/python && pip install -e .
33
+ ```
34
+
35
+ Python 3.9+. **Zero required dependencies** — the client uses only the standard library
36
+ (`urllib` + `json`). `httpx` is an optional extra (`pip install 'cilow[httpx]'`) for users
37
+ who want pooling/async; it is not needed for the default client.
38
+
39
+ ## Point it at a server
40
+
41
+ ```sh
42
+ cargo build --profile fast --features serve --bin cilow-serve
43
+ CILOW_DB=/tmp/cilow.log CILOW_TOKENS="demo:1:1" ./target/fast/cilow-serve
44
+ # listening on http://0.0.0.0:8080 · bearer token "demo"
45
+ ```
46
+
47
+ The token maps to a tenant scope that the server **stamps** onto every request — a client can
48
+ never read another tenant's memory, and a client-supplied `scope` is ignored over HTTP.
49
+
50
+ ## Five lines
51
+
52
+ ```python
53
+ from cilow import CilowClient
54
+
55
+ cilow = CilowClient(base_url="http://localhost:8080", token="demo")
56
+ cilow.ingest(facts=[{"subject": "Maya", "predicate": "employer", "object": "Acme"}])
57
+ r = cilow.context_pack("where does Maya work", anchor="Maya", attribute="employer")
58
+ print(r.reason if r.abstained else r.pack) # the injectible pack, citations on r.citations
59
+ print(cilow.explain(r.trace_id).report.grounded) # why it surfaced, vs the tenant threshold
60
+ ```
61
+
62
+ ## The four core verbs
63
+
64
+ | Verb | Signature | Returns | What it does |
65
+ |------|-----------|---------|--------------|
66
+ | `ingest` | `ingest(*, facts= \| text= \| url= \| content_base64=, mime=, subject_hint=, metadata=, source=, raw_context=, branch=, scope=, source_id=, observed_at=)` | `IngestResponse` | The **one write door**. Never rejects: known kinds extract, unknown kinds are retained and recallable. A new value for an exclusive attribute *supersedes* the old one (history stays queryable). |
67
+ | `context_pack` | `context_pack(query, *, scope=, now=, as_of=, anchor=, attribute=)` | `ContextPackResponse` | The **product read**: a ready-to-inject `pack`, structured `citations` / `claims` with `is_current`, and the faithfulness fields `abstained` / `reason_code` / `grounding` / `pack_sufficient` / `as_of` / `trace_id`. No free-form synthesis. |
68
+ | `forget` | `forget(entity, *, attribute=, value=, erase=, scope=, at=)` | `ForgetResponse` | **Withdraw**, not erase history: recall stops returning it; as-of-T reads before `at` still see it. `erase=True` is the destructive right-to-be-forgotten path. |
69
+ | `explain` | `explain(trace_id, *, scope=)` | `ExplainResponse` | **Why** a pack/recall surfaced what it surfaced: the cited claims (labels resolved, inclusion probability each), `best_nonconformity` vs the tenant threshold `q_hat`, and `report.grounded`. `found=False` + `error` is in-band. |
70
+
71
+ Plus `health()` (liveness probe, no auth). All responses are frozen `dataclass`es.
72
+
73
+ `ingest` takes **exactly one** content form. `source_id` (the idempotency key the wire requires)
74
+ defaults to a **content hash** — `ingest_source_id(...)` — so re-sending the same payload is a
75
+ no-op; the key actually sent is echoed on `.source_id`. `.kind` tells you which server path ran
76
+ (`"facts"` → the `remember` receipt on `.remember`; `"content"` → the raw-durable receipt on
77
+ `.content` with `blob_id` / `detected` / `reader_error`).
78
+
79
+ `anchor` (an entity surface form like `"Maya"`) + `attribute` (a predicate like `"employer"`)
80
+ take the exact-key **fast path**. Omit them for free-text semantic reads — same response shape.
81
+
82
+ ### Full profile / legacy aliases
83
+
84
+ The engine's full tool profile (`CILOW_MCP_PROFILE=full`) also advertises the older verbs, and
85
+ the client keeps them as aliases with their original receipts:
86
+
87
+ | Alias | Signature | Returns |
88
+ |-------|-----------|---------|
89
+ | `remember` | `remember(facts, *, scope=, source=, source_id=, observed_at=, raw_context=, branch=)` | `RememberResponse` |
90
+ | `recall` | `recall(query, *, scope=, as_of=, now=, anchor=, attribute=, branch=)` | `RecallResponse` |
91
+ | `answer` | `answer(query, *, scope=, now=, anchor=, attribute=, branch=)` | `AnswerResponse` |
92
+ | `timeline` | `timeline(entity, *, scope=, at=, t_from=, t_to=)` | `list[TimelineEntry]` |
93
+ | `track_entity` | `track_entity(name, *, scope=, at=)` | `TrackEntityResponse` |
94
+
95
+ Also available: `remember_text`, `ingest_image` / `ingest_audio` / `ingest_pdf` /
96
+ `ingest_structured`, `save` / `ingest_any`, `feedback`, `consolidate`, `fork` / `branch_list`,
97
+ `blob_get` / `blob_meta` / `blob_list`, and the `client.memories.*` id-based REST surface.
98
+
99
+ ### Time is in microseconds
100
+
101
+ Every time field (`observed_at`, `as_of`, `now`, `at`, `t_from`, `t_to`, and the `valid_from`
102
+ / `valid_until` on timeline entries) is **epoch microseconds (µs)**, matching the engine. They
103
+ default to "now". Use the exported `now_micros()` helper:
104
+
105
+ ```python
106
+ from cilow import now_micros
107
+ t = now_micros()
108
+ cilow.remember(facts, observed_at=t)
109
+ past = cilow.recall("...", as_of=t - 86_400_000_000, now=t) # a day ago
110
+ ```
111
+
112
+ ## The deferral contract
113
+
114
+ `context_pack` (and the `recall` / `answer` aliases) **never raise** for a deferral — they return
115
+ a normal response with a boolean flag. When `abstained` is `True`, the pack / claims / citations
116
+ are empty and `reason_code` says why: `below_threshold` / `no_candidates` are a *calibrated*
117
+ abstain (memory genuinely lacks grounded context — do not fabricate past it), while
118
+ `provider_unavailable` is an *infrastructure* abstain (retry when the provider recovers). Branch
119
+ with `r.is_calibrated_abstain` / `r.is_infrastructure_abstain` rather than matching strings.
120
+
121
+ On `answer` / `context_pack` an abstain also names **which layer stopped it** — `r.terminal_layer`
122
+ (`structural` | `gate` | `provider` | `reader` | `verifier`; `r.stopped_at` is the same thing gated on
123
+ `abstained`). Only `provider` is retryable. Both surfaces also carry `r.evidence`: the claim, span,
124
+ and verbatim lanes collapsed into one list ordered by fused cross-lane rank (`Evidence.origins`
125
+ says which lanes agreed; `Evidence.structure` is present when a typed claim backs the unit). It is
126
+ present on abstains too — the raw lanes have no standing at the gate, but you may still read them.
127
+
128
+ ```python
129
+ r = cilow.context_pack("what is Maya's salary", anchor="Maya", attribute="salary")
130
+ if r.abstained:
131
+ # r.pack is empty; r.reason explains the configured gate decision.
132
+ return f"I don't have that in memory ({r.reason})."
133
+ return r.pack
134
+ ```
135
+
136
+ Every read carries a `trace_id`. Hand it to `explain` for the audit trail — the cited claims,
137
+ the tenant's conformal threshold `q_hat`, the best candidate's `best_nonconformity`, and the
138
+ `margin` (`q̂ − n`, ≥0 grounded, <0 a gap) — or to `feedback` so memory learns from the outcome.
139
+ This is the difference between "I don't know" and a confident wrong answer.
140
+
141
+ ## Errors
142
+
143
+ `CilowError` is raised for genuine failures — auth (`401` / JSON-RPC `-32001`), bad params,
144
+ transport errors, malformed responses. A deferral is not an error.
145
+
146
+ ```python
147
+ from cilow import CilowError
148
+ try:
149
+ cilow.recall("...")
150
+ except CilowError as e:
151
+ if e.is_unauthorized: # bad/expired token
152
+ ...
153
+ ```
154
+
155
+ ## Develop
156
+
157
+ ```sh
158
+ pip install -e .
159
+ python3 -m pytest -q tests # mocks the HTTP layer (no server needed)
160
+ python examples/quickstart.py # runs against a live server
161
+ ```
cilow-0.1.0/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # cilow — Python
2
+
3
+ The Python client for **Cilow**, the verifiable context layer for AI agents. Point it at a
4
+ running [`cilow-serve`](../../docs/user_guide/mcp_server.md) and call **four core verbs** —
5
+ `ingest`, `context_pack`, `forget`, `explain` — the same four the MCP core profile advertises.
6
+ The headline feature is **calibrated deferral**: every read tells you when the engine
7
+ *doesn't know* instead of fabricating an answer.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ cd sdk/python && pip install -e .
13
+ ```
14
+
15
+ Python 3.9+. **Zero required dependencies** — the client uses only the standard library
16
+ (`urllib` + `json`). `httpx` is an optional extra (`pip install 'cilow[httpx]'`) for users
17
+ who want pooling/async; it is not needed for the default client.
18
+
19
+ ## Point it at a server
20
+
21
+ ```sh
22
+ cargo build --profile fast --features serve --bin cilow-serve
23
+ CILOW_DB=/tmp/cilow.log CILOW_TOKENS="demo:1:1" ./target/fast/cilow-serve
24
+ # listening on http://0.0.0.0:8080 · bearer token "demo"
25
+ ```
26
+
27
+ The token maps to a tenant scope that the server **stamps** onto every request — a client can
28
+ never read another tenant's memory, and a client-supplied `scope` is ignored over HTTP.
29
+
30
+ ## Five lines
31
+
32
+ ```python
33
+ from cilow import CilowClient
34
+
35
+ cilow = CilowClient(base_url="http://localhost:8080", token="demo")
36
+ cilow.ingest(facts=[{"subject": "Maya", "predicate": "employer", "object": "Acme"}])
37
+ r = cilow.context_pack("where does Maya work", anchor="Maya", attribute="employer")
38
+ print(r.reason if r.abstained else r.pack) # the injectible pack, citations on r.citations
39
+ print(cilow.explain(r.trace_id).report.grounded) # why it surfaced, vs the tenant threshold
40
+ ```
41
+
42
+ ## The four core verbs
43
+
44
+ | Verb | Signature | Returns | What it does |
45
+ |------|-----------|---------|--------------|
46
+ | `ingest` | `ingest(*, facts= \| text= \| url= \| content_base64=, mime=, subject_hint=, metadata=, source=, raw_context=, branch=, scope=, source_id=, observed_at=)` | `IngestResponse` | The **one write door**. Never rejects: known kinds extract, unknown kinds are retained and recallable. A new value for an exclusive attribute *supersedes* the old one (history stays queryable). |
47
+ | `context_pack` | `context_pack(query, *, scope=, now=, as_of=, anchor=, attribute=)` | `ContextPackResponse` | The **product read**: a ready-to-inject `pack`, structured `citations` / `claims` with `is_current`, and the faithfulness fields `abstained` / `reason_code` / `grounding` / `pack_sufficient` / `as_of` / `trace_id`. No free-form synthesis. |
48
+ | `forget` | `forget(entity, *, attribute=, value=, erase=, scope=, at=)` | `ForgetResponse` | **Withdraw**, not erase history: recall stops returning it; as-of-T reads before `at` still see it. `erase=True` is the destructive right-to-be-forgotten path. |
49
+ | `explain` | `explain(trace_id, *, scope=)` | `ExplainResponse` | **Why** a pack/recall surfaced what it surfaced: the cited claims (labels resolved, inclusion probability each), `best_nonconformity` vs the tenant threshold `q_hat`, and `report.grounded`. `found=False` + `error` is in-band. |
50
+
51
+ Plus `health()` (liveness probe, no auth). All responses are frozen `dataclass`es.
52
+
53
+ `ingest` takes **exactly one** content form. `source_id` (the idempotency key the wire requires)
54
+ defaults to a **content hash** — `ingest_source_id(...)` — so re-sending the same payload is a
55
+ no-op; the key actually sent is echoed on `.source_id`. `.kind` tells you which server path ran
56
+ (`"facts"` → the `remember` receipt on `.remember`; `"content"` → the raw-durable receipt on
57
+ `.content` with `blob_id` / `detected` / `reader_error`).
58
+
59
+ `anchor` (an entity surface form like `"Maya"`) + `attribute` (a predicate like `"employer"`)
60
+ take the exact-key **fast path**. Omit them for free-text semantic reads — same response shape.
61
+
62
+ ### Full profile / legacy aliases
63
+
64
+ The engine's full tool profile (`CILOW_MCP_PROFILE=full`) also advertises the older verbs, and
65
+ the client keeps them as aliases with their original receipts:
66
+
67
+ | Alias | Signature | Returns |
68
+ |-------|-----------|---------|
69
+ | `remember` | `remember(facts, *, scope=, source=, source_id=, observed_at=, raw_context=, branch=)` | `RememberResponse` |
70
+ | `recall` | `recall(query, *, scope=, as_of=, now=, anchor=, attribute=, branch=)` | `RecallResponse` |
71
+ | `answer` | `answer(query, *, scope=, now=, anchor=, attribute=, branch=)` | `AnswerResponse` |
72
+ | `timeline` | `timeline(entity, *, scope=, at=, t_from=, t_to=)` | `list[TimelineEntry]` |
73
+ | `track_entity` | `track_entity(name, *, scope=, at=)` | `TrackEntityResponse` |
74
+
75
+ Also available: `remember_text`, `ingest_image` / `ingest_audio` / `ingest_pdf` /
76
+ `ingest_structured`, `save` / `ingest_any`, `feedback`, `consolidate`, `fork` / `branch_list`,
77
+ `blob_get` / `blob_meta` / `blob_list`, and the `client.memories.*` id-based REST surface.
78
+
79
+ ### Time is in microseconds
80
+
81
+ Every time field (`observed_at`, `as_of`, `now`, `at`, `t_from`, `t_to`, and the `valid_from`
82
+ / `valid_until` on timeline entries) is **epoch microseconds (µs)**, matching the engine. They
83
+ default to "now". Use the exported `now_micros()` helper:
84
+
85
+ ```python
86
+ from cilow import now_micros
87
+ t = now_micros()
88
+ cilow.remember(facts, observed_at=t)
89
+ past = cilow.recall("...", as_of=t - 86_400_000_000, now=t) # a day ago
90
+ ```
91
+
92
+ ## The deferral contract
93
+
94
+ `context_pack` (and the `recall` / `answer` aliases) **never raise** for a deferral — they return
95
+ a normal response with a boolean flag. When `abstained` is `True`, the pack / claims / citations
96
+ are empty and `reason_code` says why: `below_threshold` / `no_candidates` are a *calibrated*
97
+ abstain (memory genuinely lacks grounded context — do not fabricate past it), while
98
+ `provider_unavailable` is an *infrastructure* abstain (retry when the provider recovers). Branch
99
+ with `r.is_calibrated_abstain` / `r.is_infrastructure_abstain` rather than matching strings.
100
+
101
+ On `answer` / `context_pack` an abstain also names **which layer stopped it** — `r.terminal_layer`
102
+ (`structural` | `gate` | `provider` | `reader` | `verifier`; `r.stopped_at` is the same thing gated on
103
+ `abstained`). Only `provider` is retryable. Both surfaces also carry `r.evidence`: the claim, span,
104
+ and verbatim lanes collapsed into one list ordered by fused cross-lane rank (`Evidence.origins`
105
+ says which lanes agreed; `Evidence.structure` is present when a typed claim backs the unit). It is
106
+ present on abstains too — the raw lanes have no standing at the gate, but you may still read them.
107
+
108
+ ```python
109
+ r = cilow.context_pack("what is Maya's salary", anchor="Maya", attribute="salary")
110
+ if r.abstained:
111
+ # r.pack is empty; r.reason explains the configured gate decision.
112
+ return f"I don't have that in memory ({r.reason})."
113
+ return r.pack
114
+ ```
115
+
116
+ Every read carries a `trace_id`. Hand it to `explain` for the audit trail — the cited claims,
117
+ the tenant's conformal threshold `q_hat`, the best candidate's `best_nonconformity`, and the
118
+ `margin` (`q̂ − n`, ≥0 grounded, <0 a gap) — or to `feedback` so memory learns from the outcome.
119
+ This is the difference between "I don't know" and a confident wrong answer.
120
+
121
+ ## Errors
122
+
123
+ `CilowError` is raised for genuine failures — auth (`401` / JSON-RPC `-32001`), bad params,
124
+ transport errors, malformed responses. A deferral is not an error.
125
+
126
+ ```python
127
+ from cilow import CilowError
128
+ try:
129
+ cilow.recall("...")
130
+ except CilowError as e:
131
+ if e.is_unauthorized: # bad/expired token
132
+ ...
133
+ ```
134
+
135
+ ## Develop
136
+
137
+ ```sh
138
+ pip install -e .
139
+ python3 -m pytest -q tests # mocks the HTTP layer (no server needed)
140
+ python examples/quickstart.py # runs against a live server
141
+ ```
@@ -0,0 +1,116 @@
1
+ """cilow — Python client for Cilow, the verifiable context layer for AI agents.
2
+
3
+ Point it at a running ``cilow-serve`` and call the FOUR core verbs (the MCP core profile):
4
+ ``ingest`` (the one write door: facts | text | bytes | url), ``context_pack`` (the product read:
5
+ injectible pack + citations with ``is_current`` + ``abstained`` / ``grounding`` / ``trace_id``),
6
+ ``forget`` (withdraw), and ``explain`` (why a read surfaced what it surfaced, via ``trace_id``).
7
+ ``remember`` / ``recall`` / ``answer`` / ``timeline`` / ``track_entity`` remain as full-profile /
8
+ legacy aliases. The headline feature is CALIBRATED ABSTENTION: reads return ``abstained=True``
9
+ when the engine does not know, instead of fabricating. Gate your agent on that flag.
10
+
11
+ from cilow import CilowClient
12
+
13
+ cilow = CilowClient(base_url="http://localhost:8080", token="demo")
14
+ cilow.ingest(facts=[{"subject": "Maya", "predicate": "employer", "object": "Acme"}])
15
+ r = cilow.context_pack("where does Maya work", anchor="Maya", attribute="employer")
16
+ print(r.reason if r.abstained else r.pack)
17
+ why = cilow.explain(r.trace_id) # cited claims + grounding vs the tenant threshold
18
+ """
19
+
20
+ from .client import CilowClient, ingest_source_id, now_micros
21
+ from .errors import CilowError
22
+ from .types import (
23
+ AnswerResponse,
24
+ Branch,
25
+ Citation,
26
+ CitationPart,
27
+ Claim,
28
+ ConsolidateResponse,
29
+ Fact,
30
+ FeedbackResponse,
31
+ ContextPackResponse,
32
+ ExplainCited,
33
+ ExplainReport,
34
+ ExplainResponse,
35
+ ForgetResponse,
36
+ ForkResponse,
37
+ IngestAnyResponse,
38
+ IngestResponse,
39
+ IngestAudioResponse,
40
+ IngestImageResponse,
41
+ IngestPdfResponse,
42
+ IngestStructuredResponse,
43
+ Outcome,
44
+ ReaderUsage,
45
+ ReasonCode,
46
+ TerminalLayer,
47
+ TERMINAL_LAYERS,
48
+ Evidence,
49
+ EvidenceStructure,
50
+ EvidenceProvenance,
51
+ Receipt,
52
+ RecallResponse,
53
+ RememberResponse,
54
+ RememberTextResponse,
55
+ Scope,
56
+ Source,
57
+ TimelineEntry,
58
+ TrackEntityResponse,
59
+ Workspace,
60
+ EvidenceRevision,
61
+ ContextProgram,
62
+ ContextProgramV2,
63
+ ContextTrace,
64
+ MemoryProposal,
65
+ )
66
+
67
+ __version__ = "0.1.0"
68
+
69
+ __all__ = [
70
+ "CilowClient",
71
+ "CilowError",
72
+ "now_micros",
73
+ "ingest_source_id",
74
+ "Scope",
75
+ "Fact",
76
+ "Source",
77
+ "RememberResponse",
78
+ "Claim",
79
+ "Receipt",
80
+ "RecallResponse",
81
+ "Citation",
82
+ "CitationPart",
83
+ "AnswerResponse",
84
+ "ReaderUsage",
85
+ "ReasonCode",
86
+ "TerminalLayer",
87
+ "TERMINAL_LAYERS",
88
+ "Evidence",
89
+ "EvidenceStructure",
90
+ "EvidenceProvenance",
91
+ "TimelineEntry",
92
+ "TrackEntityResponse",
93
+ "Outcome",
94
+ "FeedbackResponse",
95
+ "ConsolidateResponse",
96
+ "RememberTextResponse",
97
+ "IngestImageResponse",
98
+ "IngestAudioResponse",
99
+ "IngestPdfResponse",
100
+ "IngestStructuredResponse",
101
+ "IngestAnyResponse",
102
+ "ForgetResponse",
103
+ "ContextPackResponse",
104
+ "IngestResponse",
105
+ "ExplainResponse",
106
+ "ExplainReport",
107
+ "ExplainCited",
108
+ "Branch",
109
+ "ForkResponse",
110
+ "Workspace",
111
+ "EvidenceRevision",
112
+ "ContextProgram",
113
+ "ContextProgramV2",
114
+ "ContextTrace",
115
+ "MemoryProposal",
116
+ ]
@@ -0,0 +1,37 @@
1
+ """``cilow.adapters`` — framework bindings over the ONE :class:`CilowMemory` contract.
2
+
3
+ Every binding is a thin shim that maps a framework's memory/retriever/tool interface onto the five
4
+ contract verbs (``ingest`` / ``recall`` / ``answer`` / ``reset`` / ``health``) and re-exposes the
5
+ differentiator unchanged: ``abstained`` + ``reason_code`` + the ``grounded`` signal.
6
+
7
+ from cilow.adapters import CilowMemoryClient
8
+ from cilow.adapters import openai, anthropic, langchain
9
+
10
+ Branch on an adapter result's ``.is_calibrated_abstain`` / ``.is_infrastructure_abstain`` properties.
11
+ """
12
+
13
+ from . import anthropic, langchain, openai
14
+ from .memory import (
15
+ AnswerResult,
16
+ CilowMemory,
17
+ CilowMemoryClient,
18
+ IngestResult,
19
+ MemoryHit,
20
+ RecallResult,
21
+ )
22
+ from .remaining import REMAINING_ADAPTERS, make_autogen_memory, make_llamaindex_retriever
23
+
24
+ __all__ = [
25
+ "CilowMemory",
26
+ "CilowMemoryClient",
27
+ "MemoryHit",
28
+ "RecallResult",
29
+ "AnswerResult",
30
+ "IngestResult",
31
+ "openai",
32
+ "anthropic",
33
+ "langchain",
34
+ "REMAINING_ADAPTERS",
35
+ "make_llamaindex_retriever",
36
+ "make_autogen_memory",
37
+ ]