blib/lib/Langertha/Reasoning.pm

filter: Statementstmt 100% 75 / 75 Branchbran 98.0% 51 / 52 Conditioncond 87.1% 27 / 31 MC/DCmcdc 84.2% 16 / 19 Subroutinesub 100% 14 / 14 Podpod 75.0% 6 / 8 totaltotal 94.9% 189 / 199 CC 38 SCAR 17.3
CC
38
Cov
97%
to_anthropic
9.0
BUILD
8.0
_thinking_toggle
7.0
CRAP 5.6
« blib/lib/Langertha/RateLimit.pm ↑ Summary blib/lib/Langertha/Input/Tools.pm »
1 package Langertha::Reasoning;
2 # ABSTRACT: Immutable normalized reasoning-effort control with cross-provider conversion
3 181 our $VERSION = '0.503';
4 181 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 181 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 181 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 181 ▶use Langertha::Reasoning::Profile;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 # Optional attributes with normal Moose predicates. No `default` / `Maybe[...]`
11 # so that `has_effort` / `has_thinking_budget` reflect whether the caller
12 # supplied the field — the standard Moose predicate (true when set, false when
13 # not set) is what BUILD and the serializers dispatch on.
14 181 has effort => (
15 is => 'ro',
16 isa => 'Str',
17 predicate => 'has_effort',
18 );
19  
20  
21 181 has model => (
22 is => 'ro',
23 isa => 'Str',
24 predicate => 'has_model',
25 );
26  
27  
28 181 has thinking_budget => (
29 is => 'ro',
30 isa => 'Int',
31 predicate => 'has_thinking_budget',
32 );
33  
34 181 has thinking_display => (
35 is => 'ro',
36 isa => 'Str',
37 predicate => 'has_thinking_display',
38 );
39  
40  
41  
42 181 has thinking_toggle => (
43 is => 'ro',
44 isa => 'Bool',
45 default => 0,
46 );
47  
48  
49 # The resolved reasoning profile (Langertha::Reasoning::Profile) for the
50 # configured model — the single source for what the model's wire accepts. All
51 # per-model gating (openai ladder, gemini clamp, fable-class, budget-vs-effort
52 # control) reads from here instead of the inline hashes/regexes that used to
53 # live in this file (karr k173). Resolved once, lazily, off the immutable model.
54 181 has _profile => (
55 is => 'ro',
56 isa => 'Langertha::Reasoning::Profile',
57 lazy => 1,
58 init_arg => undef,
59 builder => '_build_profile',
60 );
61  
62 # A thinking-toggle row is the wire truth of the endpoint that opted in
63 # (thinking_toggle), not of the model id: on every other endpoint it is
64 # invisible and the id resolves like any unlisted id (review I1).
65 # The fallback is the provider default, for_model(''), not the next matching
66 # non-toggle row. That is the same thing only while no non-toggle row matches
67 # an id a toggle row matches (true today: MiniMax-M2/M3 and the kimi-k2.6 /
68 # kimi-k2.7-code rows overlap no other row). A broader row covering those ids
69 # would have to be re-resolved here, skipping has_thinking_on rows (karr k223).
70 9514 ▶sub _build_profile {
Subroutine _build_profile: called CC=4 SCAR=13.9
71 9514 my ( $self ) = @_;
72 9514 ▶ my $profile = Langertha::Reasoning::Profile->for_model(
Branch: 1 branch
BranchTrueFalseTotal
$self->has_model ? : 9509 5 9514
73 $self->has_model ? $self->model : '' );
74 9514 ▶ return Langertha::Reasoning::Profile->for_model('')
Branch: 1 branch
BranchTrueFalseTotal
if $profile->has_thinking_on and not $self->thinking_toggle 192 9322 9514
Condition100%3/3
$profile->has_thinking_on and not $self->thinking_toggle
!ll&&!rl&&r
9083239192
MC/DC100%2/2
$profile->has_thinking_on and not $self->thinking_toggle
$profile->has_thinking_on not $self->thinking_toggle
Truth table100%3/3
A and not(B)
A= $profile->has_thinking_onB= not $self->thinking_toggle
ABresult
0X0
100
111
75 if $profile->has_thinking_on && !$self->thinking_toggle;
76 9322 return $profile;
77 }
78  
79 # Build-time wire-truth gate: exactly one native control per generation, never
80 # both. Errors here surface before the request is built (Langertha::Engine::Gemini
81 # calls to() inside chat_request), so a misconfigured engine never produces an
82 # ambiguous wire form. The budget-vs-effort split derives from the resolved
83 # profile's control (Gemini 2.5 is the only control=budget family today), so the
84 # family boundary lives in Langertha::Reasoning::Profile, not in an inline regex.
85 9517 ▶sub BUILD {
Subroutine BUILD: called CC=8 SCAR=20.8
Pod undocumented
86 9517 my ( $self ) = @_;
87  
88 9517 my $has_effort = $self->has_effort;
89 9517 my $has_budget = $self->has_thinking_budget;
90 9517 ▶ my $model = $self->has_model ? $self->model : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->has_model ? : 9512 5 9517
91  
92 9517 ▶ if ( $has_effort && $has_budget ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_effort and $has_budget) 3 9514 9517
Condition100%3/3
$has_effort and $has_budget
!ll&&!rl&&r
30392113
MC/DC100%2/2
$has_effort and $has_budget
$has_effort $has_budget
Truth table100%3/3
A and B
A= $has_effortB= $has_budget
ABresult
0X0
100
111
93 3 croak "Langertha::Reasoning: 'effort' and 'thinking_budget' are mutually "
94 . "exclusive — pick one (effort -> thinkingLevel, thinking_budget -> "
95 . "thinkingBudget); model='" . $model . "'";
96 }
97  
98 9514 my $is_budget_control = $self->_profile->control eq 'budget';
99  
100 9514 ▶ if ( $has_budget && !$is_budget_control ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_budget and not $is_budget_control) 184 9330 9514
Condition100%3/3
$has_budget and not $is_budget_control
!ll&&!rl&&r
932010184
MC/DC100%2/2
$has_budget and not $is_budget_control
$has_budget not $is_budget_control
Truth table100%3/3
A and not(B)
A= $has_budgetB= not $is_budget_control
ABresult
0X0
100
111
101 184 croak "Langertha::Reasoning: 'thinking_budget' is only valid on Gemini 2.5 "
102 . "models (model id starting with 'gemini-2.5'); got model='" . $model . "'";
103 }
104  
105 9330 ▶ if ( $has_effort && $is_budget_control ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_effort and $is_budget_control) 161 9169 9330
Condition100%3/3
$has_effort and $is_budget_control
!ll&&!rl&&r
1199050161
MC/DC100%2/2
$has_effort and $is_budget_control
$has_effort $is_budget_control
Truth table100%3/3
A and B
A= $has_effortB= $is_budget_control
ABresult
0X0
100
111
106 161 croak "Langertha::Reasoning: 'effort' is not valid on Gemini 2.5 models — "
107 . "use 'thinking_budget' (integer tokens) instead; got model='"
108 . $model . "'";
109 }
110 }
111  
112 1631 ▶sub to_gemini_level {
Subroutine to_gemini_level: called CC=1 SCAR=0.0
Pod documented
113 1631 my ( $self ) = @_;
114 1631 return $self->_profile->gemini_level_for( $self->effort );
115 }
116  
117  
118 # A thinking-toggle model (Profile thinking_on, karr k209/k215) on an endpoint
119 # that opted in (thinking_toggle: MiniMax, MiniMaxAnthropic, Moonshot,
120 # MoonshotAnthropic)
121 # takes a `thinking` object with an on/off type and no effort level, on both the
122 # openai and the anthropic wire: none -> off where the model can disable (else
123 # the field is omitted), any other level -> the model's on-type. On any other
124 # endpoint the same id serializes like the passthrough default (review I1).
125 # thinking_display rides along on the anthropic wire only, never on an off
126 # toggle; a display-only request turns the toggle on, as the adaptive path does.
127 # Whether MiniMax / Kimi accept `display` there is unverified (it is a
128 # first-party Anthropic field; kept because MiniMaxAnthropic sent it before k209).
129 215 ▶sub _thinking_toggle {
Subroutine _thinking_toggle: called CC=7 SCAR=19.5
130 215 my ( $self, $with_display ) = @_;
131 215 my $profile = $self->_profile;
132 215 ▶ my $display = $with_display && $self->has_thinking_display;
Condition100%3/3
$with_display && $self->has_thinking_display
!ll&&!rl&&r
721358
MC/DC100%2/2
$with_display && $self->has_thinking_display
$with_display $self->has_thinking_display
Truth table100%3/3
A && B
A= $with_displayB= $self->has_thinking_display
ABresult
0X0
100
111
133 215 ▶ my $thinking = $self->has_effort ? $profile->thinking_toggle_for( $self->effort )
Branch: 2 branches
BranchTrueFalseTotal
$self->has_effort ? : 202 13 215
$display ? : 8 5 13
134 : $display ? { type => $profile->thinking_on }
135 : undef;
136 215 ▶ return () unless $thinking;
Branch: 1 branch
BranchTrueFalseTotal
unless $thinking 15 200 215
137 $thinking = { %$thinking, display => $self->thinking_display }
138 200 ▶ if $display && $thinking->{type} ne 'disabled';
Branch: 1 branch
BranchTrueFalseTotal
if $display and $thinking->{"type"} ne "disabled" 8 192 200
Condition66%2/3
$display and $thinking->{"type"} ne "disabled"
!ll&&!rl&&r
19208
MC/DC50%1/2
$display and $thinking->{"type"} ne "disabled"
$display $thinking->{"type"} ne "disabled"
Truth table66%2/3
A and B
A= $displayB= $thinking->{"type"} ne "disabled"
ABresult
0X0
100
111
139 200 return ( thinking => $thinking );
140 }
141  
142 2339 ▶sub to_openai {
Subroutine to_openai: called CC=4 SCAR=13.9
Pod documented
143 2339 my ( $self ) = @_;
144 2339 ▶ return $self->_thinking_toggle(0) if $self->_profile->has_thinking_on;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_profile->has_thinking_on 72 2267 2339
145 2267 ▶ return () unless $self->has_effort;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_effort 56 2211 2267
146 2211 ▶ return () unless $self->_profile->effort_accepted_on( 'openai', $self->effort );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_profile->effort_accepted_on("openai", $self->effort) 260 1951 2211
147 1951 return ( reasoning_effort => $self->effort );
148 }
149  
150 1737 ▶sub to_responses {
Subroutine to_responses: called CC=3 SCAR=11.0
Pod documented
151 1737 my ( $self ) = @_;
152 1737 ▶ return () unless $self->has_effort;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_effort 8 1729 1737
153 1729 ▶ return () unless $self->_profile->effort_accepted_on( 'responses', $self->effort );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_profile->effort_accepted_on("responses", $self->effort) 165 1564 1729
154 1564 return ( reasoning => { effort => $self->effort } );
155 }
156  
157  
158 1898 ▶sub to_anthropic {
Subroutine to_anthropic: called CC=9 SCAR=22.0
Pod documented
159 1898 my ( $self ) = @_;
160 1898 ▶ return $self->_thinking_toggle(1) if $self->_profile->has_thinking_on;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_profile->has_thinking_on 143 1755 1898
161 1755 ▶ my $e = $self->has_effort ? $self->effort : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->has_effort ? : 1732 23 1755
162 1755 ▶ my $effort_ok = defined $e && $self->_profile->anthropic_effort_ok($e);
Condition100%3/3
defined $e && $self->_profile->anthropic_effort_ok($e)
!ll&&!rl&&r
235181214
MC/DC100%2/2
defined $e && $self->_profile->anthropic_effort_ok($e)
defined $e $self->_profile->anthropic_effort_ok($e)
Truth table100%3/3
A && B
A= defined $eB= $self->_profile->anthropic_effort_ok($e)
ABresult
0X0
100
111
163  
164 # Adaptive-thinking models need thinking:{type:adaptive} or thinking stays
165 # off; always-on "Fable-class" models 400 on thinking:{type:disabled} and
166 # need no thinking field at all (thinking is always on). thinking.display
167 # controls visibility: the wire default is "omitted" on every current model,
168 # so $response->thinking comes back empty unless the caller asks for
169 # "summarized". We emit the thinking block whenever an effort or a display is
170 # in play so a display-only request still turns summaries on.
171 1755 my @thinking;
172 1755 ▶ if ( !$self->_profile->fable_class && ( $effort_ok || $self->has_thinking_display ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_profile->fable_class and $effort_ok || $self->has_thinking_display) 1199 556 1755
Condition100%6/6
not $self->_profile->fable_class and $effort_ok || $self->has_thinking_display
!ll&&!rl&&r
724841199
$effort_ok or $self->has_thinking_display
l!l&&r!l&&!r
116930484
MC/DC100%3/3
not $self->_profile->fable_class and $effort_ok || $self->has_thinking_display
not $self->_profile->fable_class $effort_ok $self->has_thinking_display
Truth table100%4/4
not(A) and B or C
A= not $self->_profile->fable_classB= $effort_okC= $self->has_thinking_display
ABCresult
0XX0
1000
11X1
1011
173 1199 ▶ @thinking = ( thinking => {
Branch: 1 branch
BranchTrueFalseTotal
$self->has_thinking_display ? : 62 1137 1199
174 type => 'adaptive',
175 ( $self->has_thinking_display ? ( display => $self->thinking_display ) : () ),
176 } );
177 }
178  
179 return (
180 1755 ▶ ( $effort_ok ? ( output_config => { effort => $e } ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
$effort_ok ? : 1214 541 1755
181 @thinking,
182 );
183 }
184  
185  
186 1649 ▶sub to_gemini {
Subroutine to_gemini: called CC=3 SCAR=11.0
Pod undocumented
187 1649 my ( $self ) = @_;
188 1649 ▶ if ( $self->has_thinking_budget ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_thinking_budget) 10 1639 1649
189 # BUILD has already verified the model is Gemini 2.5.
190 10 return ( thinkingConfig => { thinkingBudget => $self->thinking_budget } );
191 }
192 1639 ▶ return () unless $self->has_effort;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_effort 8 1631 1639
193 1631 return ( thinkingConfig => { thinkingLevel => $self->to_gemini_level } );
194 }
195  
196 1546 ▶sub to_ollama {
Subroutine to_ollama: called CC=4 SCAR=13.9
Pod documented
197 1546 my ( $self ) = @_;
198 1546 ▶ return () unless $self->has_effort;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_effort 1 1545 1546
199 # GPT-OSS takes graded level STRINGS on the options.think knob
200 # (low<medium<high<max) and ALWAYS reasons — there is no "off": think:false is
201 # ignored, so a boolean has zero effect and 'none' maps to the floor 'low'.
202 # Live-probed 2026-09-17 via ollama.com gpt-oss:20b (k175). Every other model
203 # takes only the boolean: any effort level -> on, 'none' -> off.
204 1545 ▶ return ( think => $self->_profile->ollama_level_for( $self->effort ) )
Branch: 1 branch
BranchTrueFalseTotal
if $self->_profile->has_ollama_levels 31 1514 1545
205 if $self->_profile->has_ollama_levels;
206 1514 ▶ return ( think => $self->effort eq 'none' ? JSON->false : JSON->true );
Branch: 1 branch
BranchTrueFalseTotal
$self->effort eq 'none' ? : 218 1296 1514
207 }
208  
209  
210 # Maps a reasoning_wire_format tag to the per-format serializer method.
211 181 my %TO_METHOD = (
212 openai => 'to_openai',
213 responses => 'to_responses',
214 anthropic => 'to_anthropic',
215 gemini => 'to_gemini',
216 ollama => 'to_ollama',
217 );
218  
219 9169 ▶sub to {
Subroutine to: called CC=4 SCAR=16.9
Pod documented
220 9169 my ( $self, $fmt ) = @_;
221 9169 ▶ my $method = $TO_METHOD{ $fmt // '' }
Branch: 1 branch
BranchTrueFalseTotal
my $method = $TO_METHOD{$fmt // ""} or croak(q[Langertha::Reasoning: unknown reasoning wire format '] . ($fmt // "") . q[']) 9169 0 9169
Condition25%1/4
$fmt // ""
l!l
91690
$fmt // ""
l!l
00
MC/DC0%0/1
$fmt // ""
$fmt
MC/DC0%0/1
$fmt // ""
$fmt
Truth table50%1/2
A
A= $fmt
Aresult
11
00
Truth table0%0/2
A
A= $fmt
Aresult
11
00
222 or croak "Langertha::Reasoning: unknown reasoning wire format '" . ( $fmt // '' ) . "'";
223 9169 return $self->$method;
224 }
225  
226  
227 181 __PACKAGE__->meta->make_immutable;
228  
229  
230 181 1;
231  
232 __END__
233  
234 =pod
235  
236 =encoding UTF-8
237  
238 =head1 NAME
239  
240 Langertha::Reasoning - Immutable normalized reasoning-effort control with cross-provider conversion
241  
242 =head1 VERSION
243  
244 version 0.503
245  
246 =head1 SYNOPSIS
247  
248 my $r = Langertha::Reasoning->new(
249 effort => 'high',
250 model => 'claude-opus-4-8',
251 );
252 my %kwargs = $r->to('anthropic');
253 # ( output_config => { effort => 'high' }, thinking => { type => 'adaptive' } )
254  
255 # Gemini 2.5 takes an integer thinking_budget instead of a level
256 my $rb = Langertha::Reasoning->new(
257 thinking_budget => 2048,
258 model => 'gemini-2.5-pro',
259 );
260 my %kw = $rb->to('gemini');
261 # ( thinkingConfig => { thinkingBudget => 2048 } )
262  
263 =head1 DESCRIPTION
264  
265 Canonical value object for the request-side reasoning-effort knob, dispatched
266 by an engine's C<reasoning_wire_format>. Mirrors L<Langertha::Tool> /
267 L<Langertha::ToolChoice>: the value-set clamping and per-provider placement of
268 the field live in this one reviewable place rather than scattered across
269 engines (ADR 0001).
270  
271 The normalized vocabulary is the OpenAI superset
272 C<none|minimal|low|medium|high|xhigh|max>. Each C<to_*> serializer clamps that
273 vocabulary to what the target wire actually accepts and returns the body kwargs
274 to merge into the request.
275  
276 The OpenAI clamp is B<model-gated>, not wire-gated: Chat Completions
277 (C<to_openai>) and the Responses API (C<to_responses>) C<$ref> the identical
278 C<ReasoningEffort> schema, so both share one per-model gate and can never
279 diverge for the same model. The accepted set differs per model generation —
280 gpt-6 (astra) accepts neither C<none> nor C<minimal> (C<low>..C<max>); the
281 gpt-5.6/gpt-5.5 generation accepts C<none>/C<xhigh>/(C<max>) but not
282 C<minimal>; the legacy gpt-5 generation accepts C<minimal> but not
283 C<none>/C<xhigh>/C<max> — so no single wire-level clamp is correct. Unlisted
284 model ids keep the full vocabulary. See L</to_openai>.
285  
286 Gemini splits its reasoning knob by model generation: Gemini 3 accepts a
287 C<thinkingLevel> emitted from C<effort> (vocabulary
288 C<minimal>|C<low>|C<medium>|C<high>, clamped to the subset the configured
289 model family accepts — see L</to_gemini_level>); Gemini 2.5 takes a
290 C<thinkingBudget> integer instead. Exactly one of the two fields is
291 emitted per request — never both. C<BUILD> rejects every
292 C<effort>/C<thinking_budget> combination that would produce an ambiguous wire
293 form (either field on the wrong generation, or both fields together on any
294 generation). The rule is "exactly one native control per generation",
295 enforced loudly before any request is built.
296  
297 =head2 effort
298  
299 The normalized reasoning effort, one of C<none|minimal|low|medium|high|xhigh|max>.
300 Optional (must not coexist with C<thinking_budget> on any Gemini generation;
301 see L</BUILD>). On Gemini 3, C<effort> is the only knob and emits
302 C<thinkingConfig.thinkingLevel>, model-gated clamped to the level subset the
303 configured model family accepts (L</to_gemini_level>). Setting C<effort> on a
304 Gemini 2.5 model is rejected — Gemini 2.5 takes the integer budget, not the
305 level vocabulary.
306  
307 =head2 model
308  
309 Optional model name. Used by L</to_anthropic> to detect always-on
310 "Fable-class" models (where C<thinking:{type:disabled}> 400s and the
311 C<thinking> field must be omitted) and by L</to_gemini> to dispatch between
312 Gemini 2.5 (C<thinkingBudget>) and Gemini 3 (C<thinkingLevel>) and to clamp
313 the Gemini 3 level vocabulary to the model family's supported subset.
314  
315 =head2 thinking_display
316  
317 Optional Anthropic thinking-visibility control, serialized by L</to_anthropic>
318 as C<thinking.display>. Values: C<summarized> (return a readable summary of the
319 reasoning), C<omitted> (no summary; the C<thinking> field comes back empty), or
320 C<updates> (beta; between-tool-call progress notes). On every current Claude
321 model the API default is C<omitted>, so a caller that wants to read
322 C<< $response->thinking >> must set C<thinking_display =E<gt> 'summarized'>
323 explicitly. Consumed only on the C<anthropic> wire; ignored on every other
324 format. Only takes effect together with a thinking block, i.e. on the adaptive
325 (non-Fable-class) path — see L</to_anthropic>.
326  
327 =head2 thinking_budget
328  
329 Optional integer thinking budget for Gemini 2.5 models. When set on a Gemini
330 2.5 model (model id starting with C<gemini-2.5>), L</to_gemini> emits
331 C<thinkingConfig.thinkingBudget> as the integer. Setting C<thinking_budget>
332 on a Gemini 3 model, or setting it together with C<effort> on any model, is
333 rejected at construction time (L</BUILD>) — the two fields speak different
334 units (binary level vs integer tokens) and a combined or wrong-generation wire
335 form would be ambiguous.
336  
337 =head2 thinking_toggle
338  
339 Whether the target endpoint speaks the C<thinking> on/off toggle (MiniMax's
340 cloud API, Kimi's Messages and chat/completions faces; karr k209/k215/k219). Set by
341 L<Langertha::Role::ReasoningEffort/reasoning_kwargs_for> from the engine's
342 opt-in. Only when it is true does a thinking-toggle profile
343 (L<Langertha::Reasoning::Profile/thinking_on>) serialize as the toggle; when
344 false (the default) the same model id serializes exactly like the unlisted-id
345 passthrough, because a self-hosted server or proxy serving a bare
346 C<MiniMax-M3> / C<kimi-k2.6> id does not parse the toggle.
347  
348 =head2 to_gemini_level
349  
350 Maps the normalized effort onto Gemini 3's C<thinkingLevel> vocabulary
351 (C<minimal>|C<low>|C<medium>|C<high>): C<none>/C<minimal> become C<minimal>,
352 C<high>/C<xhigh>/C<max> become C<high>, C<low> and C<medium> pass through.
353 The result is then clamped down to the subset the configured L</model> family
354 accepts: C<gemini-3.7-flash>, C<gemini-3.8-flash> and C<gemini-3.1-pro-*> drop
355 C<minimal> to C<low> (no C<minimal> support), C<gemini-3-pro-*> accepts only
356 C<low>|C<high> and drops C<minimal> and C<medium> to C<low>. Models outside the Gemini 3 line (or no
357 model) keep the universally-accepted binary C<low>|C<high> collapse, splitting
358 at C<high>.
359  
360 =head2 to_openai
361  
362 =head2 to_responses
363  
364 Serialize L</effort> to the two OpenAI wires — Chat Completions
365 (C<reasoning_effort =E<gt> $effort>) and the Responses API
366 (C<reasoning =E<gt> { effort =E<gt> $effort }>). Both surfaces C<$ref> the
367 identical C<ReasoningEffort> schema, so both clamp through the same model-gated
368 gate: the accepted value set is per model generation
369 (gpt-6 astra: C<low|medium|high|xhigh|max>, no C<none|minimal>;
370 gpt-5.6-* / gpt-5.5-*: C<none|low|medium|high|xhigh(|max)>, no C<minimal>;
371 gpt-5 legacy: C<minimal|low|medium|high>, no C<none|xhigh|max>), and an
372 unrecognized model id keeps the full normalized vocabulary. An effort the
373 configured L</model> does not accept yields an empty list on B<both> wires —
374 they can never diverge. Empty list when no L</effort> is set.
375  
376 A B<thinking-toggle> model (its profile has
377 L<Langertha::Reasoning::Profile/thinking_on>: MiniMax-M3 / M2.x, Kimi K2.x),
378 serialized for an endpoint that opted in with L</thinking_toggle>, takes no
379 effort field on C<to_openai>: it gets
380 C<< thinking =E<gt> { type =E<gt> ... } >> instead — C<disabled> for C<none>
381 where the model can turn thinking off, the model's on-type (C<adaptive> or
382 C<enabled>) for any other level. Every level gives the same depth there.
383 Without L</thinking_toggle> the same model id is serialized like any unlisted
384 id.
385  
386 =head2 to_anthropic
387  
388 Serializes to the Messages-API reasoning shape: C<output_config.effort> (when
389 L</effort> maps onto Anthropic's C<low|medium|high|xhigh|max> set) plus a
390 C<thinking> block. On adaptive (non-Fable-class) models the block is
391 C<< { type =E<gt> 'adaptive' } >>, carrying C<display =E<gt> ...> when
392 L</thinking_display> is set. Fable-class models (Fable / Mythos) get no
393 C<thinking> key — thinking is always on and C<type:disabled> 400s there — and
394 therefore cannot carry a C<display> either. Empty list when neither an
395 Anthropic-supported effort nor a C<thinking_display> is present.
396  
397 A B<thinking-toggle> model on an opted-in endpoint (L</thinking_toggle>) gets
398 only the C<thinking> toggle described under L</to_openai> (no
399 C<output_config.effort>), with C<display> added to an on toggle when
400 L</thinking_display> is set (whether MiniMax and Kimi accept C<display> there is
401 not verified).
402  
403 =head2 to_ollama
404  
405 Serializes to Ollama's C<options.think> knob. For the GPT-OSS family (whose
406 resolved L<Langertha::Reasoning::Profile> carries C<ollama_levels>) it emits a
407 graded level B<string> — C<low>/C<medium>/C<high>/C<max> — because GPT-OSS
408 ignores the boolean and always reasons (C<none> maps to the floor C<low>;
409 live-probed 2026-09-17 via ollama.com gpt-oss:20b, k175). For every other model
410 it emits the C<options.think> B<boolean>: any effort level other than C<none>
411 turns thinking on, C<none> turns it off. Empty list when no effort is set.
412 (Ollama does not compose L<Langertha::Role::ReasoningEffort> — the engine calls
413 this serializer directly from its C<chat_request> when a per-request
414 C<reasoning_effort> control arrives.)
415  
416 =head2 to
417  
418 my %kwargs = $r->to($reasoning_wire_format);
419  
420 Dispatch to the per-format serializer. Returns the body kwargs to merge into
421 the request (an empty list when the value is unsupported on that wire).
422  
423 =head1 SEE ALSO
424  
425 =over
426  
427 =item * L<Langertha::Reasoning::Profile> - The per-model wire-truth this value object resolves and consumes
428  
429 =item * L<Langertha::Role::ReasoningEffort> - The composed role exposing C<reasoning_effort>
430 and C<thinking_budget>
431  
432 =item * L<Langertha::ToolChoice> - Sibling value object for tool-selection policy
433  
434 =back
435  
436 =head1 SUPPORT
437  
438 =head2 Issues
439  
440 Please report bugs and feature requests on GitHub at
441 L<https://github.com/Getty/langertha/issues>.
442  
443 =head2 IRC
444  
445 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
446  
447 =head1 CONTRIBUTING
448  
449 Contributions are welcome! Please fork the repository and submit a pull request.
450  
451 =head1 AUTHOR
452  
453 Torsten Raudssus <getty@cpan.org>
454  
455 =head1 COPYRIGHT AND LICENSE
456  
457 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
458  
459 This is free software; you can redistribute it and/or modify it under
460 the same terms as the Perl 5 programming language system itself.
461  
462 =cut
« blib/lib/Langertha/RateLimit.pm ↑ Summary blib/lib/Langertha/Input/Tools.pm »