hebbrix 2.8.0__tar.gz → 2.10.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.
- {hebbrix-2.8.0 → hebbrix-2.10.0}/CHANGELOG.md +12 -0
- {hebbrix-2.8.0/hebbrix.egg-info → hebbrix-2.10.0}/PKG-INFO +14 -5
- {hebbrix-2.8.0 → hebbrix-2.10.0}/README.md +13 -4
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix/__init__.py +1 -1
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix/answers.py +131 -14
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix/client.py +1 -1
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix/sync_client.py +1 -1
- {hebbrix-2.8.0 → hebbrix-2.10.0/hebbrix.egg-info}/PKG-INFO +14 -5
- {hebbrix-2.8.0 → hebbrix-2.10.0}/pyproject.toml +1 -1
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_answer_context.py +38 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_answer_decision.py +127 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_customer_developer_experience.py +1 -1
- {hebbrix-2.8.0 → hebbrix-2.10.0}/LICENSE +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/MANIFEST.in +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/contracts/openapi-routes.json +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/docs/native-experience-operations.md +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/examples/native_reflection_worker.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix/_advice.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix/chat.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix/exceptions.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix/execution.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix/experience.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix/models.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix/openai_reflection.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix/reflection_worker.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix/resources.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix/workflow.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix.egg-info/SOURCES.txt +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix.egg-info/dependency_links.txt +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix.egg-info/entry_points.txt +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix.egg-info/requires.txt +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/hebbrix.egg-info/top_level.txt +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/setup.cfg +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_advanced_resources.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_advisor_integrity.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_chat_answer_options.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_compact_search_default.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_evidence_loop_resource.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_evidence_safety_boundary.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_execution_permission.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_experience_request.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_experience_workflow.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_followup_helpers.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_memories_resource.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_openai_reflection.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_openapi_parity.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_outcome_advice_resource.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_procedural_resource.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_reflection_worker_cli.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_release_version.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_sync_client.py +0 -0
- {hebbrix-2.8.0 → hebbrix-2.10.0}/tests/test_workflow_route_contract.py +0 -0
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.10.0 — 2026-11-12 (applicable rules, consistent abstention flags)
|
|
4
|
+
|
|
5
|
+
- An `unverified` search response whose rows include `evidence_role: "applicable_rule"` (server 1.4.27) returns reason `applicable_rule` and action `use_as_context`, those rules first in `decision.context`: policy that speaks to the asked case but that the API has not verified decides it. Let your model apply it, or call `reason`. A rule is never an authorization; `authorization_not_verifiable` still comes first.
|
|
6
|
+
- `history=True` no longer overrides an explicit abstention flag on an `answerable` response: a response marked `answerable` that also sets `no_match`, `abstain_recommended` or `decision_abstained` contradicts itself and is declined in every mode, with that flag as the reason. History mode still answers a `superseded` response from its earlier versions (its flags concern the present), never one with `no_match`.
|
|
7
|
+
|
|
8
|
+
## 2.9.0 — 2026-11-11 (high-stakes readiness, history and suggestions)
|
|
9
|
+
|
|
10
|
+
- `should_answer(response, require_ready=True)` (also on `usable_memories` and `answer_context`): for high-stakes flows, holds the answer with action `retry` and reason `index_not_ready` until `indexing.status` is `ready` and `indexing.answer_risk` is `none`. A response that does not report its indexing is not ready.
|
|
11
|
+
- Behaviour change: `history=True` now applies only when the server answered or marked the response `superseded`; it no longer overrides `unverified`, `no_relevant_memory` or `indexing`.
|
|
12
|
+
- A Reason result for a suggestion or plan (`grounding.answerability: "context_only"`) returns action `use_as_context` with its memories in `context`; `answer_context` lists them as context that is neither an established fact nor permission to act.
|
|
13
|
+
- `answer_context` says when recent writes could not be reflected in the profile (`projection.status: "failed"`, server 1.4.25).
|
|
14
|
+
|
|
3
15
|
## 2.8.0 — 2026-11-11 (answer decisions and answer context)
|
|
4
16
|
|
|
5
17
|
- New `hebbrix.should_answer(response)`: decides in code whether a `search_with_proof()` or `reason()` response may be answered from, returning an `AnswerDecision` with `action` (`answer`, `say_unknown`, `abstain`, `verify_authorization`, `ask_user`, `retry` or `say_no_longer_current`), `reason`, the usable `memories` and the `context` rows never to answer from. `history=True` counts superseded and historical versions for questions about the past.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hebbrix
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.10.0
|
|
4
4
|
Summary: Typed Python client for Hebbrix memory, retrieval, and outcome-learning APIs
|
|
5
5
|
Author-email: Hebbrix Team <support@hebbrix.com>
|
|
6
6
|
Maintainer-email: Hebbrix Team <support@hebbrix.com>
|
|
@@ -65,14 +65,14 @@ Dynamic: license-file
|
|
|
65
65
|
|
|
66
66
|
Typed Python client for Hebbrix memory, retrieval, and outcome-learning APIs.
|
|
67
67
|
|
|
68
|
-
The current stable package is **2.
|
|
68
|
+
The current stable package is **2.10.0**. Start with memory storage and search, or
|
|
69
69
|
the three-call outcome-learning workflow below. Advanced evidence and execution
|
|
70
70
|
permission transports are opt-in; installing the SDK never permits an action.
|
|
71
71
|
|
|
72
72
|
## Install
|
|
73
73
|
|
|
74
74
|
```bash
|
|
75
|
-
pip install hebbrix==2.
|
|
75
|
+
pip install hebbrix==2.10.0
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
Python 3.8+ is supported. `MemoryClient` is asynchronous. `SyncMemoryClient`
|
|
@@ -145,8 +145,17 @@ profile's `scope`, and says so when the profile is still being updated
|
|
|
145
145
|
is not taken as absent. When the decision is not to answer it returns the
|
|
146
146
|
profile alone. `usable_memories(response)` returns just the rows. Pass
|
|
147
147
|
`history=True` for a question about the past, when superseded and historical
|
|
148
|
-
versions should count
|
|
149
|
-
|
|
148
|
+
versions should count (it never overrides `unverified`, `no_relevant_memory`,
|
|
149
|
+
`indexing` or `conflicting`). Pass `require_ready=True` for a high-stakes flow:
|
|
150
|
+
the answer is then also held, with action `retry`, until `indexing.status` is
|
|
151
|
+
`ready` and `indexing.answer_risk` is `none`. A Reason suggestion or plan
|
|
152
|
+
(`context_only`) returns action `use_as_context`: its memories shape what your
|
|
153
|
+
model suggests, and are never a fact or a permission. An `unverified` search
|
|
154
|
+
whose rows include `evidence_role: "applicable_rule"` returns reason
|
|
155
|
+
`applicable_rule` and action `use_as_context`: the rule speaks to the asked
|
|
156
|
+
case but the API has not verified it decides it; let your model apply it, or
|
|
157
|
+
call `reason()`. `reason()` takes
|
|
158
|
+
`deadline_ms`; a `timed_out` response is an abstention. `verify_authorization` means the returned rule limits the action
|
|
150
159
|
to a group the store cannot place the user in: use the rule, and check the
|
|
151
160
|
permission in your own system.
|
|
152
161
|
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Typed Python client for Hebbrix memory, retrieval, and outcome-learning APIs.
|
|
4
4
|
|
|
5
|
-
The current stable package is **2.
|
|
5
|
+
The current stable package is **2.10.0**. Start with memory storage and search, or
|
|
6
6
|
the three-call outcome-learning workflow below. Advanced evidence and execution
|
|
7
7
|
permission transports are opt-in; installing the SDK never permits an action.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
pip install hebbrix==2.
|
|
12
|
+
pip install hebbrix==2.10.0
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
Python 3.8+ is supported. `MemoryClient` is asynchronous. `SyncMemoryClient`
|
|
@@ -82,8 +82,17 @@ profile's `scope`, and says so when the profile is still being updated
|
|
|
82
82
|
is not taken as absent. When the decision is not to answer it returns the
|
|
83
83
|
profile alone. `usable_memories(response)` returns just the rows. Pass
|
|
84
84
|
`history=True` for a question about the past, when superseded and historical
|
|
85
|
-
versions should count
|
|
86
|
-
|
|
85
|
+
versions should count (it never overrides `unverified`, `no_relevant_memory`,
|
|
86
|
+
`indexing` or `conflicting`). Pass `require_ready=True` for a high-stakes flow:
|
|
87
|
+
the answer is then also held, with action `retry`, until `indexing.status` is
|
|
88
|
+
`ready` and `indexing.answer_risk` is `none`. A Reason suggestion or plan
|
|
89
|
+
(`context_only`) returns action `use_as_context`: its memories shape what your
|
|
90
|
+
model suggests, and are never a fact or a permission. An `unverified` search
|
|
91
|
+
whose rows include `evidence_role: "applicable_rule"` returns reason
|
|
92
|
+
`applicable_rule` and action `use_as_context`: the rule speaks to the asked
|
|
93
|
+
case but the API has not verified it decides it; let your model apply it, or
|
|
94
|
+
call `reason()`. `reason()` takes
|
|
95
|
+
`deadline_ms`; a `timed_out` response is an abstention. `verify_authorization` means the returned rule limits the action
|
|
87
96
|
to a group the store cannot place the user in: use the rule, and check the
|
|
88
97
|
permission in your own system.
|
|
89
98
|
|
|
@@ -49,6 +49,15 @@ ACTIONS = {
|
|
|
49
49
|
# the rule is in ``context``; check the asker's role in your own system.
|
|
50
50
|
AUTHORIZATION_NOT_VERIFIABLE = "authorization_not_verifiable"
|
|
51
51
|
VERIFY_AUTHORIZATION = "verify_authorization"
|
|
52
|
+
# A Reason request for a suggestion or plan ("Can you suggest accessories for my
|
|
53
|
+
# camera?") has no stored answer: its sources are the memories that should shape
|
|
54
|
+
# what your model composes (``grounding.answerability`` "context_only"). They are
|
|
55
|
+
# context, never a verified fact or a permission.
|
|
56
|
+
CONTEXT_ONLY = "context_only"
|
|
57
|
+
USE_AS_CONTEXT = "use_as_context"
|
|
58
|
+
# ``require_ready``: the scope's index is not complete, or the server says the
|
|
59
|
+
# answer may still change (``indexing.answer_risk``).
|
|
60
|
+
INDEX_NOT_READY = "index_not_ready"
|
|
52
61
|
# Set by the SDK on a response whose rows it kept although it is degraded: not a
|
|
53
62
|
# malformed envelope, so it is not a reason to fail closed on its own.
|
|
54
63
|
_PRESERVED = "degraded_evidence_preserved"
|
|
@@ -105,17 +114,71 @@ def _is_history(row: Mapping[str, Any], *, search_row: bool) -> bool:
|
|
|
105
114
|
)
|
|
106
115
|
|
|
107
116
|
|
|
117
|
+
def _ready(response: Mapping[str, Any]) -> bool:
|
|
118
|
+
"""Whether the response says its scope is fully indexed with nothing that
|
|
119
|
+
could change the answer. A response that does not say is not ready."""
|
|
120
|
+
|
|
121
|
+
indexing = response.get("indexing")
|
|
122
|
+
if not isinstance(indexing, Mapping):
|
|
123
|
+
return False
|
|
124
|
+
return indexing.get("status") == "ready" and indexing.get("answer_risk") in (
|
|
125
|
+
None,
|
|
126
|
+
"none",
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
_ABSTENTION_FLAGS = ("no_match", "abstain_recommended", "decision_abstained")
|
|
131
|
+
# A row's evidence_role for a current rule that speaks to the asked case but is
|
|
132
|
+
# not verified to decide it (see ``should_answer``).
|
|
133
|
+
APPLICABLE_RULE = "applicable_rule"
|
|
134
|
+
|
|
135
|
+
|
|
108
136
|
def should_answer(
|
|
109
|
-
response: Optional[Mapping[str, Any]],
|
|
137
|
+
response: Optional[Mapping[str, Any]],
|
|
138
|
+
*,
|
|
139
|
+
history: bool = False,
|
|
140
|
+
require_ready: bool = False,
|
|
110
141
|
) -> AnswerDecision:
|
|
111
142
|
"""Whether you may answer from ``response`` (a ``search_with_proof`` or
|
|
112
143
|
``reason`` result), the rows to answer from, and what to do when you may not.
|
|
113
144
|
|
|
145
|
+
Every server signal is enforced: ``answer_status``, ``no_match``,
|
|
146
|
+
``abstain_recommended``, ``decision_abstained``, ``confidence_reason`` and
|
|
147
|
+
each row's ``low_confidence`` and ``revision_status``.
|
|
148
|
+
|
|
149
|
+
``require_ready=True`` is for high-stakes flows (money, health, actions):
|
|
150
|
+
the answer is also held, with action ``retry``, until ``indexing.status`` is
|
|
151
|
+
``ready`` and ``indexing.answer_risk`` is ``none``. Without it an answer
|
|
152
|
+
from a scope still indexing is allowed when the server allows it
|
|
153
|
+
(``answer_risk`` ``may_change``), and a count, total or list is always held
|
|
154
|
+
while indexing (``answer_status`` ``indexing``).
|
|
155
|
+
|
|
114
156
|
``history=True`` is for a question about the past that your application
|
|
115
|
-
recognises ("Where did I live before?")
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
157
|
+
recognises ("Where did I live before?"). It overrides one thing: a
|
|
158
|
+
superseded or historical row then counts as evidence, so a response the
|
|
159
|
+
server answered or marked ``superseded`` can be answered from its earlier
|
|
160
|
+
versions (a superseded response's ``abstain_recommended`` or
|
|
161
|
+
``decision_abstained`` concerns the present, so it does not bar this). It
|
|
162
|
+
never overrides ``unverified``, ``no_relevant_memory``, ``indexing``,
|
|
163
|
+
``conflicting``, ``authorization_not_verifiable`` or ``no_match``.
|
|
164
|
+
|
|
165
|
+
A response marked ``answerable`` that also sets ``no_match``,
|
|
166
|
+
``abstain_recommended`` or ``decision_abstained`` contradicts itself; the
|
|
167
|
+
server never sends one, and this helper declines it, with that flag as
|
|
168
|
+
the reason, in every mode. Keep each
|
|
169
|
+
row's ``revision_status`` and ``stated_at`` in what you pass to the model, so
|
|
170
|
+
it can tell the versions apart.
|
|
171
|
+
|
|
172
|
+
A Reason result for a suggestion or plan (``context_only``) returns action
|
|
173
|
+
``use_as_context``: give ``decision.context`` to your model to shape what it
|
|
174
|
+
suggests, never as an established fact or a permission to act.
|
|
175
|
+
|
|
176
|
+
An ``unverified`` search response whose rows include an
|
|
177
|
+
``evidence_role: applicable_rule`` row returns reason ``applicable_rule``
|
|
178
|
+
and action ``use_as_context``, with those rules first in
|
|
179
|
+
``decision.context``: policy that speaks to the asked case but that the
|
|
180
|
+
API has not verified decides it. Let your model apply it (and say so), or
|
|
181
|
+
ask ``reason``, which applies stored rules to the case and cites them.
|
|
119
182
|
"""
|
|
120
183
|
|
|
121
184
|
if not isinstance(response, Mapping) or "answer_status" not in response:
|
|
@@ -135,16 +198,37 @@ def should_answer(
|
|
|
135
198
|
return declined(status, ACTIONS[status])
|
|
136
199
|
if response.get("confidence_reason") == AUTHORIZATION_NOT_VERIFIABLE:
|
|
137
200
|
return declined(AUTHORIZATION_NOT_VERIFIABLE, VERIFY_AUTHORIZATION)
|
|
138
|
-
|
|
201
|
+
grounding = response.get("grounding")
|
|
202
|
+
if isinstance(grounding, Mapping) and grounding.get("answerability") == CONTEXT_ONLY:
|
|
203
|
+
return declined(CONTEXT_ONLY, USE_AS_CONTEXT)
|
|
204
|
+
if require_ready and not _ready(response):
|
|
205
|
+
return declined(INDEX_NOT_READY, "retry")
|
|
206
|
+
flags = [flag for flag in _ABSTENTION_FLAGS if response.get(flag) is True]
|
|
207
|
+
if status == "answerable" and flags:
|
|
208
|
+
# The server never marks a response answerable while it recommends
|
|
209
|
+
# abstaining. An envelope that does contradicts itself, and a
|
|
210
|
+
# contradiction is not an answer, in history mode or not.
|
|
211
|
+
return declined(flags[0], "abstain")
|
|
212
|
+
if history and status in ("answerable", "superseded") and "no_match" not in flags:
|
|
213
|
+
# A superseded response recommends abstaining for the present: every
|
|
214
|
+
# relevant record states a value that no longer holds. That is what a
|
|
215
|
+
# question about the past reads, so those flags do not bar it here.
|
|
139
216
|
usable = [row for row in rows if _is_history(row, search_row=search_rows)]
|
|
140
217
|
if usable:
|
|
141
218
|
others = [row for row in rows if row not in usable]
|
|
142
219
|
return AnswerDecision(True, "history", "answer", usable, others, cited)
|
|
220
|
+
if status == "unverified":
|
|
221
|
+
rules = [row for row in rows if row.get("evidence_role") == APPLICABLE_RULE]
|
|
222
|
+
if rules:
|
|
223
|
+
# A rule that speaks to the asked case, not verified to decide
|
|
224
|
+
# it: policy for your model to apply, never an established answer
|
|
225
|
+
# or a permission (authorization questions were declined above).
|
|
226
|
+
others = [row for row in rows if row not in rules]
|
|
227
|
+
return AnswerDecision(
|
|
228
|
+
False, APPLICABLE_RULE, USE_AS_CONTEXT, [], [*rules, *others], cited
|
|
229
|
+
)
|
|
143
230
|
if status != "answerable":
|
|
144
231
|
return declined(status, ACTIONS[status])
|
|
145
|
-
for flag in ("no_match", "abstain_recommended", "decision_abstained"):
|
|
146
|
-
if response.get(flag) is True:
|
|
147
|
-
return declined(flag, "abstain")
|
|
148
232
|
usable = [row for row in rows if _is_evidence(row, search_row=search_rows)]
|
|
149
233
|
if not usable:
|
|
150
234
|
return declined("no_usable_memories", "abstain")
|
|
@@ -153,12 +237,17 @@ def should_answer(
|
|
|
153
237
|
|
|
154
238
|
|
|
155
239
|
def usable_memories(
|
|
156
|
-
response: Optional[Mapping[str, Any]],
|
|
240
|
+
response: Optional[Mapping[str, Any]],
|
|
241
|
+
*,
|
|
242
|
+
history: bool = False,
|
|
243
|
+
require_ready: bool = False,
|
|
157
244
|
) -> List[Dict[str, Any]]:
|
|
158
245
|
"""The rows of ``response`` safe to pass to a model as evidence; empty when
|
|
159
246
|
``should_answer`` says not to answer."""
|
|
160
247
|
|
|
161
|
-
return should_answer(
|
|
248
|
+
return should_answer(
|
|
249
|
+
response, history=history, require_ready=require_ready
|
|
250
|
+
).memories
|
|
162
251
|
|
|
163
252
|
|
|
164
253
|
def _day(value: Any) -> Optional[str]:
|
|
@@ -189,7 +278,8 @@ def _profile_lines(profile: Any) -> List[str]:
|
|
|
189
278
|
projection = profile.get("projection")
|
|
190
279
|
projection = projection if isinstance(projection, Mapping) else {}
|
|
191
280
|
pending = projection.get("status") == "pending"
|
|
192
|
-
|
|
281
|
+
failed = projection.get("status") == "failed"
|
|
282
|
+
if not facts and not avoid and not pending and not failed:
|
|
193
283
|
return []
|
|
194
284
|
scope = profile.get("scope")
|
|
195
285
|
scope = (
|
|
@@ -226,6 +316,17 @@ def _profile_lines(profile: Any) -> List[str]:
|
|
|
226
316
|
f"- still being updated: {writes} not yet reflected; a fact here may be "
|
|
227
317
|
"missing or about to change."
|
|
228
318
|
)
|
|
319
|
+
elif failed:
|
|
320
|
+
count = projection.get("failed_writes")
|
|
321
|
+
writes = (
|
|
322
|
+
f"{count} recent writes"
|
|
323
|
+
if isinstance(count, int) and count > 0
|
|
324
|
+
else "recent writes"
|
|
325
|
+
)
|
|
326
|
+
lines.append(
|
|
327
|
+
f"- incomplete: {writes} could not be reflected; a fact from them may be "
|
|
328
|
+
"missing."
|
|
329
|
+
)
|
|
229
330
|
return lines
|
|
230
331
|
|
|
231
332
|
|
|
@@ -276,6 +377,7 @@ def answer_context(
|
|
|
276
377
|
decision: Optional[AnswerDecision] = None,
|
|
277
378
|
*,
|
|
278
379
|
history: bool = False,
|
|
380
|
+
require_ready: bool = False,
|
|
279
381
|
) -> str:
|
|
280
382
|
"""The text to give your own model with the user's message: the end user's
|
|
281
383
|
standing profile and the memories ``should_answer`` lets you answer from.
|
|
@@ -290,11 +392,16 @@ def answer_context(
|
|
|
290
392
|
memory type, date, whom it is about, the names it states, its revision
|
|
291
393
|
status and its support. When the decision is not to answer, only the
|
|
292
394
|
profile is returned: standing preferences still shape a reply such as
|
|
293
|
-
"I don't know that yet".
|
|
395
|
+
"I don't know that yet". For a Reason suggestion or plan (``context_only``)
|
|
396
|
+
the memories that should shape it are listed as context, marked as neither
|
|
397
|
+
established facts nor permission to act. Returns "" when there is nothing to
|
|
398
|
+
add.
|
|
294
399
|
"""
|
|
295
400
|
|
|
296
401
|
if decision is None:
|
|
297
|
-
decision = should_answer(
|
|
402
|
+
decision = should_answer(
|
|
403
|
+
response, history=history, require_ready=require_ready
|
|
404
|
+
)
|
|
298
405
|
sections = []
|
|
299
406
|
profile = _profile_lines(
|
|
300
407
|
response.get("profile") if isinstance(response, Mapping) else None
|
|
@@ -313,4 +420,14 @@ def answer_context(
|
|
|
313
420
|
lines.append(f"[{index}]" + (f" ({'; '.join(details)})" if details else ""))
|
|
314
421
|
lines.append(str(row.get("content") or ""))
|
|
315
422
|
sections.append("\n".join(lines))
|
|
423
|
+
elif decision.reason == CONTEXT_ONLY and decision.context:
|
|
424
|
+
lines = [
|
|
425
|
+
"Memories that should shape the suggestion (context: not established "
|
|
426
|
+
"facts, and never permission to act):"
|
|
427
|
+
]
|
|
428
|
+
for index, row in enumerate(decision.context, start=1):
|
|
429
|
+
details = _memory_details(row)
|
|
430
|
+
lines.append(f"[{index}]" + (f" ({'; '.join(details)})" if details else ""))
|
|
431
|
+
lines.append(str(row.get("content") or ""))
|
|
432
|
+
sections.append("\n".join(lines))
|
|
316
433
|
return "\n\n".join(sections)
|
|
@@ -1144,7 +1144,7 @@ class SyncMemoryClient:
|
|
|
1144
1144
|
self.source = source or os.getenv("HEBBRIX_SOURCE")
|
|
1145
1145
|
headers = {
|
|
1146
1146
|
"Content-Type": "application/json",
|
|
1147
|
-
"User-Agent": "hebbrix-python/2.
|
|
1147
|
+
"User-Agent": "hebbrix-python/2.10.0",
|
|
1148
1148
|
}
|
|
1149
1149
|
if api_key:
|
|
1150
1150
|
headers["Authorization"] = f"Bearer {api_key}"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hebbrix
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.10.0
|
|
4
4
|
Summary: Typed Python client for Hebbrix memory, retrieval, and outcome-learning APIs
|
|
5
5
|
Author-email: Hebbrix Team <support@hebbrix.com>
|
|
6
6
|
Maintainer-email: Hebbrix Team <support@hebbrix.com>
|
|
@@ -65,14 +65,14 @@ Dynamic: license-file
|
|
|
65
65
|
|
|
66
66
|
Typed Python client for Hebbrix memory, retrieval, and outcome-learning APIs.
|
|
67
67
|
|
|
68
|
-
The current stable package is **2.
|
|
68
|
+
The current stable package is **2.10.0**. Start with memory storage and search, or
|
|
69
69
|
the three-call outcome-learning workflow below. Advanced evidence and execution
|
|
70
70
|
permission transports are opt-in; installing the SDK never permits an action.
|
|
71
71
|
|
|
72
72
|
## Install
|
|
73
73
|
|
|
74
74
|
```bash
|
|
75
|
-
pip install hebbrix==2.
|
|
75
|
+
pip install hebbrix==2.10.0
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
Python 3.8+ is supported. `MemoryClient` is asynchronous. `SyncMemoryClient`
|
|
@@ -145,8 +145,17 @@ profile's `scope`, and says so when the profile is still being updated
|
|
|
145
145
|
is not taken as absent. When the decision is not to answer it returns the
|
|
146
146
|
profile alone. `usable_memories(response)` returns just the rows. Pass
|
|
147
147
|
`history=True` for a question about the past, when superseded and historical
|
|
148
|
-
versions should count
|
|
149
|
-
|
|
148
|
+
versions should count (it never overrides `unverified`, `no_relevant_memory`,
|
|
149
|
+
`indexing` or `conflicting`). Pass `require_ready=True` for a high-stakes flow:
|
|
150
|
+
the answer is then also held, with action `retry`, until `indexing.status` is
|
|
151
|
+
`ready` and `indexing.answer_risk` is `none`. A Reason suggestion or plan
|
|
152
|
+
(`context_only`) returns action `use_as_context`: its memories shape what your
|
|
153
|
+
model suggests, and are never a fact or a permission. An `unverified` search
|
|
154
|
+
whose rows include `evidence_role: "applicable_rule"` returns reason
|
|
155
|
+
`applicable_rule` and action `use_as_context`: the rule speaks to the asked
|
|
156
|
+
case but the API has not verified it decides it; let your model apply it, or
|
|
157
|
+
call `reason()`. `reason()` takes
|
|
158
|
+
`deadline_ms`; a `timed_out` response is an abstention. `verify_authorization` means the returned rule limits the action
|
|
150
159
|
to a group the store cannot place the user in: use the rule, and check the
|
|
151
160
|
permission in your own system.
|
|
152
161
|
|
|
@@ -119,6 +119,29 @@ def test_a_profile_still_being_projected_says_so():
|
|
|
119
119
|
)
|
|
120
120
|
|
|
121
121
|
|
|
122
|
+
def test_a_profile_whose_writes_failed_to_project_says_it_is_incomplete():
|
|
123
|
+
failed = {
|
|
124
|
+
**PROFILE,
|
|
125
|
+
"facts": [],
|
|
126
|
+
"avoid_topics": [],
|
|
127
|
+
"projection": {
|
|
128
|
+
"status": "failed",
|
|
129
|
+
"pending_writes": 0,
|
|
130
|
+
"failed_writes": 2,
|
|
131
|
+
"capped": False,
|
|
132
|
+
"failure": {"reason": "profile_extraction_failed", "retryable": True},
|
|
133
|
+
"retry_after_seconds": None,
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
context = answer_context(search([], failed, answer_status="no_relevant_memory"))
|
|
137
|
+
assert context == (
|
|
138
|
+
"Standing profile of this user (applies to every reply; collection_id c-1; "
|
|
139
|
+
"end_user_id user-42; as of 2026-11-08; projection failed):\n"
|
|
140
|
+
"- incomplete: 2 recent writes could not be reflected; a fact from them may "
|
|
141
|
+
"be missing."
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
|
|
122
145
|
def test_an_unavailable_profile_is_not_presented_as_empty():
|
|
123
146
|
context = answer_context(
|
|
124
147
|
search([ALLERGY], {"status": "unavailable", "facts": [], "count": 0})
|
|
@@ -170,3 +193,18 @@ def test_reason_sources_render_too():
|
|
|
170
193
|
"[1] (fact; saved 2026-11-02; current)",
|
|
171
194
|
"The user is allergic to peanuts.",
|
|
172
195
|
]
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def test_a_suggestion_lists_its_context_as_neither_fact_nor_permission():
|
|
199
|
+
from hebbrix import answer_context
|
|
200
|
+
|
|
201
|
+
page = {
|
|
202
|
+
"answer": None,
|
|
203
|
+
"sources": [{"memory_id": "m1", "content": "The user owns a Fuji X-T5."}],
|
|
204
|
+
"decision_abstained": True,
|
|
205
|
+
"answer_status": "unverified",
|
|
206
|
+
"grounding": {"status": "supported", "answerability": "context_only"},
|
|
207
|
+
}
|
|
208
|
+
text = answer_context(page)
|
|
209
|
+
assert "The user owns a Fuji X-T5." in text
|
|
210
|
+
assert "not established facts" in text and "never permission" in text
|
|
@@ -383,3 +383,130 @@ def test_an_unverified_permission_is_its_own_action_with_the_rule_as_context():
|
|
|
383
383
|
def test_the_authorization_reason_is_the_apis():
|
|
384
384
|
text = SCHEMAS["SearchResponse"]["properties"]["confidence_reason"]["description"]
|
|
385
385
|
assert "authorization_not_verifiable" in text
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
def test_history_never_overrides_an_unverified_response():
|
|
389
|
+
# The server could not establish any row: earlier versions among them are
|
|
390
|
+
# not evidence for the past either.
|
|
391
|
+
rows = [row("old", is_current=False, revision_status="historical", low_confidence=True)]
|
|
392
|
+
page = search(rows, answer_status="unverified", abstain_recommended=True)
|
|
393
|
+
decision = should_answer(page, history=True)
|
|
394
|
+
assert not decision
|
|
395
|
+
assert decision.action == "abstain"
|
|
396
|
+
assert ids(decision.context) == ["old"]
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def test_a_high_stakes_answer_waits_for_a_ready_index():
|
|
400
|
+
ready = {"status": "ready", "answer_risk": "none"}
|
|
401
|
+
assert should_answer(search(indexing=ready), require_ready=True)
|
|
402
|
+
for indexing in (
|
|
403
|
+
{"status": "incomplete", "answer_risk": "may_change"},
|
|
404
|
+
{"status": "ready", "answer_risk": "may_change"},
|
|
405
|
+
None,
|
|
406
|
+
):
|
|
407
|
+
decision = should_answer(search(indexing=indexing), require_ready=True)
|
|
408
|
+
assert not decision
|
|
409
|
+
assert decision.action == "retry"
|
|
410
|
+
assert decision.reason == "index_not_ready"
|
|
411
|
+
# Without it, a response the server lets answer while indexing answers.
|
|
412
|
+
assert should_answer(search(indexing={"status": "incomplete", "answer_risk": "may_change"}))
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
def test_a_suggestion_is_context_to_shape_never_an_answer():
|
|
416
|
+
page = reason(
|
|
417
|
+
[source("camera")],
|
|
418
|
+
answer=None,
|
|
419
|
+
decision_abstained=True,
|
|
420
|
+
grounding={"status": "supported", "answerability": "context_only"},
|
|
421
|
+
)
|
|
422
|
+
decision = should_answer(page)
|
|
423
|
+
assert not decision
|
|
424
|
+
assert decision.action == "use_as_context"
|
|
425
|
+
assert decision.memories == []
|
|
426
|
+
assert ids(decision.context) == ["camera"]
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
@pytest.mark.parametrize("flag", ["abstain_recommended", "decision_abstained", "no_match"])
|
|
430
|
+
def test_an_answerable_status_beside_an_abstention_flag_fails_closed_in_every_mode(flag):
|
|
431
|
+
# A contradictory envelope (the server never sends one): answerable, an
|
|
432
|
+
# explicit abstention flag, and only an earlier, unestablished row.
|
|
433
|
+
page = search(
|
|
434
|
+
[
|
|
435
|
+
row(
|
|
436
|
+
"synthetic-history",
|
|
437
|
+
revision_status="historical",
|
|
438
|
+
is_current=False,
|
|
439
|
+
low_confidence=True,
|
|
440
|
+
)
|
|
441
|
+
],
|
|
442
|
+
indexing={"status": "ready", "answer_risk": "none"},
|
|
443
|
+
**{flag: True},
|
|
444
|
+
)
|
|
445
|
+
for options in ({}, {"history": True}, {"history": True, "require_ready": True}):
|
|
446
|
+
decision = should_answer(page, **options)
|
|
447
|
+
assert not decision
|
|
448
|
+
assert decision.reason == flag
|
|
449
|
+
assert decision.action == "abstain"
|
|
450
|
+
assert decision.memories == []
|
|
451
|
+
assert usable_memories(page, **options) == []
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
def test_a_superseded_reason_result_still_answers_a_history_question():
|
|
455
|
+
# Reason marks a result superseded only when it abstains for the present
|
|
456
|
+
# (decision_abstained), so that flag is what a question about the past reads.
|
|
457
|
+
page = reason(
|
|
458
|
+
[source("old", is_current=False, revision_status="superseded")],
|
|
459
|
+
answer=None,
|
|
460
|
+
decision_abstained=True,
|
|
461
|
+
answer_status="superseded",
|
|
462
|
+
)
|
|
463
|
+
assert not should_answer(page)
|
|
464
|
+
decision = should_answer(page, history=True)
|
|
465
|
+
assert decision
|
|
466
|
+
assert decision.reason == "history"
|
|
467
|
+
assert ids(decision.memories) == ["old"]
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
def test_history_never_answers_a_response_that_matched_nothing():
|
|
471
|
+
page = search(
|
|
472
|
+
[row("old", is_current=False, revision_status="superseded", low_confidence=True)],
|
|
473
|
+
answer_status="superseded",
|
|
474
|
+
abstain_recommended=True,
|
|
475
|
+
no_match=True,
|
|
476
|
+
)
|
|
477
|
+
decision = should_answer(page, history=True)
|
|
478
|
+
assert not decision
|
|
479
|
+
assert decision.reason == "superseded"
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
def test_an_applicable_rule_is_policy_context_never_an_answer():
|
|
483
|
+
rows = [
|
|
484
|
+
row("case", low_confidence=True, evidence_role="related"),
|
|
485
|
+
row("rule", low_confidence=True, evidence_role="applicable_rule"),
|
|
486
|
+
]
|
|
487
|
+
page = search(
|
|
488
|
+
rows,
|
|
489
|
+
answer_status="unverified",
|
|
490
|
+
abstain_recommended=True,
|
|
491
|
+
confidence_reason="soft_claim_candidate",
|
|
492
|
+
)
|
|
493
|
+
decision = should_answer(page)
|
|
494
|
+
assert not decision
|
|
495
|
+
assert decision.reason == "applicable_rule"
|
|
496
|
+
assert decision.action == "use_as_context"
|
|
497
|
+
assert decision.memories == []
|
|
498
|
+
assert ids(decision.context) == ["rule", "case"]
|
|
499
|
+
assert usable_memories(page) == []
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
def test_a_rule_never_answers_an_authorization_question():
|
|
503
|
+
rows = [row("rule", low_confidence=True, evidence_role="applicable_rule")]
|
|
504
|
+
page = search(
|
|
505
|
+
rows,
|
|
506
|
+
answer_status="unverified",
|
|
507
|
+
abstain_recommended=True,
|
|
508
|
+
confidence_reason="authorization_not_verifiable",
|
|
509
|
+
)
|
|
510
|
+
decision = should_answer(page)
|
|
511
|
+
assert not decision
|
|
512
|
+
assert decision.reason == "authorization_not_verifiable"
|
|
@@ -162,6 +162,6 @@ def test_package_docs_metadata_uses_canonical_host():
|
|
|
162
162
|
assert 'Documentation = "https://hebbrix.com/docs"' in text
|
|
163
163
|
assert "docs.hebbrix.com" not in text
|
|
164
164
|
readme = (root / "README.md").read_text()
|
|
165
|
-
assert "pip install hebbrix==2.
|
|
165
|
+
assert "pip install hebbrix==2.10.0" in readme
|
|
166
166
|
assert "three calls" in readme
|
|
167
167
|
assert "schema `" not in readme
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|