Repository navigation
SDK memory tools preserve receipts and recall trust - #911
Merged
Merged
Conversation
Keep canonical no-op receipts and source uncertainty visible to model tools, and omit whole evidence instead of cutting JSON. Expose existing file references in Python writes with explicit clear semantics. Signed-off-by: zlareb1 <[email protected]>
Retain the definition-leg metadata that explains why governed facts can be served alongside low-confidence ordinary retrieval. Align adapter fixtures with persisted receipts and whole-memory JSON omission. Signed-off-by: zlareb1 <[email protected]>
Review the existing memory write admission and coalescer delivery paths after exposing file references, then renew only that module's source fingerprint. Signed-off-by: zlareb1 <[email protected]>
6 tasks done
zlareb1
added a commit
that referenced
this pull request
Nov 18, 2026
Related: #911 ### Changelog category (leave one): - New Feature ### Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes): Python and TypeScript model tools can opt in to scoped code lookup for definitions, conceptual search, callers and prospective impact. Code results preserve request IDs and valid JSON within the application's character budget, with explicit evidence omissions. ### Why Applications using `AgentTools` need indexed code evidence alongside memory without writing their own schemas, scope binding and dispatcher. One read-only tool reuses the provider formats and the SDK metadata transport. An explicit code namespace keeps code and memory scope distinct; the model cannot supply tenant fields, wire operations or budgets. Keeping code lookup opt-in preserves the default memory tools and their order. Offering separate provider-specific bindings would duplicate scope and argument checks. Runtime routing or forced calls would spend on unrelated requests and replace the model's tool choice. ### Scope and risk Adds `code_namespace` / `codeNamespace` to `AgentTools` and one `loom_code_lookup` definition with `kind`, `target` and optional bounded `depth`. Code lookup leads the enabled bundle; explicitly selecting it without a namespace fails during construction. Named requests accept compact qualified references or `path:line`; conceptual prose uses search. Requests use existing read-only operations and application-owned scope. Authorization errors propagate without changing namespaces. Symbol bodies retain the canonical 2500-token request budget; search and graph requests have fixed result bounds. Oversized responses elide whole bodies and rows while preserving uncertainty and citations. If metadata cannot fit, the result explicitly reports client-budget insufficiency instead of partial JSON or an exactness claim. Includes matching SDK examples, a usage guide, scope and budget tests, and the intended API snapshot change. No server behavior, memory-tool result behavior or stored data changes. Model adoption, task success, time and token savings remain unmeasured for this helper. ### Compatibility, rollout and rollback - Wire: no operation or field changes. The default memory bundle and provider formats remain unchanged. The code tool is optional; callers must bind its namespace explicitly. - Operator steps: none. Applications opting in need an existing code index and a token with read access to that code namespace. - Rollback: revert the SDK helper and its documentation. No schema, migration or data cleanup is needed. ### Tests The focused results below apply to the code-tool source before this forward composition. This head combines it with the existing memory receipt, trust metadata and file-reference behavior. The code dispatch returns before the memory-result formatter; remember and recall retain their refusal before dispatch when the result budget cannot report omissions. - `python -m pytest tests/unit/test_sdk_code_tools.py tests/unit/test_sdk_session_tools.py -q`: 36 passed, including default-tool behavior, fixed scope, rejected model injection, actual mocked SDK metadata calls, authorization refusal and whole-evidence budgets. - `npm --prefix sdk/typescript test -- src/code-tools.test.ts src/tools.test.ts --typecheck.enabled false`: 29 passed. - API snapshot, documentation links and public-copy checks passed in a focused selection of 296 tests. The snapshot adds only the `code_namespace` keyword. - Strict mypy on the changed SDK modules, TypeScript type checking, 27 README snippets, the ESM/CJS/declaration build, dispatcher `--help`, formatting, prose, documentation generation and the function-length gate passed. - Five offline mocked cases produced matching Python/TypeScript provider definitions and byte-identical result JSON within the configured caps, including Unicode and metadata insufficiency. No live-model or provider measurement was run. Full CI passes on this composed head: 43 successful checks, two conditional publication skips and all four workflows successful, including exact-lock TypeScript tests, type checks and packaging. The selected local composition checks have not run. The earlier unit-part-6 cost assertion remains a recorded failure with an unresolved cause; a new pass qualifies this composition without explaining that failure. ### AI assistance in the code (leave one; writing this description with AI is fine): - AI-generated (an agent wrote most of the diff): Codex. Checked the scope boundaries, wire request shapes, error propagation, default-tool behavior, result budgets and focused validation listed above. - [x] I can explain every line of this diff and how it interacts with the rest of Loom. ### Checklist - [x] Full CI passes, including formatting, lint, type checking, unit and integration suites. Focused local results above apply to the earlier code-tool source; selected local composition checks remain unrun. - [x] Generated documentation is regenerated in this PR; the intended SDK API snapshot is refreshed through its test. No wire, setting, schema, reach or plugin-generated surface changed. - [x] Docs under `docs/` describe the system as it now is, and this description names operator steps and wire changes. - [x] Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; history belongs in this description. - [x] Commits are signed off (`git commit -s`), as CONTRIBUTING.md asks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #908
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
SDK memory tools preserve persistence receipts, conflicts, recall abstention and source trust metadata. Python memory writes accept explicit file references for code-linked facts.
Why
A merged fact can return an existing memory ID while writing no row at the requested key. The model tool reported
stored: trueand dropped the canonical key and no-op fields. Recall dropped code freshness, row status, provenance and attestation fields, leaving the model unable to distinguish a changed or unverified claim from a current one.The tools retain the server's evidence and keep memory results valid JSON under the result budget. Governed-definition authority and term-leg status remain visible alongside retrieval scores that apply only to ordinary hits. A result that cannot carry its metadata says so instead of returning a partial receipt.
Scope and risk
Python and TypeScript memory-tool result projections, their descriptions, the Python
MemoryClient.setfile-reference argument, documentation and focused tests. Tool names and input schemas are unchanged. File and repository association use the direct SDK path; enabling code lookup does not select a repository for memory writes.Consumers parsing exact result objects receive additional receipt and trust fields. A memory too large to fit is omitted whole, including the first result. An unreportable memory-result budget fails before sending the request.
Compatibility, rollout and rollback
MemoryClient.set(files=...)exposes the existing wire field;[]clears prior references. The public Python API snapshot is regenerated.Tests
AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated: Codex wrote the change and checked wire models, both SDK implementations, focused regressions and result budgets.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed.