Skip to content

feat(toolcall): canonical tool-call contract package - #654

Open
guyu233 wants to merge 1 commit into
caigee-cmd:mainfrom
guyu233:pr/toolcall-contract-core
Open

guyu233 wants to merge 1 commit into
caigee-cmd:mainfrom
guyu233:pr/toolcall-contract-core

Conversation

@guyu233

@guyu233 guyu233 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

What this adds

A single canonical model of the tool-call contract: declarations, tool choice, argument repair, native call identity and rendering move out of internal/translate into a new internal/toolcall package, instead of every protocol re-implementing the same rules.

  • internal/toolcall carries request parsing, name/argument reduction, native call identity and rendering, with its own tests.
  • The shared chat-request validation in internal/translate delegates tools / tool_choice / parallel_tool_calls to it, so an orphan auto degrades to unspecified while required or a named choice fails instead of silently dropping the tool request.
  • internal/translate keeps its existing argument helpers for now; the delivery path still uses them until the follow-up PR switches the call sites over. Nothing is removed here, which keeps this PR additive and easy to review.

Why it is split out

The two PRs that follow (provider tool profiles, dispatch/terminal accounting) both need the same tool-call model. Landing it alone keeps the review small and the tests focused.

Stack

PR 1 of a 3-part backend stack. It applies cleanly to current main; the next PR is based on this branch, so please merge in order. The console PR in this set is independent.

Verification

  • go build ./...
  • go vet ./...
  • go test ./...
  • python3 scripts/release-notes.py validate

No console source or internal/webui/static changes, so the frontend CI job and the static consistency check stay green.

Introduce internal/toolcall as the single model of tool declarations,
tool choice, argument repair, native call identity and rendering.

translate.ValidateChatRequest now delegates tool_choice validation to
toolcall.ParseRequest, which keeps an orphan `auto` degrading to
unspecified while a `required` or named choice fails instead of being
silently dropped.

translate's own tool-argument helpers stay in place until the delivery
path switches to the new package in a follow-up change.
@guyu233
guyu233 force-pushed the pr/toolcall-contract-core branch from 23f152a to 47389a5 Compare December 4, 2026 08:01
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