blib/lib/Langertha/Reasoning.pm

filter: Statementstmt 56.9% 106 / 186 Branchbran 48.3% 85 / 176 Conditioncond 40.7% 53 / 130 MC/DCmcdc 38.1% 29 / 76 Subroutinesub 57.5% 19 / 33 Podpod 83.3% 20 / 24 totaltotal 49.9% 312 / 625 CC 135 SCAR 27.8
CC
135
Cov
50%
drops_thinking_enabled_on
38.4
drops_thinking_enabled_on
38.4
BUILD
22.5
CRAP 16.2
« blib/lib/Langertha/Engine/Gemini.pm ↑ Summary blib/lib/Langertha/Role/ReasoningEffort.pm »
1 package Langertha::Reasoning;
2 # ABSTRACT: Immutable normalized reasoning-effort control with cross-provider conversion
3 193 our $VERSION = '0.505';
4 193 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 193 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 193 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 193 ▶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 193 has effort => (
15 is => 'ro',
16 isa => 'Str',
17 predicate => 'has_effort',
18 );
19  
20  
21 193 has model => (
22 is => 'ro',
23 isa => 'Str',
24 predicate => 'has_model',
25 );
26  
27  
28 193 has thinking_budget => (
29 is => 'ro',
30 isa => 'Int',
31 predicate => 'has_thinking_budget',
32 );
33  
34 193 has thinking_display => (
35 is => 'ro',
36 isa => 'Str',
37 predicate => 'has_thinking_display',
38 );
39  
40  
41  
42 193 has thinking_enabled => (
43 is => 'ro',
44 isa => 'Bool',
45 predicate => 'has_thinking_enabled',
46 );
47  
48  
49 193 has thinking_toggle => (
50 is => 'ro',
51 isa => 'Bool',
52 default => 0,
53 );
54  
55  
56 # The resolved reasoning profile (Langertha::Reasoning::Profile) for the
57 # configured model — the single source for what the model's wire accepts. All
58 # per-model gating (openai ladder, gemini clamp, fable-class, budget-vs-effort
59 # control) reads from here instead of the inline hashes/regexes that used to
60 # live in this file (karr k173). Resolved once, lazily, off the immutable model.
61 193 has _profile => (
62 is => 'ro',
63 isa => 'Langertha::Reasoning::Profile',
64 lazy => 1,
65 init_arg => undef,
66 builder => '_build_profile',
67 );
68  
69 # A thinking-toggle row is the wire truth of the endpoint that opted in
70 # (thinking_toggle), not of the model id: on every other endpoint it is
71 # invisible and the id resolves like any unlisted id (review I1).
72 # The fallback is the provider default, for_model(''), not the next matching
73 # non-toggle row. That is the same thing only while no non-toggle row matches
74 # an id a toggle row matches (true today: MiniMax-M2/M3 and the kimi-k2.6 /
75 # kimi-k2.7-code rows overlap no other row). A broader row covering those ids
76 # would have to be re-resolved here, skipping has_thinking_on rows (karr k223).
77 9626 ▶sub _build_profile {
Subroutine _build_profile: called CC=4 SCAR=17.9
78 0 ▶ my ( $self ) = @_;
Subroutine _build_profile: not called CC=4 SCAR=17.9
79 0 ▶ my $profile = Langertha::Reasoning::Profile->for_model(
Branch: 2 branches
BranchTrueFalseTotal
$self->has_model ? : 9597 29 9626
$self->has_model ? : 0 0 0
80 $self->has_model ? $self->model : '' );
81 0 ▶ return Langertha::Reasoning::Profile->for_model('')
Branch: 2 branches
BranchTrueFalseTotal
if $profile->has_thinking_on and not $self->thinking_toggle 192 9434 9626
if $profile->has_thinking_on and not $self->thinking_toggle 0 0 0
Condition50%3/6
$profile->has_thinking_on and not $self->thinking_toggle
!ll&&!rl&&r
9195239192
$profile->has_thinking_on and not $self->thinking_toggle
!ll&&!rl&&r
000
MC/DC100%2/2
$profile->has_thinking_on and not $self->thinking_toggle
$profile->has_thinking_on not $self->thinking_toggle
MC/DC0%0/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
Truth table0%0/3
A and not(B)
A= $profile->has_thinking_onB= not $self->thinking_toggle
ABresult
0X0
100
111
82 if $profile->has_thinking_on && !$self->thinking_toggle;
83 0 return $profile;
84 }
85  
86 # thinking_enabled => 0 without an effort is the off switch every wire already
87 # knows as effort 'none' (karr k382): normalize it here, before BUILD checks
88 # the per-generation gates, so the serializers and the ADR 0025 temperature
89 # gate see one value. A contradicting effort is left alone for BUILD to croak.
90 9633 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
91 9633 my ( $orig, $class, @args ) = @_;
92 9633 return $class->normalize_off_switch( $class->$orig(@args) );
93 193 };
94  
95 12799 ▶sub normalize_off_switch {
Subroutine normalize_off_switch: called CC=6 SCAR=23.5
Pod documented
96 0 ▶ my ( $self, $args ) = @_;
Subroutine normalize_off_switch: not called CC=6 SCAR=23.5
Pod documented
97 return $args unless defined $args->{thinking_enabled} && !$args->{thinking_enabled}
98 0 ▶ && !defined $args->{effort};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $args->{"thinking_enabled"} and not $args->{"thinking_enabled"} and not defined $args->{"effort"} 12767 32 12799
unless defined $$args{"thinking_enabled"} and not $$args{"thinking_enabled"} and not defined $$args{"effort"} 0 0 0
Condition50%6/12
defined $args->{"thinking_enabled"} and not $args->{"thinking_enabled"} and not defined $args->{"effort"}
!ll&&!rl&&r
127462132
defined $args->{"thinking_enabled"} and not $args->{"thinking_enabled"}
!ll&&!rl&&r
127143253
defined $$args{"thinking_enabled"} and not $$args{"thinking_enabled"} and not defined $$args{"effort"}
!ll&&!rl&&r
000
defined $$args{"thinking_enabled"} and not $$args{"thinking_enabled"}
!ll&&!rl&&r
000
MC/DC100%3/3
defined $args->{"thinking_enabled"} and not $args->{"thinking_enabled"} and not defined $args->{"effort"}
defined $args->{"thinking_enabled"} not $args->{"thinking_enabled"} not defined $args->{"effort"}
MC/DC0%0/3
defined $$args{"thinking_enabled"} and not $$args{"thinking_enabled"} and not defined $$args{"effort"}
defined $$args{"thinking_enabled"} not $$args{"thinking_enabled"} not defined $$args{"effort"}
Truth table100%4/4
A and not(B) and not(C)
A= defined $args->{"thinking_enabled"}B= not $args->{"thinking_enabled"}C= not defined $args->{"effort"}
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and not(B) and not(C)
A= defined $$args{"thinking_enabled"}B= not $$args{"thinking_enabled"}C= not defined $$args{"effort"}
ABCresult
0XX0
10X0
1100
1111
99 # A budget-control generation (Gemini 2.5) takes no effort at all, so the
100 # off switch cannot become effort 'none' there (it would croak, and collide
101 # with a thinking_budget); it stays a bare thinking_enabled => 0, which no
102 # serializer of that generation sends and drops_thinking_enabled_on reports.
103 # Mapping it to thinkingBudget 0 is not done: which 2.5 models take 0 is
104 # unverified.
105 0 ▶ my $profile = Langertha::Reasoning::Profile->for_model( $args->{model} // '' );
Condition50%2/4
$args->{"model"} // ""
l!l
311
$$args{"model"} // ""
l!l
00
MC/DC100%1/1
$args->{"model"} // ""
$args->{"model"}
MC/DC0%0/1
$$args{"model"} // ""
$$args{"model"}
Truth table100%2/2
A
A= $args->{"model"}
Aresult
11
00
Truth table0%0/2
A
A= $$args{"model"}
Aresult
11
00
106 0 ▶ return $args if $profile->control eq 'budget';
Branch: 2 branches
BranchTrueFalseTotal
if $profile->control eq "budget" 7 25 32
if $profile->control eq "budget" 0 0 0
107 0 return { %$args, effort => 'none' };
108 }
109  
110  
111 13878 ▶sub assert_switch_agrees {
Subroutine assert_switch_agrees: called CC=6 SCAR=23.5
Pod documented
112 0 ▶ my ( $self, $thinking_enabled, $effort ) = @_;
Subroutine assert_switch_agrees: not called CC=6 SCAR=23.5
Pod documented
113 0 ▶ return unless defined $thinking_enabled && defined $effort;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $thinking_enabled and defined $effort 13828 50 13878
unless defined $thinking_enabled and defined $effort 0 0 0
Condition50%3/6
defined $thinking_enabled and defined $effort
!ll&&!rl&&r
137884050
defined $thinking_enabled and defined $effort
!ll&&!rl&&r
000
MC/DC100%2/2
defined $thinking_enabled and defined $effort
defined $thinking_enabled defined $effort
MC/DC0%0/2
defined $thinking_enabled and defined $effort
defined $thinking_enabled defined $effort
Truth table100%3/3
A and B
A= defined $thinking_enabledB= defined $effort
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $thinking_enabledB= defined $effort
ABresult
0X0
100
111
114 0 my $effort_on = $effort ne 'none';
115 0 ▶ return if $thinking_enabled ? $effort_on : !$effort_on;
Branch: 4 branches
BranchTrueFalseTotal
if $thinking_enabled ? $effort_on : !$effort_on 33 17 50
$thinking_enabled ? : 11 39 50
if $thinking_enabled ? $effort_on : !$effort_on 0 0 0
$thinking_enabled ? : 0 0 0
116 0 ▶ croak "Langertha::Reasoning: thinking_enabled => "
Branch: 2 branches
BranchTrueFalseTotal
$thinking_enabled ? : 7 10 17
$thinking_enabled ? : 0 0 0
117 . ( $thinking_enabled ? 1 : 0 ) . " contradicts effort '"
118 . $effort . "' -- thinking off is effort 'none', thinking on is "
119 . "any other effort level; set one of them, or make them agree";
120 }
121  
122  
123 # Build-time wire-truth gate: exactly one native control per generation, never
124 # both. Errors here surface before the request is built (Langertha::Engine::Gemini
125 # calls to() inside chat_request), so a misconfigured engine never produces an
126 # ambiguous wire form. The budget-vs-effort split derives from the resolved
127 # profile's control (Gemini 2.5 is the only control=budget family today), so the
128 # family boundary lives in Langertha::Reasoning::Profile, not in an inline regex.
129 9633 ▶sub BUILD {
Subroutine BUILD: called CC=10 SCAR=31.1
Pod undocumented
130 0 ▶ my ( $self ) = @_;
Subroutine BUILD: not called CC=10 SCAR=31.1
Pod undocumented
131  
132 0 ▶ $self->assert_switch_agrees(
Branch: 4 branches
BranchTrueFalseTotal
$self->has_thinking_enabled ? : 44 9589 9633
$self->has_effort ? : 9308 325 9633
$self->has_thinking_enabled ? : 0 0 0
$self->has_effort ? : 0 0 0
133 ( $self->has_thinking_enabled ? $self->thinking_enabled : undef ),
134 ( $self->has_effort ? $self->effort : undef ),
135 );
136  
137 0 my $has_effort = $self->has_effort;
138 0 my $has_budget = $self->has_thinking_budget;
139 0 ▶ my $model = $self->has_model ? $self->model : '';
Branch: 2 branches
BranchTrueFalseTotal
$self->has_model ? : 9600 29 9629
$self->has_model ? : 0 0 0
140  
141 0 ▶ if ( $has_effort && $has_budget ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($has_effort and $has_budget) 3 9626 9629
if ($has_effort and $has_budget) 0 0 0
Condition50%3/6
$has_effort and $has_budget
!ll&&!rl&&r
32593013
$has_effort and $has_budget
!ll&&!rl&&r
000
MC/DC100%2/2
$has_effort and $has_budget
$has_effort $has_budget
MC/DC0%0/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
Truth table0%0/3
A and B
A= $has_effortB= $has_budget
ABresult
0X0
100
111
142 0 croak "Langertha::Reasoning: 'effort' and 'thinking_budget' are mutually "
143 . "exclusive — pick one (effort -> thinkingLevel, thinking_budget -> "
144 . "thinkingBudget); model='" . $model . "'";
145 }
146  
147 0 my $is_budget_control = $self->_profile->control eq 'budget';
148  
149 0 ▶ if ( $has_budget && !$is_budget_control ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($has_budget and not $is_budget_control) 186 9440 9626
if ($has_budget and not $is_budget_control) 0 0 0
Condition50%3/6
$has_budget and not $is_budget_control
!ll&&!rl&&r
942812186
$has_budget and not $is_budget_control
!ll&&!rl&&r
000
MC/DC100%2/2
$has_budget and not $is_budget_control
$has_budget not $is_budget_control
MC/DC0%0/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
Truth table0%0/3
A and not(B)
A= $has_budgetB= not $is_budget_control
ABresult
0X0
100
111
150 0 croak "Langertha::Reasoning: 'thinking_budget' is only valid on Gemini 2.5 "
151 . "models (model id starting with 'gemini-2.5'); got model='" . $model . "'";
152 }
153  
154 0 ▶ if ( $has_effort && $is_budget_control ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($has_effort and $is_budget_control) 161 9279 9440
if ($has_effort and $is_budget_control) 0 0 0
Condition50%3/6
$has_effort and $is_budget_control
!ll&&!rl&&r
1399140161
$has_effort and $is_budget_control
!ll&&!rl&&r
000
MC/DC100%2/2
$has_effort and $is_budget_control
$has_effort $is_budget_control
MC/DC0%0/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
Truth table0%0/3
A and B
A= $has_effortB= $is_budget_control
ABresult
0X0
100
111
155 0 croak "Langertha::Reasoning: 'effort' is not valid on Gemini 2.5 models — "
156 . "use 'thinking_budget' (integer tokens) instead; got model='"
157 . $model . "'";
158 }
159 }
160  
161 1660 ▶sub to_gemini_level {
Subroutine to_gemini_level: called CC=1 SCAR=1.2
Pod documented
162 0 ▶ my ( $self ) = @_;
Subroutine to_gemini_level: not called CC=1 SCAR=1.2
Pod documented
163 0 return $self->_profile->gemini_level_for( $self->effort );
164 }
165  
166  
167 # A thinking-toggle model (Profile thinking_on, karr k209/k215) on an endpoint
168 # that opted in (thinking_toggle: MiniMax, MiniMaxAnthropic, Moonshot,
169 # MoonshotAnthropic)
170 # takes a `thinking` object with an on/off type and no effort level, on both the
171 # openai and the anthropic wire: none -> off where the model can disable (else
172 # the field is omitted), any other level -> the model's on-type. On any other
173 # endpoint the same id serializes like the passthrough default (review I1).
174 # thinking_display rides along on the anthropic wire only, never on an off
175 # toggle; a display-only request turns the toggle on, as the adaptive path does.
176 # Whether MiniMax / Kimi accept `display` there is unverified (it is a
177 # first-party Anthropic field; kept because MiniMaxAnthropic sent it before k209).
178 215 ▶sub _thinking_toggle {
Subroutine _thinking_toggle: called CC=8 SCAR=29.0
179 0 ▶ my ( $self, $with_display ) = @_;
Subroutine _thinking_toggle: not called CC=8 SCAR=29.0
180 0 my $profile = $self->_profile;
181 0 ▶ my $display = $with_display && $self->has_thinking_display;
Condition50%3/6
$with_display && $self->has_thinking_display
!ll&&!rl&&r
721358
$with_display && $self->has_thinking_display
!ll&&!rl&&r
000
MC/DC100%2/2
$with_display && $self->has_thinking_display
$with_display $self->has_thinking_display
MC/DC0%0/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
Truth table0%0/3
A && B
A= $with_displayB= $self->has_thinking_display
ABresult
0X0
100
111
182 # thinking_enabled without an effort is always 1 here (0 is normalized to
183 # effort 'none' in BUILDARGS), so it turns the toggle on (karr k382).
184 0 ▶ my $thinking = $self->has_effort ? $profile->thinking_toggle_for( $self->effort )
Branch: 4 branches
BranchTrueFalseTotal
$self->has_effort ? : 202 13 215
$display || $self->has_thinking_enabled ? : 8 5 13
$self->has_effort ? : 0 0 0
$display || $self->has_thinking_enabled ? : 0 0 0
Condition33%2/6
$display or $self->has_thinking_enabled
l!l&&r!l&&!r
805
$display or $self->has_thinking_enabled
l!l&&r!l&&!r
000
MC/DC50%1/2
$display or $self->has_thinking_enabled
$display $self->has_thinking_enabled
MC/DC0%0/2
$display or $self->has_thinking_enabled
$display $self->has_thinking_enabled
Truth table66%2/3
A or B
A= $displayB= $self->has_thinking_enabled
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $displayB= $self->has_thinking_enabled
ABresult
1X1
011
000
185 : $display || $self->has_thinking_enabled
186 ? { type => $profile->thinking_on }
187 : undef;
188 0 ▶ return () unless $thinking;
Branch: 2 branches
BranchTrueFalseTotal
unless $thinking 15 200 215
unless $thinking 0 0 0
189 $thinking = { %$thinking, display => $self->thinking_display }
190 0 ▶ if $display && $thinking->{type} ne 'disabled';
Branch: 2 branches
BranchTrueFalseTotal
if $display and $thinking->{"type"} ne "disabled" 8 192 200
if $display and $$thinking{"type"} ne "disabled" 0 0 0
Condition33%2/6
$display and $thinking->{"type"} ne "disabled"
!ll&&!rl&&r
19208
$display and $$thinking{"type"} ne "disabled"
!ll&&!rl&&r
000
MC/DC50%1/2
$display and $thinking->{"type"} ne "disabled"
$display $thinking->{"type"} ne "disabled"
MC/DC0%0/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
Truth table0%0/3
A and B
A= $displayB= $$thinking{"type"} ne "disabled"
ABresult
0X0
100
111
191 0 return ( thinking => $thinking );
192 }
193  
194 2292 ▶sub to_openai {
Subroutine to_openai: called CC=4 SCAR=17.9
Pod documented
195 0 ▶ my ( $self ) = @_;
Subroutine to_openai: not called CC=4 SCAR=17.9
Pod documented
196 0 ▶ return $self->_thinking_toggle(0) if $self->_profile->has_thinking_on;
Branch: 2 branches
BranchTrueFalseTotal
if $self->_profile->has_thinking_on 72 2220 2292
if $self->_profile->has_thinking_on 0 0 0
197 0 ▶ return () unless $self->has_effort;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->has_effort 55 2165 2220
unless $self->has_effort 0 0 0
198 0 ▶ return () unless $self->_profile->effort_accepted_on( 'openai', $self->effort );
Branch: 2 branches
BranchTrueFalseTotal
unless $self->_profile->effort_accepted_on("openai", $self->effort) 260 1905 2165
unless $self->_profile->effort_accepted_on("openai", $self->effort) 0 0 0
199 0 return ( reasoning_effort => $self->effort );
200 }
201  
202 1737 ▶sub to_responses {
Subroutine to_responses: called CC=3 SCAR=14.2
Pod documented
203 0 ▶ my ( $self ) = @_;
Subroutine to_responses: not called CC=3 SCAR=14.2
Pod documented
204 0 ▶ return () unless $self->has_effort;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->has_effort 8 1729 1737
unless $self->has_effort 0 0 0
205 0 ▶ return () unless $self->_profile->effort_accepted_on( 'responses', $self->effort );
Branch: 2 branches
BranchTrueFalseTotal
unless $self->_profile->effort_accepted_on("responses", $self->effort) 165 1564 1729
unless $self->_profile->effort_accepted_on("responses", $self->effort) 0 0 0
206 0 return ( reasoning => { effort => $self->effort } );
207 }
208  
209  
210 1898 ▶sub to_anthropic {
Subroutine to_anthropic: called CC=9 SCAR=29.5
Pod documented
211 0 ▶ my ( $self ) = @_;
Subroutine to_anthropic: not called CC=9 SCAR=29.5
Pod documented
212 0 ▶ return $self->_thinking_toggle(1) if $self->_profile->has_thinking_on;
Branch: 2 branches
BranchTrueFalseTotal
if $self->_profile->has_thinking_on 143 1755 1898
if $self->_profile->has_thinking_on 0 0 0
213 0 ▶ my $e = $self->has_effort ? $self->effort : undef;
Branch: 2 branches
BranchTrueFalseTotal
$self->has_effort ? : 1732 23 1755
$self->has_effort ? : 0 0 0
214 0 ▶ my $effort_ok = defined $e && $self->_profile->anthropic_effort_ok($e);
Condition50%3/6
defined $e && $self->_profile->anthropic_effort_ok($e)
!ll&&!rl&&r
235181214
defined $e && $self->_profile->anthropic_effort_ok($e)
!ll&&!rl&&r
000
MC/DC100%2/2
defined $e && $self->_profile->anthropic_effort_ok($e)
defined $e $self->_profile->anthropic_effort_ok($e)
MC/DC0%0/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
Truth table0%0/3
A && B
A= defined $eB= $self->_profile->anthropic_effort_ok($e)
ABresult
0X0
100
111
215  
216 # Adaptive-thinking models need thinking:{type:adaptive} or thinking stays
217 # off; always-on "Fable-class" models 400 on thinking:{type:disabled} and
218 # need no thinking field at all (thinking is always on). thinking.display
219 # controls visibility: the wire default is "omitted" on every current model,
220 # so $response->thinking comes back empty unless the caller asks for
221 # "summarized". We emit the thinking block whenever an effort or a display is
222 # in play so a display-only request still turns summaries on.
223 0 my @thinking;
224 0 ▶ if ( !$self->_profile->fable_class && ( $effort_ok || $self->has_thinking_display ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->_profile->fable_class and $effort_ok || $self->has_thinking_display) 1199 556 1755
if (not $self->_profile->fable_class and $effort_ok || $self->has_thinking_display) 0 0 0
Condition50%6/12
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
not $self->_profile->fable_class and $effort_ok || $self->has_thinking_display
!ll&&!rl&&r
000
$effort_ok or $self->has_thinking_display
l!l&&r!l&&!r
000
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
MC/DC0%0/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
Truth table0%0/4
not(A) and B or C
A= not $self->_profile->fable_classB= $effort_okC= $self->has_thinking_display
ABCresult
0XX0
1000
11X1
1011
225 0 ▶ @thinking = ( thinking => {
Branch: 2 branches
BranchTrueFalseTotal
$self->has_thinking_display ? : 62 1137 1199
$self->has_thinking_display ? : 0 0 0
226 type => 'adaptive',
227 ( $self->has_thinking_display ? ( display => $self->thinking_display ) : () ),
228 } );
229 }
230  
231 return (
232 0 ▶ ( $effort_ok ? ( output_config => { effort => $e } ) : () ),
Branch: 2 branches
BranchTrueFalseTotal
$effort_ok ? : 1214 541 1755
$effort_ok ? : 0 0 0
233 @thinking,
234 );
235 }
236  
237  
238 1682 ▶sub to_gemini {
Subroutine to_gemini: called CC=3 SCAR=14.2
Pod undocumented
239 0 ▶ my ( $self ) = @_;
Subroutine to_gemini: not called CC=3 SCAR=14.2
Pod undocumented
240 0 ▶ if ( $self->has_thinking_budget ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_thinking_budget) 12 1670 1682
if ($self->has_thinking_budget) 0 0 0
241 # BUILD has already verified the model is Gemini 2.5.
242 0 return ( thinkingConfig => { thinkingBudget => $self->thinking_budget } );
243 }
244 0 ▶ return () unless $self->has_effort;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->has_effort 10 1660 1670
unless $self->has_effort 0 0 0
245 0 return ( thinkingConfig => { thinkingLevel => $self->to_gemini_level } );
246 }
247  
248 1554 ▶sub to_ollama {
Subroutine to_ollama: called CC=7 SCAR=26.5
Pod documented
249 0 ▶ my ( $self ) = @_;
Subroutine to_ollama: not called CC=7 SCAR=26.5
Pod documented
250 # A bare thinking_enabled => 1 is the boolean on-switch; GPT-OSS has no
251 # level-free form, so nothing there (drops_thinking_enabled_on).
252 0 ▶ unless ( $self->has_effort ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->has_effort) 5 1549 1554
unless ($self->has_effort) 0 0 0
253 0 ▶ return () unless $self->has_thinking_enabled && $self->thinking_enabled
Branch: 2 branches
BranchTrueFalseTotal
unless $self->has_thinking_enabled and $self->thinking_enabled and not $self->_profile->has_ollama_levels 3 2 5
unless $self->has_thinking_enabled and $self->thinking_enabled and not $self->_profile->has_ollama_levels 0 0 0
Condition41%5/12
$self->has_thinking_enabled and $self->thinking_enabled and not $self->_profile->has_ollama_levels
!ll&&!rl&&r
122
$self->has_thinking_enabled and $self->thinking_enabled
!ll&&!rl&&r
104
$self->has_thinking_enabled and $self->thinking_enabled and not $self->_profile->has_ollama_levels
!ll&&!rl&&r
000
$self->has_thinking_enabled and $self->thinking_enabled
!ll&&!rl&&r
000
MC/DC66%2/3
$self->has_thinking_enabled and $self->thinking_enabled and not $self->_profile->has_ollama_levels
$self->has_thinking_enabled $self->thinking_enabled not $self->_profile->has_ollama_levels
MC/DC0%0/3
$self->has_thinking_enabled and $self->thinking_enabled and not $self->_profile->has_ollama_levels
$self->has_thinking_enabled $self->thinking_enabled not $self->_profile->has_ollama_levels
Truth table75%3/4
A and B and not(C)
A= $self->has_thinking_enabledB= $self->thinking_enabledC= not $self->_profile->has_ollama_levels
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and not(C)
A= $self->has_thinking_enabledB= $self->thinking_enabledC= not $self->_profile->has_ollama_levels
ABCresult
0XX0
10X0
1100
1111
254 && !$self->_profile->has_ollama_levels;
255 0 return ( think => JSON->true );
256 }
257 # GPT-OSS takes graded level STRINGS on the options.think knob
258 # (low<medium<high<max) and ALWAYS reasons — there is no "off": think:false is
259 # ignored, so a boolean has zero effect and 'none' maps to the floor 'low'.
260 # Live-probed 2026-09-17 via ollama.com gpt-oss:20b (k175). Every other model
261 # takes only the boolean: any effort level -> on, 'none' -> off.
262 0 ▶ return ( think => $self->_profile->ollama_level_for( $self->effort ) )
Branch: 2 branches
BranchTrueFalseTotal
if $self->_profile->has_ollama_levels 33 1516 1549
if $self->_profile->has_ollama_levels 0 0 0
263 if $self->_profile->has_ollama_levels;
264 0 ▶ return ( think => $self->effort eq 'none' ? JSON->false : JSON->true );
Branch: 2 branches
BranchTrueFalseTotal
$self->effort eq 'none' ? : 220 1296 1516
$self->effort eq 'none' ? : 0 0 0
265 }
266  
267  
268 # Self-hosted OpenAI-compatible servers (llama.cpp, SGLang; opt-in for any
269 # other) switch thinking through the chat template: top-level
270 # chat_template_kwargs.enable_thinking (karr k382, advisor-validated against the
271 # llama.cpp / SGLang source). The OpenAI per-model effort ladder is NOT
272 # consulted -- a self-hosted model id is whatever the operator named it, so the
273 # effort goes out unclamped. enable_thinking must be a real JSON boolean:
274 # llama.cpp reacts only to true/false after dumping the kwargs (a 0/1 desyncs
275 # template and reasoning parser), and a string 400s. 'none' sends no
276 # reasoning_effort, because older SGLang, gpt-oss and MiniMax-M3 templates 400
277 # on it.
278 115 ▶sub to_chat_template_kwargs {
Subroutine to_chat_template_kwargs: called CC=5 SCAR=21.8
Pod documented
279 0 ▶ my ( $self ) = @_;
Subroutine to_chat_template_kwargs: not called CC=5 SCAR=21.8
Pod documented
280 0 ▶ if ( $self->has_effort ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_effort) 103 12 115
if ($self->has_effort) 0 0 0
281 0 ▶ return ( chat_template_kwargs => { enable_thinking => JSON->false } )
Branch: 2 branches
BranchTrueFalseTotal
if $self->effort eq "none" 34 69 103
if $self->effort eq "none" 0 0 0
282 if $self->effort eq 'none';
283 return (
284 0 chat_template_kwargs => { enable_thinking => JSON->true },
285 reasoning_effort => $self->effort,
286 );
287 }
288 0 ▶ return () unless $self->has_thinking_enabled;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->has_thinking_enabled 7 5 12
unless $self->has_thinking_enabled 0 0 0
289 0 ▶ return ( chat_template_kwargs => {
Branch: 2 branches
BranchTrueFalseTotal
$self->thinking_enabled ? : 5 0 5
$self->thinking_enabled ? : 0 0 0
290 enable_thinking => $self->thinking_enabled ? JSON->true : JSON->false,
291 } );
292 }
293  
294  
295 1307 ▶sub drops_thinking_enabled_on {
Subroutine drops_thinking_enabled_on: called CC=11 SCAR=36.5
Pod documented
296 0 ▶ my ( $self, $fmt ) = @_;
Subroutine drops_thinking_enabled_on: not called CC=11 SCAR=36.5
Pod documented
297 0 ▶ return 0 unless $self->has_thinking_enabled && !$self->has_effort;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->has_thinking_enabled and not $self->has_effort 1289 18 1307
unless $self->has_thinking_enabled and not $self->has_effort 0 0 0
Condition50%3/6
$self->has_thinking_enabled and not $self->has_effort
!ll&&!rl&&r
12701918
$self->has_thinking_enabled and not $self->has_effort
!ll&&!rl&&r
000
MC/DC100%2/2
$self->has_thinking_enabled and not $self->has_effort
$self->has_thinking_enabled not $self->has_effort
MC/DC0%0/2
$self->has_thinking_enabled and not $self->has_effort
$self->has_thinking_enabled not $self->has_effort
Truth table100%3/3
A and not(B)
A= $self->has_thinking_enabledB= not $self->has_effort
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $self->has_thinking_enabledB= not $self->has_effort
ABresult
0X0
100
111
298 0 ▶ $fmt //= '';
Condition25%1/4
$fmt //= ""
l!l
180
$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
299 0 ▶ return 0 if $fmt eq 'chat_template_kwargs';
Branch: 2 branches
BranchTrueFalseTotal
if $fmt eq "chat_template_kwargs" 5 13 18
if $fmt eq "chat_template_kwargs" 0 0 0
300 # An off switch left without an effort is one normalize_off_switch kept (a
301 # budget generation): no other wire sends it.
302 0 ▶ return 1 unless $self->thinking_enabled;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->thinking_enabled 4 9 13
unless $self->thinking_enabled 0 0 0
303 # The toggle path of to_openai / to_anthropic has an on-type of its own.
304 0 ▶ return 0 if $self->_profile->has_thinking_on && ( $fmt eq 'openai' || $fmt eq 'anthropic' );
Branch: 2 branches
BranchTrueFalseTotal
if $self->_profile->has_thinking_on and $fmt eq "openai" || $fmt eq "anthropic" 0 9 9
if $self->_profile->has_thinking_on and $fmt eq "openai" || $fmt eq "anthropic" 0 0 0
Condition8%1/12
$self->_profile->has_thinking_on and $fmt eq "openai" || $fmt eq "anthropic"
!ll&&!rl&&r
900
$fmt eq "openai" or $fmt eq "anthropic"
l!l&&r!l&&!r
000
$self->_profile->has_thinking_on and $fmt eq "openai" || $fmt eq "anthropic"
!ll&&!rl&&r
000
$fmt eq "openai" or $fmt eq "anthropic"
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->_profile->has_thinking_on and $fmt eq "openai" || $fmt eq "anthropic"
$self->_profile->has_thinking_on $fmt eq "openai" $fmt eq "anthropic"
MC/DC0%0/3
$self->_profile->has_thinking_on and $fmt eq "openai" || $fmt eq "anthropic"
$self->_profile->has_thinking_on $fmt eq "openai" $fmt eq "anthropic"
Truth table25%1/4
A and B or C
A= $self->_profile->has_thinking_onB= $fmt eq "openai"C= $fmt eq "anthropic"
ABCresult
0XX0
1000
11X1
1011
Truth table0%0/4
A and B or C
A= $self->_profile->has_thinking_onB= $fmt eq "openai"C= $fmt eq "anthropic"
ABCresult
0XX0
1000
11X1
1011
305 # Ollama's boolean think; GPT-OSS takes only levels, so nothing there.
306 0 ▶ return 0 if $fmt eq 'ollama' && !$self->_profile->has_ollama_levels;
Branch: 2 branches
BranchTrueFalseTotal
if $fmt eq "ollama" and not $self->_profile->has_ollama_levels 2 7 9
if $fmt eq "ollama" and not $self->_profile->has_ollama_levels 0 0 0
Condition50%3/6
$fmt eq "ollama" and not $self->_profile->has_ollama_levels
!ll&&!rl&&r
522
$fmt eq "ollama" and not $self->_profile->has_ollama_levels
!ll&&!rl&&r
000
MC/DC100%2/2
$fmt eq "ollama" and not $self->_profile->has_ollama_levels
$fmt eq "ollama" not $self->_profile->has_ollama_levels
MC/DC0%0/2
$fmt eq "ollama" and not $self->_profile->has_ollama_levels
$fmt eq "ollama" not $self->_profile->has_ollama_levels
Truth table100%3/3
A and not(B)
A= $fmt eq "ollama"B= not $self->_profile->has_ollama_levels
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $fmt eq "ollama"B= not $self->_profile->has_ollama_levels
ABresult
0X0
100
111
307 0 return 1;
308 }
309  
310  
311 # Maps a reasoning_wire_format tag to the per-format serializer method.
312 193 my %TO_METHOD = (
313 openai => 'to_openai',
314 responses => 'to_responses',
315 anthropic => 'to_anthropic',
316 gemini => 'to_gemini',
317 ollama => 'to_ollama',
318 chat_template_kwargs => 'to_chat_template_kwargs',
319 );
320  
321 9278 ▶sub to {
Subroutine to: called CC=4 SCAR=23.1
Pod documented
322 0 ▶ my ( $self, $fmt ) = @_;
Subroutine to: not called CC=4 SCAR=23.1
Pod documented
323 0 ▶ my $method = $TO_METHOD{ $fmt // '' }
Branch: 2 branches
BranchTrueFalseTotal
my $method = $TO_METHOD{$fmt // ""} or croak(q[Langertha::Reasoning: unknown reasoning wire format '] . ($fmt // "") . q[']) 9278 0 9278
my $method = $TO_METHOD{$fmt // ""} or croak(q[Langertha::Reasoning: unknown reasoning wire format '] . ($fmt // "") . q[']) 0 0 0
Condition12%1/8
$fmt // ""
l!l
92780
$fmt // ""
l!l
00
$fmt // ""
l!l
00
$fmt // ""
l!l
00
MC/DC0%0/1
$fmt // ""
$fmt
MC/DC0%0/1
$fmt // ""
$fmt
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
Truth table0%0/2
A
A= $fmt
Aresult
11
00
Truth table0%0/2
A
A= $fmt
Aresult
11
00
324 or croak "Langertha::Reasoning: unknown reasoning wire format '" . ( $fmt // '' ) . "'";
325 0 return $self->$method;
326 }
327  
328  
329 193 __PACKAGE__->meta->make_immutable;
330  
331  
332 193 1;
333  
334 __END__
« blib/lib/Langertha/Engine/Gemini.pm ↑ Summary blib/lib/Langertha/Role/ReasoningEffort.pm »