blib/lib/Langertha/Reasoning/Profile.pm

filter: Statementstmt 63.4% 118 / 186 Branchbran 41.4% 29 / 70 Conditioncond 31.5% 12 / 38 MC/DCmcdc 13.6% 3 / 22 Subroutinesub 58.8% 20 / 34 Podpod 100% 13 / 13 totaltotal 53.7% 195 / 363 CC 54 SCAR 23.4
CC
54
Cov
54%
_match
33.7
_match
33.7
gemini_level_for
11.3
CRAP 10.4
« blib/lib/Langertha/Plugin/Langfuse.pm ↑ Summary blib/lib/Langertha/Runtime/Metrics/OTLP.pm »
1 package Langertha::Reasoning::Profile;
2 # ABSTRACT: Typed per-model reasoning wire-truth (accepted vocabulary + numeric bounds)
3 193 our $VERSION = '0.505';
4 193 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 193 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 193 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 # The normalized ascending reasoning vocabulary, defined ONCE and reused. A
10 # namespaced type name so it cannot collide with any other 'ReasoningLevel'
11 # registered in the process (Moose croaks on enum-name redefinition).
12 193 enum 'Langertha::Reasoning::Level'
13 => [qw( none minimal low medium high xhigh max )];
14 193 enum 'Langertha::Reasoning::Control'
15 => [qw( effort budget boolean none )];
16 193 enum 'Langertha::Reasoning::DisableForm'
17 => [qw( absent explicit_none think_false budget_zero thinking_disabled )];
18 193 enum 'Langertha::Reasoning::ThinkingOn'
19 => [qw( adaptive enabled )];
20 193 enum 'Langertha::Reasoning::Wire'
21 => [qw( openai responses anthropic gemini ollama )];
22  
23 # The full Anthropic Messages-API output_config.effort vocabulary (the
24 # normalized none/minimal have no Anthropic equivalent and drop). The default
25 # the generic-claude, Fable/Mythos and provider-default profiles reuse — but NOT
26 # uniform across every Claude model: Claude 4.6 (opus/sonnet) drops xhigh, so
27 # anthropic_effort_ok checks the resolved profile's own `levels` rather than this
28 # module-level set (karr k177).
29 193 my @ANTHROPIC_EFFORT_LEVELS = qw( low medium high xhigh max );
30  
31 # Normalized effort -> Gemini 3 thinkingLevel base vocabulary
32 # (minimal|low|medium|high); then clamped down to the family's accepted subset.
33 193 my %GEMINI_BASE = (
34 none => 'minimal',
35 minimal => 'minimal',
36 low => 'low',
37 medium => 'medium',
38 high => 'high',
39 xhigh => 'high',
40 max => 'high',
41 );
42 193 my %GEMINI_ORDER = ( minimal => 0, low => 1, medium => 2, high => 3 );
43  
44 # Normalized effort -> GPT-OSS Ollama options.think level (low|medium|high|max).
45 # GPT-OSS always reasons — there is no "off" — so 'none' (and 'minimal') map to
46 # the floor 'low' (live-probed 2026-09-17 via ollama.com gpt-oss:20b, k175).
47 193 my %OLLAMA_LEVEL = (
48 none => 'low',
49 minimal => 'low',
50 low => 'low',
51 medium => 'medium',
52 high => 'high',
53 xhigh => 'max',
54 max => 'max',
55 );
56  
57 193 has model_match => (
58 is => 'ro',
59 isa => 'Str | RegexpRef',
60 );
61  
62  
63 193 has control => (
64 is => 'ro',
65 isa => 'Langertha::Reasoning::Control',
66 required => 1,
67 );
68  
69  
70 has levels => (
71 is => 'ro',
72 isa => 'ArrayRef[Langertha::Reasoning::Level]',
73 120 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
74 193 );
75  
76  
77 has levels_by_wire => (
78 is => 'ro',
79 isa => 'HashRef[ArrayRef[Langertha::Reasoning::Level]]',
80 659 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
81 193 );
82  
83  
84 193 has ollama_levels => (
85 is => 'ro',
86 isa => 'ArrayRef[Langertha::Reasoning::Level]',
87 predicate => 'has_ollama_levels',
88 );
89  
90  
91 193 has can_disable => (
92 is => 'ro',
93 isa => 'Bool',
94 default => 1,
95 );
96  
97  
98 193 has default_reasoning_off => (
99 is => 'ro',
100 isa => 'Bool',
101 default => 0,
102 );
103  
104  
105 193 has is_reasoning_model => (
106 is => 'ro',
107 isa => 'Bool',
108 default => 0,
109 );
110  
111  
112 193 has disable_form => (
113 is => 'ro',
114 isa => 'Langertha::Reasoning::DisableForm',
115 default => 'absent',
116 );
117  
118  
119 193 has thinking_on => (
120 is => 'ro',
121 isa => 'Langertha::Reasoning::ThinkingOn',
122 predicate => 'has_thinking_on',
123 );
124  
125  
126 193 has wire_format => (
127 is => 'ro',
128 isa => 'Langertha::Reasoning::Wire',
129 required => 1,
130 );
131  
132  
133 193 has is_gemini3 => (
134 is => 'ro',
135 isa => 'Bool',
136 default => 0,
137 );
138  
139  
140 193 for my $bound (qw( budget_min budget_max off_value dynamic_value )) {
141 772 has $bound => (
142 is => 'ro',
143 isa => 'Int',
144 predicate => 'has_' . $bound,
145 );
146 }
147  
148  
149  
150  
151 193 has source => (
152 is => 'ro',
153 isa => 'Str',
154 default => '',
155 );
156  
157  
158  
159 1755 ▶sub fable_class { return $_[0]->can_disable ? 0 : 1 }
Subroutine fable_class: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->can_disable ? : 1683 72 1755
160  
161  
162 202 ▶sub thinking_toggle_for {
Subroutine thinking_toggle_for: called CC=4 SCAR=18.8
Pod documented
163 0 ▶ my ( $self, $effort ) = @_;
Subroutine thinking_toggle_for: not called CC=4 SCAR=18.8
Pod documented
164 0 ▶ return unless $self->has_thinking_on;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->has_thinking_on 0 202 202
unless $self->has_thinking_on 0 0 0
165 0 ▶ if ( $effort eq 'none' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($effort eq "none") 28 174 202
if ($effort eq "none") 0 0 0
166 0 ▶ return unless $self->disable_form eq 'thinking_disabled';
Branch: 2 branches
BranchTrueFalseTotal
unless $self->disable_form eq "thinking_disabled" 10 18 28
unless $self->disable_form eq "thinking_disabled" 0 0 0
167 0 return { type => 'disabled' };
168 }
169 0 return { type => $self->thinking_on };
170 }
171  
172  
173 3904 ▶sub effort_accepted_on {
Subroutine effort_accepted_on: called CC=3 SCAR=14.2
Pod documented
174 0 ▶ my ( $self, $wire, $effort ) = @_;
Subroutine effort_accepted_on: not called CC=3 SCAR=14.2
Pod documented
175 0 my $set = $self->levels_by_wire->{$wire};
176 0 ▶ return 1 unless defined $set;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $set 2614 1290 3904
unless defined $set 0 0 0
177 0 ▶ return ( grep { $_ eq $effort } @$set ) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
grep({$_ eq $effort;} @$set) ? : 864 426 1290
grep({$_ eq $effort;} @$set) ? : 0 0 0
178 }
179  
180  
181 1732 ▶sub anthropic_effort_ok {
Subroutine anthropic_effort_ok: called CC=2 SCAR=9.2
Pod documented
182 0 ▶ my ( $self, $effort ) = @_;
Subroutine anthropic_effort_ok: not called CC=2 SCAR=9.2
Pod documented
183 0 ▶ return ( grep { $_ eq $effort } @{ $self->levels } ) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
grep({$_ eq $effort;} @{$self->levels;}) ? : 1214 518 1732
grep({$_ eq $effort;} @{$self->levels;}) ? : 0 0 0
184 }
185  
186  
187 1660 ▶sub gemini_level_for {
Subroutine gemini_level_for: called CC=6 SCAR=24.3
Pod documented
188 0 ▶ my ( $self, $effort ) = @_;
Subroutine gemini_level_for: not called CC=6 SCAR=24.3
Pod documented
189 0 ▶ unless ( $self->is_gemini3 ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->is_gemini3) 1501 159 1660
unless ($self->is_gemini3) 0 0 0
190 0 ▶ return ( $effort eq 'high' || $effort eq 'xhigh' || $effort eq 'max' )
Branch: 2 branches
BranchTrueFalseTotal
$effort eq 'high' || $effort eq 'xhigh' || $effort eq 'max' ? : 645 856 1501
$effort eq 'high' || $effort eq 'xhigh' || $effort eq 'max' ? : 0 0 0
Condition50%6/12
$effort eq "high" or $effort eq "xhigh" or $effort eq "max"
l!l&&r!l&&!r
430215856
$effort eq "high" or $effort eq "xhigh"
l!l&&r!l&&!r
2172131071
$effort eq "high" or $effort eq "xhigh" or $effort eq "max"
l!l&&r!l&&!r
000
$effort eq "high" or $effort eq "xhigh"
l!l&&r!l&&!r
000
MC/DC100%3/3
$effort eq "high" or $effort eq "xhigh" or $effort eq "max"
$effort eq "high" $effort eq "xhigh" $effort eq "max"
MC/DC0%0/3
$effort eq "high" or $effort eq "xhigh" or $effort eq "max"
$effort eq "high" $effort eq "xhigh" $effort eq "max"
Truth table100%4/4
A or B or C
A= $effort eq "high"B= $effort eq "xhigh"C= $effort eq "max"
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
A or B or C
A= $effort eq "high"B= $effort eq "xhigh"C= $effort eq "max"
ABCresult
1XX1
01X1
0011
0000
191 ? 'high' : 'low';
192 }
193 0 ▶ my $level = $GEMINI_BASE{$effort} // 'low';
Condition25%1/4
$GEMINI_BASE{$effort} // "low"
l!l
1590
$GEMINI_BASE{$effort} // "low"
l!l
00
MC/DC0%0/1
$GEMINI_BASE{$effort} // "low"
$GEMINI_BASE{$effort}
MC/DC0%0/1
$GEMINI_BASE{$effort} // "low"
$GEMINI_BASE{$effort}
Truth table50%1/2
A
A= $GEMINI_BASE{$effort}
Aresult
11
00
Truth table0%0/2
A
A= $GEMINI_BASE{$effort}
Aresult
11
00
194 0 return $self->_clamp_gemini_level($level);
195 }
196  
197 # Clamp a base Gemini level down to the profile's accepted set: keep it if
198 # accepted, else drop to the highest accepted level below it, or rise to the
199 # lowest accepted level when it sits below the family's floor. The accepted sets
200 # are contiguous ranges, so this reproduces the family clamps exactly.
201 159 ▶sub _clamp_gemini_level {
Subroutine _clamp_gemini_level: called CC=5 SCAR=20.9
202 0 ▶ my ( $self, $level ) = @_;
Subroutine _clamp_gemini_level: not called CC=5 SCAR=20.9
203 0 my %ok = map { $_ => 1 } @{ $self->levels };
204 0 ▶ return $level if $ok{$level};
Branch: 2 branches
BranchTrueFalseTotal
if $ok{$level} 118 41 159
if $ok{$level} 0 0 0
205 0 my @sorted = sort { $GEMINI_ORDER{$a} <=> $GEMINI_ORDER{$b} }
206 0 grep { defined $GEMINI_ORDER{$_} } @{ $self->levels };
207 0 my $target = $GEMINI_ORDER{$level};
208 0 my $result;
209 0 for my $lvl (@sorted) {
210 0 ▶ $result = $lvl if $GEMINI_ORDER{$lvl} < $target;
Branch: 2 branches
BranchTrueFalseTotal
if $GEMINI_ORDER{$lvl} < $target 7 98 105
if $GEMINI_ORDER{$lvl} < $target 0 0 0
211 }
212 0 ▶ return defined $result ? $result : $sorted[0];
Branch: 2 branches
BranchTrueFalseTotal
defined $result ? : 7 34 41
defined $result ? : 0 0 0
213 }
214  
215  
216 33 ▶sub ollama_level_for {
Subroutine ollama_level_for: called CC=2 SCAR=10.9
Pod documented
217 0 ▶ my ( $self, $effort ) = @_;
Subroutine ollama_level_for: not called CC=2 SCAR=10.9
Pod documented
218 0 ▶ return $OLLAMA_LEVEL{$effort} // 'low';
Condition25%1/4
$OLLAMA_LEVEL{$effort} // "low"
l!l
330
$OLLAMA_LEVEL{$effort} // "low"
l!l
00
MC/DC0%0/1
$OLLAMA_LEVEL{$effort} // "low"
$OLLAMA_LEVEL{$effort}
MC/DC0%0/1
$OLLAMA_LEVEL{$effort} // "low"
$OLLAMA_LEVEL{$effort}
Truth table50%1/2
A
A= $OLLAMA_LEVEL{$effort}
Aresult
11
00
Truth table0%0/2
A
A= $OLLAMA_LEVEL{$effort}
Aresult
11
00
219 }
220  
221 # ---------------------------------------------------------------------------
222 # The registry — one ordered, most-specific-first table. Built lazily so the
223 # class is fully defined (and immutable) before any profile is constructed.
224 # ---------------------------------------------------------------------------
225 193 my @REGISTRY;
226 my $DEFAULT;
227  
228 # developers.openai.com/api/docs/guides/reasoning + per-model pages,
229 # advisor-verified 2026-09-01 (karr k140); gpt-6-astra 2026-09-14 (karr k151).
230 193 my $OPENAI_SRC = 'developers.openai.com/api/docs/guides/reasoning; k140 2026-09-01, gpt-6 k151 2026-09-14';
231 # ai.google.dev/gemini-api/docs/thinking level table, verified 2026-09-01
232 # (karr k140); gemini-3.8-flash 2026-09-14 (karr k153).
233 193 my $GEMINI3_SRC = 'ai.google.dev/gemini-api/docs/thinking; k140 2026-09-01, 3.8-flash k153 2026-09-14';
234 # ai.google.dev/gemini-api/docs/thinking budget table (2.5), advisor-verified
235 # 2026-09-16 (karr k173).
236 193 my $GEMINI25_SRC = 'ai.google.dev/gemini-api/docs/thinking budget table; k173 2026-09-16';
237 # ai.google.dev/gemini-api/docs/generate-content/latest-model + the Vertex
238 # gemini-4-argon guide, fetched 2026-10-19 (karr k381) -- doc-sourced, not live.
239 193 my $GEMINI4_SRC = 'ai.google.dev/gemini-api/docs/generate-content/latest-model + Vertex gemini-4-argon guide; k381 2026-10-19 (doc-sourced, not live)';
240 # Self-hosted Qwen3.x reasoning family: the loaded model's chat template — NOT
241 # the vLLM/SGLang/llama.cpp server — fixes the accepted reasoning_effort
242 # vocabulary. Live-probed 2026-09-17 on a cortex vLLM server (karr k79/k180):
243 # Qwen/Qwen3.8-27B-FP8 400s on reasoning_effort=high ("Unexpected reasoning
244 # effort high. Supported types are xhigh (default), medium, and low."), accepting
245 # only none/low/medium/xhigh.
246 193 my $QWEN_SELFHOSTED_SRC = 'live-probed 2026-09-17 cortex vLLM Qwen/Qwen3.8-27B-FP8: reasoning_effort high->400, accepts none/low/medium/xhigh (k79/k180)';
247  
248 # karr k176: 'max' is Responses-only for the gpt-6 and gpt-5.6 generations. The
249 # gpt-5.6 split is live-confirmed (2026-09-16 on gpt-5.6-terra): Chat Completions
250 # reasoning_effort=max -> HTTP 400 ("Supported values are: 'none', 'low',
251 # 'medium', 'high', and 'xhigh'."), Responses reasoning.effort=max -> HTTP 200.
252 # The gpt-6 split is doc-sourced (advisor Azure mirror, same Responses-only-max
253 # pattern) — not live-probed.
254 193 my $OPENAI_K176_LIVE = "$OPENAI_SRC; k176 2026-09-16 live gpt-5.6-terra: chat reasoning_effort=max->400, responses reasoning.effort=max->200";
255 193 my $OPENAI_K176_DOC = "$OPENAI_SRC; k176 gpt-6 max Responses-only (advisor Azure mirror, doc-sourced, not live-probed)";
256 # karr k174: gpt-5.1 is gated (Azure Foundry reasoning table, advisor-verified
257 # 2026-09-16 — doc-sourced, NOT live-probed). Base gpt-5.1 drops minimal/xhigh/max
258 # (none|low|medium|high); gpt-5.1-codex-max re-adds xhigh (still no max). Both
259 # wires identical (xhigh is not Responses-only), so no openai_levels split.
260 193 my $OPENAI_K174_DOC = "$OPENAI_SRC; k174 gpt-5.1 gate (Azure Foundry reasoning table, advisor-verified 2026-09-16, doc-sourced not live)";
261 # karr k177: Claude 4.6 (opus/sonnet) accepts low|medium|high|max but NOT xhigh
262 # — Anthropic's effort doc lists 4.6 under `max` yet not under `xhigh`; 4.7+/5
263 # take the full set. Advisor-verified 2026-09-16 (doc-sourced, NOT live-probed).
264 193 my $ANTHROPIC_K177_DOC = 'platform.claude.com output_config.effort doc; k177 2026-09-16 claude-4.6 no xhigh (advisor-verified, doc-sourced not live)';
265 # karr k208: xAI reasoning page (updated 2026-09-21), advisor-verified
266 # 2026-09-25 — doc-sourced, NOT live-probed (the reply to an off-enum value,
267 # 400 or ignored, is unverified).
268 193 my $XAI_K208_DOC = 'docs.x.ai/developers/model-capabilities/text/reasoning; k208 2026-09-25 (advisor-verified, doc-sourced not live)';
269  
270 # karr k209: MiniMax chat/completions + /anthropic request schemas, advisor
271 # 2026-09-25 — doc-sourced, NOT live-probed.
272 193 my $MINIMAX_K209_DOC = 'platform.minimax.io openapi-chat-openai.json + openapi-chat-anthropic.json; k209 2026-09-25 (advisor-verified, doc-sourced not live)';
273 # karr k215: Kimi Messages API + Claude Code guide, advisor 2026-09-25 —
274 # doc-sourced, NOT live-probed (budget_tokens on `enabled` unverified).
275 193 my $KIMI_K215_DOC = 'platform.kimi.ai docs/api/messages.md + docs/guide/claude-code-kimi.md; k215 2026-09-25 (advisor-verified, doc-sourced not live; budget_tokens unverified)';
276 # $levels is the superset a family accepts on the `responses` (Responses API)
277 # wire; $extra{openai_levels} is the narrower Chat Completions set, defaulting to
278 # $levels when the two wires agree. The k176 per-wire max split is exactly this
279 # openai_levels-vs-levels divergence for the gpt-6 / gpt-5.6 generations.
280 270 ▶sub _openai_profile {
Subroutine _openai_profile: called CC=2 SCAR=10.3
281 0 ▶ my ( $match, $levels, %extra ) = @_;
Subroutine _openai_profile: not called CC=2 SCAR=10.3
282 0 ▶ my $openai_levels = delete $extra{openai_levels} // $levels;
Condition33%2/6
delete $extra{"openai_levels"} // $levels
l!l&&r!l&&!r
602100
delete $extra{"openai_levels"} // $levels
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $extra{"openai_levels"} // $levels
delete $extra{"openai_levels"} $levels
MC/DC0%0/2
delete $extra{"openai_levels"} // $levels
delete $extra{"openai_levels"} $levels
Truth table66%2/3
A // B
A= delete $extra{"openai_levels"}B= $levels
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= delete $extra{"openai_levels"}B= $levels
ABresult
1X1
011
000
283 0 return __PACKAGE__->new(
284 model_match => $match,
285 control => 'effort',
286 wire_format => 'openai',
287 levels => $levels,
288 levels_by_wire => { openai => $openai_levels, responses => $levels },
289 source => $OPENAI_SRC,
290 %extra,
291 );
292 }
293  
294 # An OpenAI line whose effort ladder is uncurated: the unlisted-id passthrough
295 # serialization (full normalized enum, no per-wire restriction) with an explicit
296 # reasoning classification (karr k186).
297 90 ▶sub _openai_passthrough {
Subroutine _openai_passthrough: called CC=1 SCAR=1.2
298 0 ▶ my ( $match, $is_reasoning, $source ) = @_;
Subroutine _openai_passthrough: not called CC=1 SCAR=1.2
299 0 return __PACKAGE__->new(
300 model_match => $match,
301 control => 'effort',
302 wire_format => 'openai',
303 levels => [@ANTHROPIC_EFFORT_LEVELS],
304 is_reasoning_model => $is_reasoning,
305 source => $source,
306 );
307 }
308  
309 # A non-reasoning chat carve-out that serializes exactly like the reasoning
310 # family it sits in ($like is that family's resolved profile): only the
311 # classification differs, so the carve-out changes nothing on the reasoning wire
312 # (karr k186).
313 319 ▶sub _non_reasoning_like {
Subroutine _non_reasoning_like: called CC=1 SCAR=1.2
314 0 ▶ my ( $match, $like ) = @_;
Subroutine _non_reasoning_like: not called CC=1 SCAR=1.2
315 0 return $like->meta->clone_object( $like,
316 model_match => $match,
317 is_reasoning_model => 0,
318 source => $like->source . "; k186 non-reasoning chat carve-out",
319 );
320 }
321  
322 150 ▶sub _gemini3_profile {
Subroutine _gemini3_profile: called CC=2 SCAR=10.5
323 0 ▶ my ( $match, $levels, $source ) = @_;
Subroutine _gemini3_profile: not called CC=2 SCAR=10.5
324 0 ▶ return __PACKAGE__->new(
Condition33%2/6
$source // $GEMINI3_SRC
l!l&&r!l&&!r
301200
$source // $GEMINI3_SRC
l!l&&r!l&&!r
000
MC/DC0%0/2
$source // $GEMINI3_SRC
$source $GEMINI3_SRC
MC/DC0%0/2
$source // $GEMINI3_SRC
$source $GEMINI3_SRC
Truth table66%2/3
A // B
A= $sourceB= $GEMINI3_SRC
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $sourceB= $GEMINI3_SRC
ABresult
1X1
011
000
325 model_match => $match,
326 control => 'effort',
327 wire_format => 'gemini',
328 is_gemini3 => 1,
329 levels => $levels,
330 source => $source // $GEMINI3_SRC,
331 );
332 }
333  
334 10364 ▶sub _ensure_registry {
Subroutine _ensure_registry: called CC=2 SCAR=9.2
335 0 ▶ return if @REGISTRY;
Subroutine _ensure_registry: not called CC=2 SCAR=9.2
Branch: 2 branches
BranchTrueFalseTotal
if @REGISTRY 10335 29 10364
if @REGISTRY 0 0 0
336  
337 # Provider default: an unrecognized id keeps the full normalized enum on the
338 # openai wire (no per-wire restriction), takes the fixed set on anthropic, and
339 # the binary collapse on gemini. Shared by every OpenAI-compatible provider
340 # (and no model at all). Never a reasoning model (is_reasoning_model 0). Built
341 # first: a chat carve-out whose family id matches no row copies the default,
342 # so the registry must not depend on a passthrough row existing (karr k196).
343 0 $DEFAULT = __PACKAGE__->new(
344 model_match => '',
345 control => 'effort',
346 wire_format => 'openai',
347 levels => [@ANTHROPIC_EFFORT_LEVELS],
348 is_reasoning_model => 0,
349 source => 'normalized OpenAI superset passthrough (unlisted id)',
350 );
351  
352 0 my @families = _family_profiles();
353  
354 # Non-reasoning chat carve-outs (karr k186): gpt-5-chat and every dotted
355 # gpt-5.N-chat id (gpt-5.1-chat-latest, gpt-5.2-chat-latest, ...) are
356 # non-reasoning chat models inside reasoning families. Listed first so they
357 # win over the family patterns. Generated per digit (karr k196): each copies
358 # the profile of its own family id (gpt-5.N-chat -> gpt-5.N), so a newly
359 # curated gpt-5.N family is picked up without a hand-kept mapping. The
360 # literal "-chat" after the digit already rejects a second digit.
361 my @carve_outs = map {
362 0 my ( $match, $like_id ) = @$_;
363 0 _non_reasoning_like( $match, _match( $like_id, @families ) );
364 } (
365 [ qr/\Agpt-5-chat/, 'gpt-5' ],
366 0 map { my $digit = $_; [ qr/\Agpt-5\.${digit}-chat/, "gpt-5.$digit" ] } 0 .. 9,
367 );
368  
369 0 @REGISTRY = ( @carve_outs, @families );
370 0 return;
371 }
372  
373 # The family rows, most-specific-first (everything except the chat carve-outs
374 # and the provider default).
375 30 ▶sub _family_profiles {
Subroutine _family_profiles: called CC=1 SCAR=1.2
376 return (
377 # Anthropic always-on Fable/Mythos: matched before the generic claude
378 # family. Case-insensitive substring, mirroring the legacy _is_fable_class.
379 0 ▶ __PACKAGE__->new(
Subroutine _family_profiles: not called CC=1 SCAR=1.2
380 model_match => qr/fable|mythos/i,
381 control => 'effort',
382 wire_format => 'anthropic',
383 levels => [@ANTHROPIC_EFFORT_LEVELS],
384 can_disable => 0,
385 disable_form => 'absent',
386 source => 'Anthropic Messages API; Fable/Mythos always-on thinking, k173 2026-09-16',
387 ),
388  
389 # OpenAI generation ladders. gpt-6 (astra): no none/minimal. gpt-5.6 /
390 # gpt-5.5: none but no minimal. gpt-5.1: gated (karr k174), with a codex-max
391 # carve-out matched first. Legacy gpt-5: minimal but no none/xhigh/max — the
392 # gpt-5(?![.\d]) negative-lookahead keeps it off gpt-5.5/5.6/5.1.
393 # gpt-6 and gpt-5.6 carry a per-wire split (karr k176): 'max' is
394 # Responses-only, so their openai (Chat Completions) set drops max while the
395 # responses set (== levels) keeps it. gpt-5.6 live-confirmed, gpt-6 doc-sourced.
396 # The gpt-6 row also covers its single-digit point releases (gpt-6.1, karr
397 # k201): they keep this doc-sourced ladder rather than an uncurated
398 # passthrough (which would send none/minimal and chat 'max'), so no separate
399 # gpt-6.N row exists. (?!\.\d\d) is the multi-digit guard after the dot:
400 # gpt-6.10 is an unknown id, not gpt-6.
401 _openai_profile( qr/\Agpt-6(?!\d)(?!\.\d\d)/,
402 [qw( low medium high xhigh max )],
403 openai_levels => [qw( low medium high xhigh )],
404 source => $OPENAI_K176_DOC,
405 disable_form => 'absent', can_disable => 1, is_reasoning_model => 1 ),
406 _openai_profile( qr/\Agpt-5\.6(?!\d)/,
407 [qw( none low medium high xhigh max )],
408 openai_levels => [qw( none low medium high xhigh )],
409 source => $OPENAI_K176_LIVE,
410 disable_form => 'explicit_none', is_reasoning_model => 1 ),
411 _openai_profile( qr/\Agpt-5\.5(?!\d)/,
412 [qw( none low medium high xhigh )], disable_form => 'explicit_none',
413 is_reasoning_model => 1 ),
414 # gpt-5.1 (karr k174), most-specific-first: codex-max re-adds xhigh, base
415 # drops minimal/xhigh/max. Both wires identical (xhigh is not Responses-only).
416 # default_reasoning_off: the 5.1 line's no-effort server-side default is
417 # reasoning-OFF (k185 2026-09-19 live) — a bare request does not reason.
418 _openai_profile( qr/\Agpt-5\.1-codex-max/,
419 [qw( none low medium high xhigh )],
420 source => $OPENAI_K174_DOC, disable_form => 'explicit_none',
421 default_reasoning_off => 1, is_reasoning_model => 1 ),
422 _openai_profile( qr/\Agpt-5\.1(?!\d)/,
423 [qw( none low medium high )],
424 source => $OPENAI_K174_DOC, disable_form => 'explicit_none',
425 default_reasoning_off => 1, is_reasoning_model => 1 ),
426 # gpt-5.2 / gpt-5.4: same no-effort-default-off generation as gpt-5.1
427 # (reasoning_tokens=0 with no effort, a non-default temperature honored --
428 # k185 2026-09-19 live). Their accepted effort ladder is not yet live-curated,
429 # so they keep the unlisted-id passthrough (full enum, no per-wire restriction)
430 # rather than an invented gate — only the default-reasoning-off signal is
431 # sourced. gpt-5.3, if it appears, falls through to the reasoning-on default.
432 __PACKAGE__->new(
433 model_match => qr/\Agpt-5\.[24](?!\d)/,
434 control => 'effort',
435 wire_format => 'openai',
436 levels => [@ANTHROPIC_EFFORT_LEVELS],
437 default_reasoning_off => 1,
438 is_reasoning_model => 1,
439 source => 'k185 2026-09-19 live: gpt-5.2/5.4 no-effort default reasoning off; effort ladder uncurated (passthrough)',
440 ),
441 _openai_profile( qr/\Agpt-5(?![.\d])/,
442 [qw( minimal low medium high )], disable_form => 'absent',
443 is_reasoning_model => 1 ),
444 # Uncurated OpenAI reasoning lines (karr k186): any other gpt-5.N (5.3, 5.7,
445 # ...) and the o-series are reasoning models, but their effort ladder is not
446 # curated, so they keep the unlisted-id passthrough serialization — only the
447 # reasoning classification is added. Matched after the curated gpt-5.N
448 # families above. Every dotted family pattern ends in (?!\d) (karr k196):
449 # gpt-5.10 is not gpt-5.1, and a multi-digit id matches no gpt-5.N row at
450 # all, so it is an unknown id (non-reasoning, temperature kept). The undotted
451 # gpt-6 and o-series rows carry the same guard (gpt-60, o10 are unknown).
452 _openai_passthrough( qr/\Agpt-5\.\d(?!\d)/, 1,
453 'k186: uncurated gpt-5.N reasoning line; effort ladder passthrough' ),
454 _openai_passthrough( qr/\Ao\d(?!\d)/, 1,
455 'k186: OpenAI o-series reasoning models; effort ladder passthrough' ),
456 # Non-reasoning OpenAI chat models (karr k186), marked explicitly so the
457 # classification never falls out of the default: gpt-4o / gpt-4.1 (and the
458 # rest of gpt-4*). Same passthrough serialization as the unlisted default.
459 _openai_passthrough( qr/\Agpt-4/, 0,
460 'k186: non-reasoning gpt-4 line (gpt-4o, gpt-4.1); effort ladder passthrough' ),
461  
462 # xAI grok (karr k208): grok-4.6 / grok-4.7 (and later single-digit 4.N)
463 # accept low|medium|high|xhigh, grok-4.5 low|medium|high; reasoning cannot
464 # be disabled (default high), so none/minimal/max drop and the server
465 # default applies. Same set on chat and responses. The (?!\d) guard keeps
466 # grok-4.20-multi-agent (effort = agent count) an unknown id.
467 _openai_profile( qr/\Agrok-4\.[6-9](?!\d)/,
468 [qw( low medium high xhigh )],
469 source => $XAI_K208_DOC, can_disable => 0, disable_form => 'absent' ),
470 _openai_profile( qr/\Agrok-4\.5(?!\d)/,
471 [qw( low medium high )],
472 source => $XAI_K208_DOC, can_disable => 0, disable_form => 'absent' ),
473  
474 # Moonshot kimi-k3 (karr k207): top-level reasoning_effort on
475 # chat/completions and output_config.effort on the Messages API, both
476 # low|high|max (server default max); always reasons, and the Messages API
477 # has no thinking request field, so can_disable 0 keeps to_anthropic from
478 # sending one. \A-anchored on Moonshot's own ids: OpenRouter's
479 # moonshotai/kimi-k3 is deliberately not matched (what an aggregator
480 # forwards was not checked). K2.x takes no effort (cleared per model on
481 # Engine::Moonshot only). (?!\d): kimi-k30 is an unknown id (k196 guard).
482 _openai_profile( qr/\Akimi-k3(?!\d)/,
483 [qw( low high max )],
484 source => 'platform.kimi.ai use-reasoning-effort + api/chat + api/messages; k207 2026-09-25 (advisor-verified, doc-sourced not live)',
485 can_disable => 0, disable_form => 'absent' ),
486  
487 # Thinking-toggle families (karr k209, k215): the wire takes a `thinking`
488 # object with an on/off type and no effort level, so Langertha::Reasoning
489 # maps none -> off and every other level -> on (the ladder collapses).
490 # \A-anchored on the providers' own ids; aggregator ids are not matched.
491 #
492 # MiniMax (platform.minimax.io openapi-chat-openai.json /
493 # openapi-chat-anthropic.json, advisor 2026-09-25, doc-sourced not live):
494 # thinking {type: disabled|adaptive}, no effort, no budget. M3 honors
495 # disabled; M2.x accepts it but keeps thinking on, so it cannot disable.
496 # MiniMax's own /v1/responses maps effort the same way (none -> off, any
497 # level -> adaptive).
498 __PACKAGE__->new(
499 model_match => qr/\AMiniMax-M3(?!\d)/,
500 control => 'boolean',
501 wire_format => 'openai',
502 can_disable => 1,
503 disable_form => 'thinking_disabled',
504 thinking_on => 'adaptive',
505 source => $MINIMAX_K209_DOC,
506 ),
507 __PACKAGE__->new(
508 model_match => qr/\AMiniMax-M2(?!\d)/,
509 control => 'boolean',
510 wire_format => 'openai',
511 can_disable => 0,
512 disable_form => 'absent',
513 thinking_on => 'adaptive',
514 source => $MINIMAX_K209_DOC,
515 ),
516 # Kimi K2.x (karr k215; platform.kimi.ai api/messages + guide/claude-code-kimi,
517 # advisor 2026-09-25, doc-sourced not live): thinking {type: enabled|disabled},
518 # no effort (output_config.effort is K3-only). kimi-k2.7-code(-highspeed) is
519 # forced on ("only type=enabled is allowed"), kimi-k2.6 can disable. Whether
520 # `enabled` needs budget_tokens on the Messages face is UNVERIFIED; none is
521 # sent. \z-anchored to Kimi's documented ids: AKI.IO's hosted
522 # kimi-k2.7-code-1100b is a different API and is not matched. Reached on
523 # MoonshotAnthropic (both rows) and on Engine::Moonshot's chat/completions
524 # (kimi-k2.6 only, karr k219: the same toggle as a top-level `thinking`;
525 # wire_format is descriptive, to_openai serializes it). Engine::Moonshot
526 # keeps reasoning_effort cleared on kimi-k2.7-code, where the chat face
527 # must not be sent thinking at all.
528 __PACKAGE__->new(
529 model_match => qr/\Akimi-k2\.7-code(?:-highspeed)?\z/,
530 control => 'boolean',
531 wire_format => 'anthropic',
532 can_disable => 0,
533 disable_form => 'absent',
534 thinking_on => 'enabled',
535 source => $KIMI_K215_DOC,
536 ),
537 __PACKAGE__->new(
538 model_match => qr/\Akimi-k2\.6\z/,
539 control => 'boolean',
540 wire_format => 'anthropic',
541 can_disable => 1,
542 disable_form => 'thinking_disabled',
543 thinking_on => 'enabled',
544 source => $KIMI_K215_DOC,
545 ),
546 # Self-hosted Qwen3.x reasoning family (vLLM / SGLang / llama.cpp), matched
547 # with or without its HuggingFace org prefix (served ids look like
548 # "Qwen/Qwen3.8-27B-FP8"). The loaded chat template — not the server —
549 # dictates the vocabulary: this family accepts none|low|medium|xhigh and
550 # REJECTS high|minimal (live-probed, k79/k180). Only the openai (Chat
551 # Completions) wire is restricted — the sole wire these engines speak — so the
552 # two rejected efforts drop before they can 400 the server. Unknown
553 # self-hosted models are deliberately NOT listed: they fall through to the
554 # passthrough default and keep going raw (correct for an unknown chat
555 # template, k180).
556 __PACKAGE__->new(
557 model_match => qr{(?:\A|/)qwen3\.\d(?!\d)}i,
558 control => 'effort',
559 wire_format => 'openai',
560 levels => [qw( none low medium xhigh )],
561 levels_by_wire => { openai => [qw( none low medium xhigh )] },
562 disable_form => 'explicit_none',
563 source => $QWEN_SELFHOSTED_SRC,
564 ),
565  
566 # Gemini 2.5: integer thinkingBudget (no level vocabulary). Category (b)
567 # bounds carried but not enforced in Phase 1 (the value passes through).
568 __PACKAGE__->new(
569 model_match => qr/\Agemini-2\.5-flash-lite/,
570 control => 'budget', wire_format => 'gemini', levels => [],
571 budget_min => 512, budget_max => 24576, off_value => 0, dynamic_value => -1,
572 disable_form => 'budget_zero', source => $GEMINI25_SRC,
573 ),
574 __PACKAGE__->new(
575 model_match => qr/\Agemini-2\.5-flash/,
576 control => 'budget', wire_format => 'gemini', levels => [],
577 budget_min => 0, budget_max => 24576, off_value => 0, dynamic_value => -1,
578 disable_form => 'budget_zero', source => $GEMINI25_SRC,
579 ),
580 __PACKAGE__->new(
581 model_match => qr/\Agemini-2\.5-pro/,
582 control => 'budget', wire_format => 'gemini', levels => [],
583 budget_min => 128, budget_max => 32768, dynamic_value => -1, can_disable => 0,
584 disable_form => 'absent', source => $GEMINI25_SRC,
585 ),
586 __PACKAGE__->new(
587 model_match => qr/\Agemini-2\.5(?!\d)/,
588 control => 'budget', wire_format => 'gemini', levels => [],
589 budget_min => 0, budget_max => 24576, off_value => 0, dynamic_value => -1,
590 disable_form => 'budget_zero', source => $GEMINI25_SRC,
591 ),
592  
593 # Gemini 3 thinkingLevel families, most-specific-first: 3.7/3.8-flash and
594 # 3.1-pro drop minimal (low|medium|high); 3-pro is binary (low|high); every
595 # other gemini-3 keeps the full minimal..high set.
596 _gemini3_profile( qr/\Agemini-3\.[78]-flash/, [qw( low medium high )] ),
597 _gemini3_profile( qr/\Agemini-3\.1-pro/, [qw( low medium high )] ),
598 _gemini3_profile( qr/\Agemini-3-pro/, [qw( low high )] ),
599 _gemini3_profile( qr/\Agemini-3/, [qw( minimal low medium high )] ),
600 # Gemini 4 (karr k381): the same thinkingLevel knob, low|medium|high
601 # (default medium); Vertex answers minimal with 400, so minimal and none
602 # rise to low, as on 3.7/3.8-flash. thinkingBudget is never sent (control
603 # 'effort': a budget croaks in Langertha::Reasoning BUILD). (?!\d): gemini-40
604 # is an unknown id (k196 guard).
605 _gemini3_profile( qr/\Agemini-4(?!\d)/, [qw( low medium high )], $GEMINI4_SRC ),
606  
607 # Claude 4.6 (opus/sonnet): accepts low|medium|high|max but NOT xhigh —
608 # Anthropic's effort doc lists 4.6 under `max`, not under `xhigh`. Matched
609 # before the generic claude family. karr k177, doc-sourced (not live).
610 __PACKAGE__->new(
611 model_match => qr/\Aclaude-(opus|sonnet)-4-6/,
612 control => 'effort',
613 wire_format => 'anthropic',
614 levels => [qw( low medium high max )],
615 source => $ANTHROPIC_K177_DOC,
616 ),
617  
618 # Generic Claude family (adaptive thinking, can disable).
619 __PACKAGE__->new(
620 model_match => qr/\Aclaude/,
621 control => 'effort',
622 wire_format => 'anthropic',
623 levels => [@ANTHROPIC_EFFORT_LEVELS],
624 source => 'Anthropic Messages API output_config.effort; k173 2026-09-16',
625 ),
626  
627 # GPT-OSS on Ollama: the one family that takes graded level STRINGS on the
628 # options.think knob (low<medium<high<max) instead of the model-agnostic
629 # boolean, and ALWAYS reasons — there is no "off" (think:false is ignored,
630 # so 'none' -> floor 'low'). Its other wires stay unrestricted so nothing
631 # regresses off the ollama path: no levels_by_wire (openai passes the full
632 # enum through), and levels keeps the generic anthropic set. Live-probed
633 # 2026-09-17 via ollama.com gpt-oss:20b (k175).
634 __PACKAGE__->new(
635 model_match => qr/\Agpt-oss/,
636 control => 'effort',
637 wire_format => 'ollama',
638 levels => [@ANTHROPIC_EFFORT_LEVELS],
639 ollama_levels => [qw( low medium high max )],
640 source => 'live-probed 2026-09-17 via ollama.com gpt-oss:20b (k175)',
641 ),
642 );
643 }
644  
645  
646 10364 ▶sub for_model {
Subroutine for_model: called CC=1 SCAR=1.2
Pod documented
647 0 ▶ my ( $class, $id ) = @_;
Subroutine for_model: not called CC=1 SCAR=1.2
Pod documented
648 0 _ensure_registry();
649 0 return _match( $id, @REGISTRY );
650 }
651  
652 # First profile in @profiles (most-specific-first) whose model_match matches
653 # $id, else the provider default.
654 10683 ▶sub _match {
Subroutine _match: called CC=8 SCAR=35.2
655 0 ▶ my ( $id, @profiles ) = @_;
Subroutine _match: not called CC=8 SCAR=35.2
656 0 ▶ $id = '' unless defined $id;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $id 0 10683 10683
unless defined $id 0 0 0
657 0 for my $profile (@profiles) {
658 0 my $match = $profile->model_match;
659 0 ▶ if ( ref $match eq 'Regexp' ) {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $match eq 'Regexp') { } 262936 0 262936
elsif (defined $match and length $match) { } 0 0 0
if (ref $match eq 'Regexp') { } 0 0 0
elsif (defined $match and length $match) { } 0 0 0
660 0 ▶ return $profile if $id =~ $match;
Branch: 2 branches
BranchTrueFalseTotal
if $id =~ /$match/ 7709 255227 262936
if $id =~ /$match/ 0 0 0
661 }
662 ▶ elsif ( defined $match && length $match ) {
Condition0%0/6
defined $match and length $match
!ll&&!rl&&r
000
defined $match and length $match
!ll&&!rl&&r
000
MC/DC0%0/2
defined $match and length $match
defined $match length $match
MC/DC0%0/2
defined $match and length $match
defined $match length $match
Truth table0%0/3
A and B
A= defined $matchB= length $match
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $matchB= length $match
ABresult
0X0
100
111
663 0 ▶ return $profile if $id eq $match;
Branch: 2 branches
BranchTrueFalseTotal
if $id eq $match 0 0 0
if $id eq $match 0 0 0
664 }
665 }
666 0 return $DEFAULT;
667 }
668  
669 193 __PACKAGE__->meta->make_immutable;
670  
671  
672 193 1;
673  
674 __END__
« blib/lib/Langertha/Plugin/Langfuse.pm ↑ Summary blib/lib/Langertha/Runtime/Metrics/OTLP.pm »