shrink builtin tool schemas to save tokens#2694
Merged
dgageot merged 3 commits intodocker:mainfrom May 7, 2026
Merged
Conversation
docker-agent
reviewed
May 7, 2026
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
Reviewed the schema null-stripping logic, description trimming, struct tag removals, and slog.WarnContext drive-by changes.
Key areas checked:
SchemaToMap/removeNullFromType: Thefiltered := arr[:0]in-place filter pattern is provably safe — Go's range captures the slice header at loop start, so reads always precede writes on the same backing-array positions. No correctness bug.stripNullFromRequiredTypesrecursion: Correctly gatesremoveNullFromTypeon therequiredset; recursive descent into nestedpropertiesanditemsis well-scoped.- Filesystem/shell struct tag removals: Tags were description-only (
jsonschema:"description=..."); JSON serialization keys (json:"...") are untouched. No serialization breakage. AddDescriptionParameterdescription text: Shortened text is functionally equivalent — no logic change.slog.WarnContextchanges: Each call site already had actxin scope; the substitution is correct.- Cassette updates: Updated request bodies match the new schema shapes for all five providers (OpenAI strict mode, Anthropic, Gemini, Mistral). The type narrowing from
["null","array"]→"array"for required fields aligns with the PR's stated intent and preserves strict-mode compatibility.
No bugs found in the changed code.
gtardif
approved these changes
May 7, 2026
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.
Reduces the size of builtin tool definitions sent to LLM providers on
every turn. Most of the savings come from the filesystem and shell
toolsets, which together represented ~1.2k tokens per request.
Changes:
SchemaToMapnow strips"null"from the type of required fields.jsonschema-go emits
["null", "array"]for every Go slice (includingrequired ones), which is contradictory and only inflates the schema.
OpenAI's strict mode still adds
nullfor fields it promotes fromoptional to required, so behaviour is preserved there.
AddDescriptionParameter.jsonschema:"..."tags on filesystem and shell toolarg structs.
slog.Warncalls toslog.WarnContextinspots where a context was already in scope (custom linter caught it).
Cassettes were updated to match the new request bodies. No behaviour
change for callers.