Skip to content

SDK model tools support scoped code lookup - #908

Merged
zlareb1 merged 3 commits into
mainfrom
feat/sdk-code-tools
Nov 18, 2026
Merged

zlareb1 merged 3 commits into
mainfrom
feat/sdk-code-tools

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

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.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • 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.
  • 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.
  • Docs under docs/ describe the system as it now is, and this description names operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; history belongs in this description.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

Applications can bind indexed code evidence through AgentTools instead of
writing a provider-specific dispatcher. An explicit code namespace keeps
memory scope separate and leaves the default tool bundle unchanged.

The result cap preserves valid JSON, whole evidence and explicit client
omissions alongside the SDK request ID and server uncertainty.

Signed-off-by: zlareb1 <[email protected]>
Keep the constructor in the form produced by the Markdown code formatter
so the SDK example passes the repository format gate.

Signed-off-by: zlareb1 <[email protected]>
zlareb1 added a commit that referenced this pull request Nov 18, 2026
Related: #908

### Changelog category (leave one):

- Bug Fix (user-visible misbehavior in a release)

### 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: true` and 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.set` file-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

- Wire: no operation, wire field or server default changes. `MemoryClient.set(files=...)` exposes the existing wire field; `[]` clears prior references. The public Python API snapshot is regenerated.
- Operator steps: none. Code linking remains asynchronous and uses the configured code namespace or an explicit matching repository tag.
- Rollback: reverting restores SDK projections and the Python method signature. No stored data or schema changes require reversal.

### Tests

- Fourteen Python and twelve TypeScript regression cases fail before the fix. They cover persisted writes, canonical no-op merges, duplicate rows, conflicts, stale code, unverified sources, abstention, oversized results and explicit file references. Two additional budget controls per SDK confirm refusal before a request.
- Governed-definition controls fail in both SDKs before the field fix. Mixed governed and weak ordinary hits retain their separate authority, scores and original abstention verdict; an ordinary-only neighbor retains abstention.
- The current selected Python gate passes 33 cases: eighteen receipt/trust cases, fourteen existing session/tools cases and the public API snapshot. README link and source-copy checks passed on the first head; CI rechecks the final head.
- The selected TypeScript tool files pass 23 cases using a cached test runner one patch below the SDK lock. This is a diagnostic result; exact-lock tests and packaging remain CI requirements. The matching compiler passes the changed module and tests, with cached type declarations one patch above the lock.
- Framework-adapter fixtures use persisted write receipts and exact bounded JSON omission checks. Their optional dependencies are absent locally, so those modules remain unrun locally and must pass CI.
- Strict Python typing, changed-file Ruff, function-length ratchets, exact-version TypeScript formatting, Markdown formatting and whitespace checks pass.
- The 17 sender-provenance census checks pass after reviewing explicit file references on the existing memory write path and renewing only its source fingerprint.
- Full format, lint, type, package and unit checks run in CI. No provider evaluation is part of this change.

### 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.

- [x] I can explain every line of this diff and how it interacts with the rest of Loom.

### Checklist

- [ ] `make format-check`, `make lint`, `make typecheck` and `make test-unit` pass; the integration suite passes if server behaviour changed.
- [x] The Python public API snapshot is regenerated. Wire, setting, schema and plugin generators are unaffected.
- [x] No migrations.
- [x] No plugin files or versions change.
- [x] No frontend changes.
- [x] Documentation describes current SDK behavior and names operator and wire changes.
- [x] Repository text carries no private deployment details.
- [x] Commits are signed off.

Signed-off-by: zlareb1 <[email protected]>
Combine scoped code lookup with the current SDK receipt and file-reference behavior. Keep current account and transport changes.

Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit bf7f8ca into main Nov 18, 2026
45 checks passed
@zlareb1 zlareb1 mentioned this pull request Nov 18, 2026
6 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant