You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(anthropic): add task_budget for Anthropic models
Adds a new 'task_budget' configuration field forwarded to Anthropic as
'output_config.task_budget'. The field caps the total number of tokens a
Claude model may spend across a multi-step agentic task (combined thinking,
tool calls, and final output), letting long-running agents self-regulate
effort without a tight per-call max_tokens.
Implementation:
- New TaskBudget type in pkg/config/latest with custom YAML/JSON marshaling
that accepts either an integer shorthand (interpreted as a 'tokens'
budget) or the full {type, total} object form. 'task_budget: 0' disables
the feature.
- Added as an inheritable field on both ModelConfig and ProviderConfig,
cascaded through applyProviderDefaults so models inherit provider-level
defaults.
- When set, CreateChatCompletionStream routes through the Beta Messages API
via a new configureTaskBudget helper that both appends the required
'task-budgets-2026-03-13' beta header and attaches the task_budget
payload through the SDK's SetExtraFields escape hatch (anthropic-sdk-go
v1.36.0 does not yet model the field natively).
- Configurable on any Claude model: docker-agent does not gate by model
name. Only Claude Opus 4.7 honors the field today; other models will
reject it.
Tests:
- Table-driven (un)marshaling, validation, and IsZero/AsMap coverage for
TaskBudget, including 'task_budget: 0' disables the feature.
- Unit tests for configureTaskBudget (no-op on nil/zero, attaches payload
and beta header, coexists with existing OutputConfig fields).
- Integration tests with a real httptest server asserting both the happy
path (Beta routing, anthropic-beta header, request body shape) and the
disabled path (no header, no payload).
- Updated ModelConfig clone test to cover the new pointer field.
Docs & schema:
- agent-schema.json: task_budget added under ModelConfig and ProviderConfig.
- examples/task_budget.yaml: demonstrates integer shorthand and object form.
- docs/: updated configuration/models, configuration/overview,
concepts/models, providers/anthropic, and providers/custom pages.
Assisted-By: docker-agent
"description": "Default total-token budget for an agentic task (forwarded to Anthropic as `output_config.task_budget`, with the required `task-budgets-2026-03-13` beta header attached automatically). Configurable on any Claude model — docker-agent does not gate by model name — but at the time of writing only Claude Opus 4.7 honors it. Accepts an integer token count or an object {type: tokens, total: N}.",
177
+
"oneOf": [
178
+
{
179
+
"type": "integer",
180
+
"minimum": 0,
181
+
"description": "Token budget for the full task (combined thinking, tool calls, and output)."
182
+
},
183
+
{
184
+
"type": "object",
185
+
"properties": {
186
+
"type": {
187
+
"type": "string",
188
+
"enum": ["tokens"],
189
+
"description": "Budget kind. Only \"tokens\" is supported today."
190
+
},
191
+
"total": {
192
+
"type": "integer",
193
+
"minimum": 0,
194
+
"description": "Total budget value."
195
+
}
196
+
},
197
+
"required": ["total"],
198
+
"additionalProperties": false
199
+
}
200
+
]
174
201
}
175
202
},
176
203
"additionalProperties": false
@@ -649,6 +676,38 @@
649
676
32768
650
677
]
651
678
},
679
+
"task_budget": {
680
+
"description": "Total-token budget for a full agentic task (forwarded to Anthropic as `output_config.task_budget`, with the required `task-budgets-2026-03-13` beta header attached automatically). Limits the combined tokens spent on thinking, tool calls, and output across the whole task. Configurable on any Claude model — docker-agent does not gate by model name — but at the time of writing only Claude Opus 4.7 honors it. Accepts an integer token count or an object {type: tokens, total: N}.",
681
+
"oneOf": [
682
+
{
683
+
"type": "integer",
684
+
"minimum": 0,
685
+
"description": "Total token budget for the task (e.g., 128000)."
686
+
},
687
+
{
688
+
"type": "object",
689
+
"properties": {
690
+
"type": {
691
+
"type": "string",
692
+
"enum": ["tokens"],
693
+
"description": "Budget kind. Only \"tokens\" is supported today."
694
+
},
695
+
"total": {
696
+
"type": "integer",
697
+
"minimum": 0,
698
+
"description": "Total budget value."
699
+
}
700
+
},
701
+
"required": ["total"],
702
+
"additionalProperties": false
703
+
}
704
+
],
705
+
"examples": [
706
+
64000,
707
+
128000,
708
+
{ "type": "tokens", "total": 128000 }
709
+
]
710
+
},
652
711
"routing": {
653
712
"type": "array",
654
713
"description": "Routing rules for request-based model selection. When configured, this model becomes a router that selects the best model based on the user's input. The model's provider/model fields define the fallback model.",
| `task_budget` | int/object | Default total token budget for an agentic task (forwarded to Anthropic; honored by Claude Opus 4.7 today). Integer shorthand or `{type: tokens, total: N}`. | — |
111
112
| `provider_opts` | object | Provider-specific options passed through to the client. | — |
0 commit comments