feat(llm): ReasoningEffort request option and ErrUnsupported sentinel

Groundwork for the provider phase: reasoning levels map to native knobs
(OpenAI reasoning_effort, Ollama think); ErrUnsupported marks declared
capability mismatches that chains advance past without health penalty.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-10 12:40:47 +02:00
parent 0d0e8e069e
commit 323558ed72
4 changed files with 25 additions and 2 deletions
+8 -1
View File
@@ -26,6 +26,13 @@ const (
// condition. Chains advance past it without penalizing the target's health.
var ErrModelNotFound = errors.New("model not found")
// ErrUnsupported marks a request the target cannot serve by declaration —
// e.g. images that cannot be normalized to its capabilities, or a feature
// (tools, structured output) it does not support. Permanent for the target,
// but chains advance past it without penalizing health: another element may
// well be able to serve the request.
var ErrUnsupported = errors.New("request unsupported by target")
// APIError is a structured provider error carrying enough context to
// classify it and to debug it.
type APIError struct {
@@ -96,7 +103,7 @@ func Classify(err error) ErrorClass {
if errors.Is(err, context.DeadlineExceeded) {
return ClassTransient
}
if errors.Is(err, ErrModelNotFound) {
if errors.Is(err, ErrModelNotFound) || errors.Is(err, ErrUnsupported) {
return ClassPermanent
}
if errors.Is(err, syscall.ECONNREFUSED) || errors.Is(err, syscall.ECONNRESET) {
+12
View File
@@ -37,6 +37,12 @@ type Request struct {
// StopSequences halt generation when emitted.
StopSequences []string
// ReasoningEffort requests a reasoning/thinking level from models that
// support one: "low", "medium", or "high" (empty = provider default).
// Providers map it to their native knob (OpenAI reasoning_effort,
// Ollama think levels) and ignore it where no mapping exists.
ReasoningEffort string
}
// Option mutates a Request before it is sent. Options passed to Generate or
@@ -88,6 +94,12 @@ func WithStopSequences(stops ...string) Option {
return func(r *Request) { r.StopSequences = stops }
}
// WithReasoningEffort requests a reasoning/thinking level ("low", "medium",
// "high") from models that support one.
func WithReasoningEffort(level string) Option {
return func(r *Request) { r.ReasoningEffort = level }
}
// Apply returns a copy of the request with all options applied. Providers
// and wrappers call this once at the top of Generate/Stream.
func (r Request) Apply(opts ...Option) Request {