feat(tools): add :defer option to tool definitions (upstream PR #1632)#137
Merged
Conversation
Port upstream github/copilot-sdk PR #1632, which adds an optional `defer: "auto" | "never"` field to tool definitions controlling whether a tool may be deferred (loaded lazily via tool search) instead of being pre-loaded into the model context. The Clojure idiom models this config enum as a keyword (:auto | :never), matching existing enum conventions, and converts it to its wire string via (name kw) when building tool definitions for both session.create and session.resume. The two builders previously held byte-identical tool cond-> blocks; this factors them into a shared tool-def->wire helper so the create/resume paths cannot drift. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a "Deferring tools" subsection to the API reference and a CHANGELOG [Unreleased] entry citing upstream PR #1632. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Ports upstream github/copilot-sdk PR #1632 by adding an optional :defer setting to Clojure tool definitions, allowing large tool sets to be lazily loaded via tool search to reduce active model context size.
Changes:
- Added
:defer(:auto/:never) todefine-toolanddefine-tool-from-spec, plus::deferspec support. - Refactored tool wire-shape construction into a shared private helper (
tool-def->wire) used by bothsession.createandsession.resumebuilders. - Added integration/spec tests and updated docs + changelog to document the new option and its wire behavior.
Show a summary per file
| File | Description |
|---|---|
| test/github/copilot_sdk/integration_test.clj | Adds tests asserting :defer keyword values serialize to "auto"/"never" on session.create/session.resume, and validates the new spec behavior. |
| src/github/copilot_sdk/tools.clj | Extends tool definition helpers to accept and carry :defer in the idiomatic tool map. |
| src/github/copilot_sdk/specs.clj | Introduces ::defer and adds it as an optional key on ::tool. |
| src/github/copilot_sdk/client.clj | Adds tool-def->wire helper and uses it in both create/resume param builders to include defer on the wire when set. |
| src/github/copilot_sdk.clj | Updates public API docs for define-tool to include :defer. |
| doc/reference/API.md | Documents how to use :defer and clarifies keyword→wire-string behavior and omission semantics. |
| CHANGELOG.md | Records the new tool option under Unreleased, referencing upstream PR #1632. |
Copilot's findings
- Files reviewed: 7/7 changed files
- Comments generated: 0
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.
Ports upstream github/copilot-sdk PR #1632, which adds an optional
defer: "auto" | "never"field to tool definitions.defercontrols whether a tool may be deferred — loaded lazily via tool search rather than always pre-loaded into the model's context — which keeps the active context smaller for large tool sets. Upstream defaults to"auto".What this adds
define-toolanddefine-tool-from-specnow accept an optional:deferkeyword. The config enum is modeled idiomatically as:auto/:never(matching existing enum conventions like:storage-mode/:remote-session-mode) and converted to its wire string via(name kw). The field is sent on the tool definition in bothsession.createandsession.resume; when omitted it is not sent and the runtime applies its"auto"default.Implementation notes
build-create-session-params/build-resume-session-params) previously carried byte-identical toolcond->blocks. Rather than add the:deferbranch in two places — a known drift hazard — this factors the tool-to-wire mapping into a privatetool-def->wirehelper shared by both paths.:deferis a single lowercase wire key, so unlike its siblings (:overridesBuiltInTool/:skipPermission) it needs no camelCase handling — only the keyword→string value conversion.deferonly on the send side (theToolinterface anddefineToolconfig), so the port mirrors exactly those sites plus the spec and docs. There is no inbound conversion to add.Validation
test-defer-on-wire(create + resume,:auto/:never→ wire string, absent-when-unset) andtest-defer-spec(accepts:auto/:never, rejects the"auto"string and:bogus).bb ci:fullgreen (E2E + examples + docs + JAR);bb validate-docsclean.Multi-model review
Both independently confirmed wire-conversion correctness, full upstream parity (no missed declaration site, no read-back surface), and complete spec coverage.