-
Notifications
You must be signed in to change notification settings - Fork 281
feat: add per-toolset model routing via model field on toolsets #2015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dgageot
merged 1 commit into
docker:main
from
dgageot:board/fix-this-per-tool-model-routing-gordon-u-d38bede0
Mar 10, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #!/usr/bin/env docker agent run | ||
|
|
||
| # Per-Tool Model Routing Example | ||
| # | ||
| # This example demonstrates how to use the `model` field on toolsets | ||
| # to automatically route specific tool results through a cheaper/faster | ||
| # model, while keeping the agent's primary model for complex reasoning. | ||
| # | ||
| # When the LLM calls a tool from a toolset with a `model` field, the | ||
| # next LLM turn (processing the tool results) uses the specified model | ||
| # instead of the agent's primary model. This is a one-shot override: | ||
| # subsequent turns return to the primary model. | ||
|
|
||
| models: | ||
| primary: | ||
| provider: anthropic | ||
| model: claude-sonnet-4-5 | ||
| fast: | ||
| provider: anthropic | ||
| model: claude-haiku-4-5 | ||
|
|
||
| agents: | ||
| root: | ||
| model: primary | ||
| description: > | ||
| An assistant that uses a fast model for simple tool operations | ||
| and the primary model for complex reasoning. | ||
| instruction: > | ||
| You are a helpful assistant. Use the available tools to help the user. | ||
| toolsets: | ||
| # The filesystem toolset uses the fast model to process results. | ||
| # Reading files and listing directories are simple operations that | ||
| # don't need the most capable model to interpret. | ||
| - type: filesystem | ||
| model: fast | ||
|
|
||
| # The shell toolset also uses the fast model. Most shell command | ||
| # outputs (ls, cat, grep, etc.) are straightforward to interpret. | ||
| - type: shell | ||
| model: fast | ||
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package runtime | ||
|
|
||
| import ( | ||
| "log/slog" | ||
|
|
||
| "github.com/docker/docker-agent/pkg/tools" | ||
| ) | ||
|
|
||
| // resolveToolCallModelOverride returns the per-toolset model override from the | ||
| // given tool calls, or "" if none. When multiple tools specify different | ||
| // overrides, the first one wins. | ||
| func resolveToolCallModelOverride(calls []tools.ToolCall, agentTools []tools.Tool) string { | ||
| if len(calls) == 0 { | ||
| return "" | ||
| } | ||
|
|
||
| toolMap := make(map[string]tools.Tool, len(agentTools)) | ||
| for _, t := range agentTools { | ||
| toolMap[t.Name] = t | ||
| } | ||
|
|
||
| for _, call := range calls { | ||
| if t, ok := toolMap[call.Function.Name]; ok && t.ModelOverride != "" { | ||
| slog.Debug("Per-tool model override detected", | ||
| "tool", call.Function.Name, "model", t.ModelOverride) | ||
| return t.ModelOverride | ||
| } | ||
| } | ||
|
|
||
| return "" | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package runtime | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/docker/docker-agent/pkg/tools" | ||
| ) | ||
|
|
||
| func TestResolveToolCallModelOverride_NoCalls(t *testing.T) { | ||
| result := resolveToolCallModelOverride(nil, nil) | ||
| assert.Empty(t, result) | ||
| } | ||
|
|
||
| func TestResolveToolCallModelOverride_NoOverride(t *testing.T) { | ||
| agentTools := []tools.Tool{ | ||
| {Name: "read_file"}, | ||
| {Name: "write_file"}, | ||
| } | ||
| calls := []tools.ToolCall{ | ||
| {Function: tools.FunctionCall{Name: "read_file"}}, | ||
| } | ||
|
|
||
| result := resolveToolCallModelOverride(calls, agentTools) | ||
| assert.Empty(t, result) | ||
| } | ||
|
|
||
| func TestResolveToolCallModelOverride_SingleOverride(t *testing.T) { | ||
| agentTools := []tools.Tool{ | ||
| {Name: "read_file", ModelOverride: "openai/gpt-4o-mini"}, | ||
| {Name: "write_file"}, | ||
| } | ||
| calls := []tools.ToolCall{ | ||
| {Function: tools.FunctionCall{Name: "read_file"}}, | ||
| } | ||
|
|
||
| result := resolveToolCallModelOverride(calls, agentTools) | ||
| assert.Equal(t, "openai/gpt-4o-mini", result) | ||
| } | ||
|
|
||
| func TestResolveToolCallModelOverride_FirstOverrideWins(t *testing.T) { | ||
| agentTools := []tools.Tool{ | ||
| {Name: "read_file", ModelOverride: "openai/gpt-4o-mini"}, | ||
| {Name: "search_kb", ModelOverride: "anthropic/claude-haiku"}, | ||
| } | ||
| calls := []tools.ToolCall{ | ||
| {Function: tools.FunctionCall{Name: "read_file"}}, | ||
| {Function: tools.FunctionCall{Name: "search_kb"}}, | ||
| } | ||
|
|
||
| result := resolveToolCallModelOverride(calls, agentTools) | ||
| assert.Equal(t, "openai/gpt-4o-mini", result) | ||
| } | ||
|
|
||
| func TestResolveToolCallModelOverride_MixedOverrideAndNonOverride(t *testing.T) { | ||
| agentTools := []tools.Tool{ | ||
| {Name: "read_file"}, | ||
| {Name: "search_kb", ModelOverride: "openai/gpt-4o-mini"}, | ||
| } | ||
| calls := []tools.ToolCall{ | ||
| {Function: tools.FunctionCall{Name: "read_file"}}, | ||
| {Function: tools.FunctionCall{Name: "search_kb"}}, | ||
| } | ||
|
|
||
| // read_file has no override, search_kb does. Since read_file is first | ||
| // but has no override, we skip it and use search_kb's. | ||
| result := resolveToolCallModelOverride(calls, agentTools) | ||
| assert.Equal(t, "openai/gpt-4o-mini", result) | ||
| } | ||
|
|
||
| func TestResolveToolCallModelOverride_UnknownTool(t *testing.T) { | ||
| agentTools := []tools.Tool{ | ||
| {Name: "read_file"}, | ||
| } | ||
| calls := []tools.ToolCall{ | ||
| {Function: tools.FunctionCall{Name: "unknown_tool"}}, | ||
| } | ||
|
|
||
| result := resolveToolCallModelOverride(calls, agentTools) | ||
| assert.Empty(t, result) | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.