blib/lib/Langertha/Role/ReasoningEffort.pm

filter: Statementstmt 90.0% 18 / 20 Branchbran 92.8% 26 / 28 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 80.0% 4 / 5 Podpod 100% 2 / 2 totaltotal 89.2% 58 / 65 CC 17 SCAR 26.5
CC
17
Cov
91%
reasoning_kwargs_for
17.1
reasoning_kwargs
2.0
BEGIN
1.0
CRAP 14.1
« blib/lib/Langertha/Manifest/Builder.pm ↑ Summary blib/lib/Langertha/Role/Capabilities.pm »
1 package Langertha::Role::ReasoningEffort;
2 # ABSTRACT: Role for an engine with a request-side reasoning-effort control
3 177 our $VERSION = '0.503';
4 177 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 177 ▶use Langertha::Reasoning;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 177 has reasoning_effort => (
8 is => 'ro',
9 isa => 'Str',
10 predicate => 'has_reasoning_effort',
11 );
12  
13  
14 177 has thinking_budget => (
15 is => 'ro',
16 isa => 'Int',
17 predicate => 'has_thinking_budget',
18 );
19  
20  
21 177 has thinking_display => (
22 is => 'ro',
23 isa => 'Str',
24 predicate => 'has_thinking_display',
25 );
26  
27  
28 177 has reasoning_wire_format => (
29 is => 'ro',
30 isa => 'Str',
31 lazy => 1,
32 builder => '_build_reasoning_wire_format',
33 );
34  
35 # Defaults to the OpenAI /chat/completions dialect; AnthropicBase, Gemini and
36 # OpenAIResponses override the builder. Deliberately NOT keyed off
37 # tool_wire_format — engines sharing tool_wire_format=openai (DeepSeek, MiniMax,
38 # Groq) disagree on the reasoning field.
39 404 ▶sub _build_reasoning_wire_format { 'openai' }
Subroutine _build_reasoning_wire_format: called CC=1 SCAR=0.0
40  
41  
42 2909 ▶sub reasoning_kwargs_for {
Subroutine reasoning_kwargs_for: called CC=17 SCAR=28.4
Pod documented
43 2909 my ( $self, %args ) = @_;
44  
45 # The wire agrees with the capability registry (karr #204, ADR 0009): an
46 # engine that advertises neither reasoning control takes none, so nothing
47 # is sent. Both flags, not reasoning_effort alone -- Gemini 2.5 clears
48 # reasoning_effort per model yet takes thinkingBudget, and its effort croak
49 # (ADR 0023) must stay loud.
50 return ()
51 2909 ▶ unless $self->supports('reasoning_effort') || $self->supports('thinking_budget');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->supports("reasoning_effort") or $self->supports("thinking_budget") 108 2801 2909
Condition100%3/3
$self->supports("reasoning_effort") or $self->supports("thinking_budget")
l!l&&r!l&&!r
274160108
MC/DC100%2/2
$self->supports("reasoning_effort") or $self->supports("thinking_budget")
$self->supports("reasoning_effort") $self->supports("thinking_budget")
Truth table100%3/3
A or B
A= $self->supports("reasoning_effort")B= $self->supports("thinking_budget")
ABresult
1X1
011
000
52  
53 # Per-request controls (chat_f, karr #46) beat the engine attributes on a
54 # per-key basis: %args may carry effort / thinking_budget (or the canonical
55 # control names reasoning_effort / thinking_budget, so the whole controls
56 # hash can be passed wholesale), and any key it does not carry falls back
57 # to the configured attribute.
58 my %merged = (
59 ( $self->has_reasoning_effort ? ( effort => $self->reasoning_effort ) : () ),
60 ( $self->has_thinking_budget ? ( thinking_budget => $self->thinking_budget ) : () ),
61 ( $self->has_thinking_display ? ( thinking_display => $self->thinking_display ) : () ),
62 ( exists $args{effort} ? ( effort => $args{effort} ) : () ),
63 ( exists $args{reasoning_effort} ? ( effort => $args{reasoning_effort} ) : () ),
64 ( exists $args{thinking_budget} ? ( thinking_budget => $args{thinking_budget} ) : () ),
65 2801 ▶ ( exists $args{thinking_display} ? ( thinking_display => $args{thinking_display} ) : () ),
Branch: 7 branches
BranchTrueFalseTotal
$self->has_reasoning_effort ? : 1036 1765 2801
$self->has_thinking_budget ? : 95 2706 2801
$self->has_thinking_display ? : 191 2610 2801
exists $args{'effort'} ? : 0 2801 2801
exists $args{'reasoning_effort'} ? : 204 2597 2801
exists $args{'thinking_budget'} ? : 93 2708 2801
exists $args{'thinking_display'} ? : 2 2799 2801
66 );
67 2801 ▶ return () unless %merged;
Branch: 1 branch
BranchTrueFalseTotal
unless %merged 1363 1438 2801
68 return Langertha::Reasoning->new(
69 ( exists $merged{effort} ? ( effort => $merged{effort} ) : () ),
70 ( exists $merged{thinking_budget} ? ( thinking_budget => $merged{thinking_budget} ) : () ),
71 1438 ▶ ( exists $merged{thinking_display} ? ( thinking_display => $merged{thinking_display} ) : () ),
Branch: 5 branches
BranchTrueFalseTotal
exists $merged{'effort'} ? : 1143 295 1438
exists $merged{'thinking_budget'} ? : 188 1250 1438
exists $merged{'thinking_display'} ? : 193 1245 1438
$self->can('chat_model') ? : 1438 0 1438
$self->can('_reasoning_thinking_toggle') && $self->_reasoning_thinking_toggle ? : 305 1133 1438
Condition66%2/3
$self->can("_reasoning_thinking_toggle") and $self->_reasoning_thinking_toggle
!ll&&!rl&&r
11330305
MC/DC50%1/2
$self->can("_reasoning_thinking_toggle") and $self->_reasoning_thinking_toggle
$self->can("_reasoning_thinking_toggle") $self->_reasoning_thinking_toggle
Truth table66%2/3
A and B
A= $self->can("_reasoning_thinking_toggle")B= $self->_reasoning_thinking_toggle
ABresult
0X0
100
111
72 ( $self->can('chat_model') ? ( model => $self->chat_model ) : () ),
73 # The thinking on/off toggle (MiniMax, both Kimi faces) is an
74 # endpoint's spelling, not a model's: an engine opts in with
75 # _reasoning_thinking_toggle, every other engine serializes a toggle
76 # model's id like any unlisted id (ADR 0023 k209 Update, review I1).
77 ( $self->can('_reasoning_thinking_toggle') && $self->_reasoning_thinking_toggle
78 ? ( thinking_toggle => 1 ) : () ),
79 )->to( $self->reasoning_wire_format );
80 }
81  
82  
83 0 ▶sub reasoning_kwargs {
Subroutine reasoning_kwargs: not called CC=1 SCAR=6.9
Pod documented
84 0 my ( $self ) = @_;
85 0 return $self->reasoning_kwargs_for;
86 }
87  
88  
89  
90 177 1;
91  
92 __END__
93  
94 =pod
95  
96 =encoding UTF-8
97  
98 =head1 NAME
99  
100 Langertha::Role::ReasoningEffort - Role for an engine with a request-side reasoning-effort control
101  
102 =head1 VERSION
103  
104 version 0.503
105  
106 =head2 reasoning_effort
107  
108 Normalized request-side reasoning effort. Vocabulary (the OpenAI superset):
109 C<none>, C<minimal>, C<low>, C<medium>, C<high>, C<xhigh>, C<max>. When set, it
110 is translated to the provider-specific wire field via L<Langertha::Reasoning>
111 keyed by L</reasoning_wire_format>; values the target wire cannot accept are
112 dropped. When not set, no reasoning field is emitted and the model's own
113 default applies.
114  
115 Note this is a request-side control, distinct from L<Langertha::Role::ThinkTag>
116 (which filters C<E<lt>thinkE<gt>> tags out of responses).
117  
118 =head2 thinking_budget
119  
120 Optional integer thinking budget, currently consumed only by Gemini 2.5 models
121 (L<Langertha::Engine::Gemini>): on C<gemini-2.5-*> the value is emitted as
122 C<generationConfig.thinkingConfig.thinkingBudget>. On Gemini 3 models
123 C<thinking_budget> is rejected — Gemini 3 takes C<thinkingLevel>, not the
124 integer budget; setting both L</reasoning_effort> and C<thinking_budget> on a
125 Gemini 3 model croaks at construction (L<Langertha::Reasoning/BUILD>). When
126 unset, no budget field is emitted. (Anthropic legacy C<budget_tokens> is
127 deliberately not modeled: it 400s on current Claude families.)
128  
129 =head2 thinking_display
130  
131 Optional Anthropic thinking-visibility control (C<summarized> | C<omitted> |
132 C<updates>), serialized by L<Langertha::Reasoning/to_anthropic> to
133 C<thinking.display>. On every current Claude model the wire default is
134 C<omitted>, which returns an empty C<< $response->thinking >>; set
135 C<thinking_display =E<gt> 'summarized'> to get a readable reasoning summary back
136 (it costs summary tokens, so it is opt-in rather than the Langertha default).
137 Ignored on non-Anthropic wires and on Fable-class models (which never carry a
138 C<thinking> block). Like L</reasoning_effort>, a per-request control (chat_f)
139 beats this attribute.
140  
141 =head2 reasoning_wire_format
142  
143 reasoning_wire_format => 'anthropic'
144  
145 The per-engine enum naming which reasoning dialect this engine speaks —
146 C<openai> | C<anthropic> | C<gemini> | C<responses>. Drives the value-object
147 dispatch in L</reasoning_kwargs>. The default follows the engine base-class
148 hierarchy: C<OpenAIBase> leaves it at C<openai>, C<AnthropicBase> overrides to
149 C<anthropic>, C<Gemini> to C<gemini>, C<OpenAIResponses> to C<responses>.
150  
151 =head2 reasoning_kwargs_for
152  
153 my %kwargs = $engine->reasoning_kwargs_for( effort => 'high' );
154 my %kwargs = $engine->reasoning_kwargs_for( %$controls );
155  
156 Returns the body kwargs to merge into a chat request for the reasoning
157 control, serialized for L</reasoning_wire_format> via L<Langertha::Reasoning>.
158 C<%args> may carry C<effort> and/or C<thinking_budget> (or the canonical
159 control names C<reasoning_effort> / C<thinking_budget>, so the whole controls
160 hash from chat_f can be passed wholesale); keys it does not carry fall back to
161 the engine attributes, so a per-request control (chat_f, karr #46) beats the
162 configured attribute on a per-key basis. Empty list when neither a per-request
163 value nor an attribute is set, when the value is unsupported on the engine's
164 wire, or when the engine advertises neither C<reasoning_effort> nor
165 C<thinking_budget> (L<Langertha::Role::Capabilities/supports>) -- clearing
166 those flags is how an engine says it takes no reasoning control, and nothing
167 is sent then. Engines override this only to model wire divergence within a
168 shared format (e.g. DeepSeek's model-gated split). An engine whose endpoint
169 speaks the C<thinking> on/off toggle (MiniMax, MiniMaxAnthropic, Moonshot,
170 MoonshotAnthropic) opts in by defining C<_reasoning_thinking_toggle> as true;
171 see L<Langertha::Reasoning/thinking_toggle>.
172  
173 =head2 reasoning_kwargs
174  
175 my %kwargs = $engine->reasoning_kwargs;
176  
177 Returns the body kwargs to merge into a chat request for the configured
178 C<reasoning_effort> and/or L</thinking_budget>, serialized for
179 L</reasoning_wire_format> via L<Langertha::Reasoning>. Empty list when neither
180 is set, or when the value is unsupported on the engine's wire. Delegates to
181 L</reasoning_kwargs_for> with no per-request overrides.
182  
183 =head1 SEE ALSO
184  
185 =over
186  
187 =item * L<Langertha::Reasoning> - The value object this role dispatches to
188  
189 =item * L<Langertha::Role::Capabilities> - Where C<reasoning_effort> is registered
190  
191 =item * L<Langertha::Role::Temperature> - Sibling request-side sampling control
192  
193 =back
194  
195 =head1 SUPPORT
196  
197 =head2 Issues
198  
199 Please report bugs and feature requests on GitHub at
200 L<https://github.com/Getty/langertha/issues>.
201  
202 =head2 IRC
203  
204 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
205  
206 =head1 CONTRIBUTING
207  
208 Contributions are welcome! Please fork the repository and submit a pull request.
209  
210 =head1 AUTHOR
211  
212 Torsten Raudssus <getty@cpan.org>
213  
214 =head1 COPYRIGHT AND LICENSE
215  
216 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
217  
218 This is free software; you can redistribute it and/or modify it under
219 the same terms as the Perl 5 programming language system itself.
220  
221 =cut
« blib/lib/Langertha/Manifest/Builder.pm ↑ Summary blib/lib/Langertha/Role/Capabilities.pm »