genkit icon indicating copy to clipboard operation
genkit copied to clipboard

[plugins] Anthropic Python: thinking config modes + model-aware validation

Open hilariie opened this issue 5 months ago • 0 comments

Parent: #5617 (Phase A, P0: item 11)

Why

The request path only understands enabled + budget_tokens; disabled, adaptive, and display are silently ignored. Worse, the manual-budget_tokens shape is exactly the form that newer 4.6/4.7/4.8 models reject under the current API, so thinking may be effectively non-functional across much of the shipped registry, surfacing as raw API 400s rather than anything actionable.

Matching the JS thinking modes makes the feature usable and predictable across the current model lineup, and turns a raw API 400 into a clear, local error.

Verify first (blocks design)

Before coding, confirm against the live Anthropic API whether 4.6/4.7/4.8 actually reject the manual budget_tokens shape, and what they accept instead (adaptive, or enabled with no manual budget). The whole request-shape decision — send budget_tokens vs force adaptive on newer models — hangs on this. Mirror the Go anthropic_live_test.go approach. Do not build the validation table on the assumption alone.

What needs to be done

  • Support the full set of thinking modes (enabled with budget, disabled, and adaptive with display), mapped to the correct Anthropic request shape, mirroring the JS thinking schema.
  • Validate combinations in a model-aware way (e.g. newer models that reject manual budgets or disabled thinking) so callers get a clear error instead of a raw 400. Keep enabled and adaptive mutually exclusive, and require a budget when enabled.
  • Enforce the max_tokens > thinking.budget_tokens API constraint. The default max_tokens is 4096 (models.py:61,202); a caller-supplied budget at or above it produces a raw 400. When enabled with a budget, auto-raise max_tokens to clear the budget (or validate and error locally), so thinking does not silently 400.

Dependencies

  • Typed config schema (item 33, #5627 ) for the typed modes.
  • Thinking response side (items 12-14, #5628 ) so the signature round-trip is testable.

Acceptance

  • All thinking modes are honored and sent in the correct shape.
  • Invalid or unsupported combinations are caught locally with a clear error rather than a raw API failure.
  • Tests cover each mode and the validation paths.

Reference

  • Current handling: py/plugins/anthropic/src/genkit/plugins/anthropic/models.py:217-229.
  • JS target: js/plugins/anthropic/src/types.ts:68-101 (ThinkingConfigSchema).

hilariie avatar Jun 26 '26 11:06 hilariie