Skip to content

feat: forward sampling provider_opts (top_k, repetition_penalty) to provider APIs#2226

Merged
dgageot merged 2 commits intodocker:mainfrom
dgageot:board/docker-agent-issue-2220-feasibility-chec-c088f140
Mar 23, 2026
Merged

feat: forward sampling provider_opts (top_k, repetition_penalty) to provider APIs#2226
dgageot merged 2 commits intodocker:mainfrom
dgageot:board/docker-agent-issue-2220-feasibility-chec-c088f140

Conversation

@dgageot
Copy link
Member

@dgageot dgageot commented Mar 23, 2026

Closes #2220

Adds support for passing sampling parameters via provider_opts to all provider backends. This enables custom OpenAI-compatible providers (vLLM, Ollama, llama.cpp) to receive parameters like top_k, repetition_penalty, min_p, and seed.

Provider support

Parameter OpenAI/Custom Anthropic Gemini Bedrock
top_k ✅ (extra field) ✅ (native) ✅ (native) ✅ (additional field)
repetition_penalty ✅ (extra field)
min_p ✅ (extra field)
seed ✅ (native)

Example

providers:
  custom:
    type: openai
    base_url: http://localhost:8080/v1
    provider_opts:
      top_k: 40
      repetition_penalty: 1.15

Changes

  • New pkg/model/provider/providerutil package with helpers for extracting typed values from provider_opts
  • OpenAI: forwards sampling keys as extra body fields via SetExtraFields; seed set natively
  • Anthropic: sets native TopK field on both standard and beta clients
  • Gemini: sets native TopK on GenerateContentConfig
  • Bedrock: passes top_k via AdditionalModelRequestFields; refactored thinking detection to avoid losing top_k on early returns
  • Updated agent-schema.json with documentation for new sampling parameters

@dgageot dgageot requested a review from a team as a code owner March 23, 2026 11:52
docker-agent[bot]

This comment was marked as outdated.

@dgageot dgageot force-pushed the board/docker-agent-issue-2220-feasibility-chec-c088f140 branch from a88e73a to 56a3913 Compare March 23, 2026 12:04
dgageot added 2 commits March 23, 2026 14:49
…) to provider APIs

Add support for passing sampling parameters via provider_opts to all
provider backends. This enables custom OpenAI-compatible providers
(vLLM, Ollama, llama.cpp) to receive parameters like top_k,
repetition_penalty, min_p, and seed that they support but the native
OpenAI API does not.

Provider support:
- OpenAI/custom: top_k, repetition_penalty, min_p, typical_p via
  SetExtraFields; seed via native field
- Anthropic: top_k via native TopK field
- Gemini: top_k via native TopK field
- Bedrock: top_k via AdditionalModelRequestFields

Also refactors Bedrock buildAdditionalModelRequestFields to avoid
early returns that would discard top_k when thinking budget is
invalid, and extracts isThinkingEnabled() to decouple thinking
detection from additional fields presence.

Assisted-By: docker-agent
…r provider_opts mismatches

- Default interleaved_thinking to true, matching schema documentation
- Warn when thinking_budget is set but interleaved_thinking is explicitly disabled
- Add debug logging in providerutil when provider_opts values have wrong types

Assisted-By: docker-agent
@dgageot dgageot force-pushed the board/docker-agent-issue-2220-feasibility-chec-c088f140 branch from 56a3913 to 4520285 Compare March 23, 2026 13:56
@dgageot dgageot merged commit f92ffe7 into docker:main Mar 23, 2026
4 checks passed
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.

[sampling parameters] new parameters

2 participants