Agent.pm

filter: Statementstmt 11.9% 20 / 167 Branchbran 0.0% 0 / 90 Conditioncond 0.0% 0 / 79 MC/DCmcdc 0.0% 0 / 43 Subroutinesub 22.2% 6 / 27 Podpod 0.0% 0 / 1 totaltotal 6.3% 26 / 407 CC 83 SCAR 54.3
CC
83
Cov
6%
run
650.0
_apply_interrupt
272.0
_invoke_tool
210.0
CRAP 228.0
« Plugin.pm ↑ Summary Adapters/OpenAICompatible.pm »
1 package Praxo::Agent;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Praxo::Json ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Praxo::Models ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Praxo::Errors qw(praxo_error error_code);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our @EXPORT_OK = qw(run_agent);
11  
12 package Praxo::Agent::FuncTool;
13  
14 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
15 0 my ($class, $name, $description, $function, $parameters, $risk) = @_;
16 0 ▶ return bless {
Condition0%0/4
$name // ""
l!l
00
$description // ""
l!l
00
MC/DC0%0/1
$name // ""
$name
MC/DC0%0/1
$description // ""
$description
Truth table0%0/2
A
A= $name
Aresult
11
00
Truth table0%0/2
A
A= $description
Aresult
11
00
17 name => $name // '',
18 description => $description // '',
19 function => $function,
20 parameters => $parameters,
21 risk => $risk,
22 }, $class;
23 }
24  
25 0 ▶sub name { $_[0]->{name} }
Subroutine name: not called CC=1 SCAR=6.9
26 0 ▶sub description { $_[0]->{description} }
Subroutine description: not called CC=1 SCAR=6.9
27 0 ▶sub invoke { $_[0]->{function}->($_[1]) }
Subroutine invoke: not called CC=1 SCAR=6.9
28  
29 package Praxo::Agent::ToolRegistry;
30  
31 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
32 0 my ($class) = @_;
33 0 return bless { tools => {} }, $class;
34 }
35  
36 0 ▶sub register {
Subroutine register: not called CC=2 SCAR=17.9
37 0 my ($self, $tool) = @_;
38 0 ▶ my $name = ref($tool) ? $tool->name : $tool->{name};
Branch: 1 branch
BranchTrueFalseTotal
ref $tool ? : 0 0 0
39 0 $self->{tools}{$name} = $tool;
40 0 return $tool;
41 }
42  
43 0 ▶sub get {
Subroutine get: not called CC=2 SCAR=17.9
44 0 my ($self, $name) = @_;
45 Praxo::Errors::praxo_error('TOOL_NOT_FOUND', "tool not found: $name")
46 0 ▶ unless exists $self->{tools}{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"tools"}{$name} 0 0 0
47 0 return $self->{tools}{$name};
48 }
49  
50 0 ▶sub specs {
Subroutine specs: not called CC=7 SCAR=40.3
51 0 my ($self) = @_;
52 my @specs = map {
53 0 ▶ my $name = ref($_) ? $_->name : $_->{name};
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
54 0 ▶ my $description = ref($_) ? $_->description : $_->{description};
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
55 0 my ($parameters, $risk);
56 0 ▶ if (ref($_) && ref($_) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ and ref $_ ne 'HASH') { } 0 0 0
Condition0%0/3
ref $_ and ref $_ ne "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ and ref $_ ne "HASH"
ref $_ ref $_ ne "HASH"
Truth table0%0/3
A and B
A= ref $_B= ref $_ ne "HASH"
ABresult
0X0
100
111
57 0 ▶ $parameters = $_->can('parameters') ? $_->parameters : $_->{parameters};
Branch: 1 branch
BranchTrueFalseTotal
$_->can('parameters') ? : 0 0 0
58 0 ▶ $risk = $_->can('risk') ? $_->risk : $_->{risk};
Branch: 1 branch
BranchTrueFalseTotal
$_->can('risk') ? : 0 0 0
59 } else {
60 0 $parameters = $_->{parameters};
61 0 $risk = $_->{risk};
62 }
63 0 Praxo::Models::tool_spec(
64 name => $name,
65 description => $description,
66 parameters => $parameters,
67 risk => $risk,
68 )
69 0 } values %{ $self->{tools} };
70 0 return [ sort { $a->{name} cmp $b->{name} } @specs ];
71 }
72  
73 package Praxo::Agent::AgentOptions;
74  
75 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
76 0 my ($class, $model) = @_;
77 0 return bless {
78 model => $model,
79 tools => undef,
80 events => undef,
81 policy => undef,
82 system_prompt => '',
83 context => undef,
84 max_steps => 8,
85 max_tokens => 0,
86 tool_choice => undef,
87 allowed_tools => [],
88 on_delta => undef,
89 require_policy => 0,
90 require_tool_scope => 0,
91 interrupt_on => [],
92 on_interrupt_decision => undef,
93 on_interrupt => undef,
94 }, $class;
95 }
96  
97 package Praxo::Agent::StaticModel;
98  
99 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
100 0 my ($class, $content) = @_;
101 0 ▶ return bless { content => $content // '' }, $class;
Condition0%0/2
$content // ""
l!l
00
MC/DC0%0/1
$content // ""
$content
Truth table0%0/2
A
A= $content
Aresult
11
00
102 }
103  
104 0 ▶sub generate {
Subroutine generate: not called CC=1 SCAR=6.9
105 0 my ($self, $request) = @_;
106 return Praxo::Models::response(
107 0 message => Praxo::Models::message_assistant($self->{content}),
108 );
109 }
110  
111 package Praxo::Agent::Agent;
112  
113 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
114 0 my ($class, $options) = @_;
115 Praxo::Errors::praxo_error(
116 'AGENT_INVALID_OPTIONS',
117 'agent: require policy: policy is required',
118 0 ▶ ) if $options->{require_policy} && !$options->{policy};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"require_policy"} and not $options->{"policy"} 0 0 0
Condition0%0/3
$options->{"require_policy"} and not $options->{"policy"}
!ll&&!rl&&r
000
MC/DC0%0/2
$options->{"require_policy"} and not $options->{"policy"}
$options->{"require_policy"} not $options->{"policy"}
Truth table0%0/3
A and not(B)
A= $options->{"require_policy"}B= not $options->{"policy"}
ABresult
0X0
100
111
119 Praxo::Errors::praxo_error(
120 'AGENT_INVALID_OPTIONS',
121 'agent: require tool scope: allowed_tools must not be empty',
122 0 ▶ ) if $options->{require_tool_scope} && !@{ $options->{allowed_tools} // [] };
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"require_tool_scope"} and not @{$options->{"allowed_tools"} // [];} 0 0 0
Condition0%0/5
$options->{"require_tool_scope"} and not @{$options->{"allowed_tools"} // [];}
!ll&&!rl&&r
000
$options->{"allowed_tools"} // []
l!l
00
MC/DC0%0/2
$options->{"require_tool_scope"} and not @{$options->{"allowed_tools"} // [];}
$options->{"require_tool_scope"} not @{$options->{"allowed_tools"} // [];}
MC/DC0%0/1
$options->{"allowed_tools"} // []
$options->{"allowed_tools"}
Truth table0%0/3
A and not(B)
A= $options->{"require_tool_scope"}B= not @{$options->{"allowed_tools"} // [];}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $options->{"allowed_tools"}
Aresult
11
00
123 0 return bless { options => $options }, $class;
124 }
125  
126 0 ▶sub run {
Subroutine run: not called CC=25 SCAR=64.8
127 0 my ($self, $session, $prompt) = @_;
128 0 my $options = $self->{options};
129 0 ▶ my $max_steps = ($options->{max_steps} // 0) > 0 ? $options->{max_steps} : 8;
Branch: 1 branch
BranchTrueFalseTotal
($options->{'max_steps'} // 0) > 0 ? : 0 0 0
Condition0%0/2
$options->{"max_steps"} // 0
l!l
00
MC/DC0%0/1
$options->{"max_steps"} // 0
$options->{"max_steps"}
Truth table0%0/2
A
A= $options->{"max_steps"}
Aresult
11
00
130 0 my $run_id = 'run-' . int(time() * 1000);
131 0 ▶ my @messages = @{ $session->{messages} // [] };
Condition0%0/2
$session->{"messages"} // []
l!l
00
MC/DC0%0/1
$session->{"messages"} // []
$session->{"messages"}
Truth table0%0/2
A
A= $session->{"messages"}
Aresult
11
00
132 0 ▶ if (length($options->{system_prompt} // '')) {
Branch: 1 branch
BranchTrueFalseTotal
if (length($options->{"system_prompt"} // "")) 0 0 0
Condition0%0/2
$options->{"system_prompt"} // ""
l!l
00
MC/DC0%0/1
$options->{"system_prompt"} // ""
$options->{"system_prompt"}
Truth table0%0/2
A
A= $options->{"system_prompt"}
Aresult
11
00
133 unshift @messages, Praxo::Models::message_text(
134 Praxo::Models::SYSTEM, $options->{system_prompt},
135 0 );
136 }
137 0 ▶ push @messages, Praxo::Models::message_text(Praxo::Models::USER, $prompt // '');
Condition0%0/2
$prompt // ""
l!l
00
MC/DC0%0/1
$prompt // ""
$prompt
Truth table0%0/2
A
A= $prompt
Aresult
11
00
138 0 my $usage = Praxo::Models::usage();
139 0 _emit($options, 'run.started', $session->{id}, $run_id);
140 0 my $step = 0;
141 0 my $result;
142 0 my $ok = eval {
143 0 for $step (1 .. $max_steps) {
144 _authorize($options, Praxo::Models::action(
145 kind => 'model.generate', session_id => $session->{id},
146 0 ));
147 0 ▶ if ($options->{context}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"context"}) 0 0 0
148 0 my ($compacted, $context_ok) = $options->{context}->compact(\@messages);
149 0 ▶ Praxo::Errors::praxo_error('AGENT_CONTEXT_BUDGET', 'context budget') unless $context_ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $context_ok 0 0 0
150 0 @messages = @$compacted;
151 }
152 my $request = Praxo::Models::request(
153 messages => \@messages,
154 tools => $options->{tools} ? $options->{tools}->specs() : [],
155 tool_choice => $options->{tool_choice},
156 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$options->{'tools'} ? : 0 0 0
157 my $response = $options->{on_delta} && $options->{model}->can('generate_stream')
158 ? $options->{model}->generate_stream($request, $options->{on_delta})
159 0 ▶ : $options->{model}->generate($request);
Branch: 1 branch
BranchTrueFalseTotal
$options->{'on_delta'} && $options->{'model'}->can('generate_stream') ? : 0 0 0
Condition0%0/3
$options->{"on_delta"} and $options->{"model"}->can("generate_stream")
!ll&&!rl&&r
000
MC/DC0%0/2
$options->{"on_delta"} and $options->{"model"}->can("generate_stream")
$options->{"on_delta"} $options->{"model"}->can("generate_stream")
Truth table0%0/3
A and B
A= $options->{"on_delta"}B= $options->{"model"}->can("generate_stream")
ABresult
0X0
100
111
160 0 ▶ $usage = Praxo::Models::usage_plus($usage, $response->{usage} // {});
Condition0%0/2
$response->{"usage"} // {}
l!l
00
MC/DC0%0/1
$response->{"usage"} // {}
$response->{"usage"}
Truth table0%0/2
A
A= $response->{"usage"}
Aresult
11
00
161 0 ▶ my $total = ($usage->{inputTokens} // 0) + ($usage->{outputTokens} // 0);
Condition0%0/4
$usage->{"inputTokens"} // 0
l!l
00
$usage->{"outputTokens"} // 0
l!l
00
MC/DC0%0/1
$usage->{"inputTokens"} // 0
$usage->{"inputTokens"}
MC/DC0%0/1
$usage->{"outputTokens"} // 0
$usage->{"outputTokens"}
Truth table0%0/2
A
A= $usage->{"inputTokens"}
Aresult
11
00
Truth table0%0/2
A
A= $usage->{"outputTokens"}
Aresult
11
00
162 Praxo::Errors::praxo_error('AGENT_MAX_TOKENS', 'token budget')
163 0 ▶ if ($options->{max_tokens} // 0) > 0 && $total > $options->{max_tokens};
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"max_tokens"} // 0) > 0 and $total > $options->{"max_tokens"} 0 0 0
Condition0%0/5
($options->{"max_tokens"} // 0) > 0 and $total > $options->{"max_tokens"}
!ll&&!rl&&r
000
$options->{"max_tokens"} // 0
l!l
00
MC/DC0%0/2
($options->{"max_tokens"} // 0) > 0 and $total > $options->{"max_tokens"}
$options->{"max_tokens"} $total > $options->{"max_tokens"}
Truth table0%0/3
A and B
A= $options->{"max_tokens"}B= $total > $options->{"max_tokens"}
ABresult
0X0
100
111
164 0 my $message = $response->{message};
165 0 push @messages, $message;
166 0 ▶ my $calls = $message->{toolCalls} // [];
Condition0%0/2
$message->{"toolCalls"} // []
l!l
00
MC/DC0%0/1
$message->{"toolCalls"} // []
$message->{"toolCalls"}
Truth table0%0/2
A
A= $message->{"toolCalls"}
Aresult
11
00
167 0 ▶ if (!@$calls) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$calls) 0 0 0
168 0 _emit($options, 'run.completed', $session->{id}, $run_id);
169 $result = Praxo::Models::run_result(
170 run_id => $run_id,
171 0 ▶ output => $message->{content} // '',
Condition0%0/2
$message->{"content"} // ""
l!l
00
MC/DC0%0/1
$message->{"content"} // ""
$message->{"content"}
Truth table0%0/2
A
A= $message->{"content"}
Aresult
11
00
172 steps => $step,
173 usage => $usage,
174 );
175 0 last;
176 }
177 0 for my $call (@$calls) {
178 0 push @messages, _invoke_tool($options, $call, $run_id, $session->{id});
179 }
180 }
181 0 ▶ if (!$result) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result) 0 0 0
182 0 Praxo::Errors::praxo_error('AGENT_MAX_STEPS', 'maximum steps');
183 }
184 0 1;
185 };
186 0 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
187 0 my $error = $@;
188 0 _emit($options, 'run.failed', $session->{id}, $run_id, {
189 error => "$error",
190 });
191 0 die $error;
192 }
193 0 return $result;
194 }
195  
196 0 ▶sub _invoke_tool {
Subroutine _invoke_tool: not called CC=14 SCAR=53.5
197 0 my ($options, $call, $run_id, $session_id) = @_;
198 0 my $original_name = $call->{name};
199 0 ▶ my $original_arguments = _deep_copy($call->{arguments} // {});
Condition0%0/2
$call->{"arguments"} // {}
l!l
00
MC/DC0%0/1
$call->{"arguments"} // {}
$call->{"arguments"}
Truth table0%0/2
A
A= $call->{"arguments"}
Aresult
11
00
200 0 ▶ Praxo::Errors::praxo_error(
Branch: 1 branch
BranchTrueFalseTotal
unless _tool_allowed($options, $original_name) 0 0 0
201 'AGENT_INVALID_OPTIONS',
202 "agent: tool $original_name is not allowed",
203 ) unless _tool_allowed($options, $original_name);
204 0 _authorize($options, Praxo::Models::action(
205 kind => 'tool.invoke', session_id => $session_id,
206 tool_name => $original_name, arguments => $original_arguments,
207 ));
208 Praxo::Errors::praxo_error('TOOL_NOT_FOUND', 'tool is not registered')
209 0 ▶ unless $options->{tools};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"tools"} 0 0 0
210 Praxo::Errors::praxo_error(
211 'AGENT_INVALID_OPTIONS',
212 "agent: tool $call->{name} is not allowed",
213 0 ▶ ) unless _tool_allowed($options, $call->{name});
Branch: 1 branch
BranchTrueFalseTotal
unless _tool_allowed($options, $call->{"name"}) 0 0 0
214 0 my ($skip, $result) = _apply_interrupt(
215 $options, $call, $run_id, $session_id,
216 );
217 0 ▶ if ($skip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip) 0 0 0
218 return Praxo::Models::message_tool(
219 Praxo::Json::stringify($result // ''),
220 0 ▶ $call->{id} // '',
Condition0%0/4
$result // ""
l!l
00
$call->{"id"} // ""
l!l
00
MC/DC0%0/1
$result // ""
$result
MC/DC0%0/1
$call->{"id"} // ""
$call->{"id"}
Truth table0%0/2
A
A= $result
Aresult
11
00
Truth table0%0/2
A
A= $call->{"id"}
Aresult
11
00
221 );
222 }
223 0 ▶ if ($call->{name} ne $original_name
Branch: 1 branch
BranchTrueFalseTotal
if ($call->{"name"} ne $original_name or not Praxo::Json::equals($call->{"arguments"} // {}, $original_arguments)) 0 0 0
Condition0%0/5
$call->{"name"} ne $original_name or not Praxo::Json::equals($call->{"arguments"} // {}, $original_arguments)
l!l&&r!l&&!r
000
$call->{"arguments"} // {}
l!l
00
MC/DC0%0/2
$call->{"name"} ne $original_name or not Praxo::Json::equals($call->{"arguments"} // {}, $original_arguments)
$call->{"name"} ne $original_name not Praxo::Json::equals($call->{"arguments"} // {}, $original_arguments)
MC/DC0%0/1
$call->{"arguments"} // {}
$call->{"arguments"}
Truth table0%0/3
A or not(B)
A= $call->{"name"} ne $original_nameB= not Praxo::Json::equals($call->{"arguments"} // {}, $original_arguments)
ABresult
1X1
011
000
Truth table0%0/2
A
A= $call->{"arguments"}
Aresult
11
00
224 || !Praxo::Json::equals($call->{arguments} // {}, $original_arguments)) {
225 _authorize($options, Praxo::Models::action(
226 kind => 'tool.invoke', session_id => $session_id,
227 tool_name => $call->{name}, arguments => $call->{arguments},
228 0 ));
229 }
230 0 my $tool = $options->{tools}->get($call->{name});
231 _emit($options, 'tool.call', $session_id, $run_id, {
232 name => $call->{name}, arguments => $call->{arguments} // {},
233 0 ▶ });
Condition0%0/2
$call->{"arguments"} // {}
l!l
00
MC/DC0%0/1
$call->{"arguments"} // {}
$call->{"arguments"}
Truth table0%0/2
A
A= $call->{"arguments"}
Aresult
11
00
234 0 ▶ my $value = $tool->invoke($call->{arguments} // {});
Condition0%0/2
$call->{"arguments"} // {}
l!l
00
MC/DC0%0/1
$call->{"arguments"} // {}
$call->{"arguments"}
Truth table0%0/2
A
A= $call->{"arguments"}
Aresult
11
00
235 return Praxo::Models::message_tool(
236 Praxo::Json::stringify($value),
237 0 ▶ $call->{id} // '',
Condition0%0/2
$call->{"id"} // ""
l!l
00
MC/DC0%0/1
$call->{"id"} // ""
$call->{"id"}
Truth table0%0/2
A
A= $call->{"id"}
Aresult
11
00
238 );
239 }
240  
241 0 ▶sub _apply_interrupt {
Subroutine _apply_interrupt: not called CC=16 SCAR=56.1
242 0 my ($options, $call, $run_id, $session_id) = @_;
243 0 ▶ return (0, undef) unless _interrupt_on($options, $call->{name});
Branch: 1 branch
BranchTrueFalseTotal
unless _interrupt_on($options, $call->{"name"}) 0 0 0
244 0 my $handler = $options->{on_interrupt_decision};
245 0 my $approval = $options->{on_interrupt};
246 Praxo::Errors::praxo_error(
247 'AGENT_INTERRUPT_UNHANDLED',
248 'agent: approval handler not configured: ' . $call->{name},
249 0 ▶ ) unless $handler || $approval;
Branch: 1 branch
BranchTrueFalseTotal
unless $handler or $approval 0 0 0
Condition0%0/3
$handler or $approval
l!l&&r!l&&!r
000
MC/DC0%0/2
$handler or $approval
$handler $approval
Truth table0%0/3
A or B
A= $handlerB= $approval
ABresult
1X1
011
000
250 _emit($options, 'tool.interrupt', $session_id, $run_id, {
251 name => $call->{name},
252 0 ▶ arguments => _deep_copy($call->{arguments} // {}),
Condition0%0/2
$call->{"arguments"} // {}
l!l
00
MC/DC0%0/1
$call->{"arguments"} // {}
$call->{"arguments"}
Truth table0%0/2
A
A= $call->{"arguments"}
Aresult
11
00
253 });
254 0 my $interrupt = Praxo::Models::interrupt(
255 run_id => $run_id,
256 session_id => $session_id,
257 call => $call,
258 );
259 0 ▶ if ($handler) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler) 0 0 0
260 0 my $decision = $handler->($interrupt);
261 0 ▶ Praxo::Errors::praxo_error(
Branch: 1 branch
BranchTrueFalseTotal
unless ref $decision eq "HASH" 0 0 0
262 'AGENT_INTERRUPT_DECISION_INVALID',
263 'agent: invalid interrupt decision',
264 ) unless ref($decision) eq 'HASH';
265 0 ▶ my $action = $decision->{action} // '';
Condition0%0/2
$decision->{"action"} // ""
l!l
00
MC/DC0%0/1
$decision->{"action"} // ""
$decision->{"action"}
Truth table0%0/2
A
A= $decision->{"action"}
Aresult
11
00
266 0 ▶ if ($action eq Praxo::Models::INTERRUPT_APPROVE()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "approve") 0 0 0
267 0 return (0, undef);
268 }
269 0 ▶ if ($action eq Praxo::Models::INTERRUPT_EDIT()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "edit") 0 0 0
270 Praxo::Errors::praxo_error(
271 'AGENT_INTERRUPT_DECISION_INVALID',
272 'agent: edit requires arguments',
273 0 ▶ ) unless defined $decision->{arguments};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $decision->{"arguments"} 0 0 0
274 0 $call->{arguments} = _deep_copy($decision->{arguments});
275 0 return (0, undef);
276 }
277 0 ▶ if ($action eq Praxo::Models::INTERRUPT_REJECT()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "reject") 0 0 0
278 Praxo::Errors::praxo_error(
279 'AGENT_APPROVAL_DENIED',
280 'agent: tool call denied by approval: ' . $call->{name}
281 0 ▶ . ': ' . ($decision->{reason} // ''),
Condition0%0/2
$decision->{"reason"} // ""
l!l
00
MC/DC0%0/1
$decision->{"reason"} // ""
$decision->{"reason"}
Truth table0%0/2
A
A= $decision->{"reason"}
Aresult
11
00
282 );
283 }
284 0 ▶ if ($action eq Praxo::Models::INTERRUPT_RESPOND()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "respond") 0 0 0
285 0 ▶ return (1, $decision->{response} // '');
Condition0%0/2
$decision->{"response"} // ""
l!l
00
MC/DC0%0/1
$decision->{"response"} // ""
$decision->{"response"}
Truth table0%0/2
A
A= $decision->{"response"}
Aresult
11
00
286 }
287 Praxo::Errors::praxo_error(
288 0 'AGENT_INTERRUPT_DECISION_INVALID',
289 'agent: invalid interrupt decision: ' . $action,
290 );
291 }
292 0 my $approved = $approval->($interrupt);
293 Praxo::Errors::praxo_error(
294 'AGENT_APPROVAL_DENIED',
295 'agent: tool call denied by approval: ' . $call->{name},
296 0 ▶ ) unless $approved;
Branch: 1 branch
BranchTrueFalseTotal
unless $approved 0 0 0
297 0 return (0, undef);
298 }
299  
300 0 ▶sub _tool_allowed {
Subroutine _tool_allowed: not called CC=4 SCAR=30.0
301 0 my ($options, $name) = @_;
302 0 ▶ my $allowed = $options->{allowed_tools} // [];
Condition0%0/2
$options->{"allowed_tools"} // []
l!l
00
MC/DC0%0/1
$options->{"allowed_tools"} // []
$options->{"allowed_tools"}
Truth table0%0/2
A
A= $options->{"allowed_tools"}
Aresult
11
00
303 0 ▶ return 1 unless ref($allowed) eq 'ARRAY' && @$allowed;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $allowed eq "ARRAY" and @$allowed 0 0 0
Condition0%0/3
ref $allowed eq "ARRAY" and @$allowed
!ll&&!rl&&r
000
MC/DC0%0/2
ref $allowed eq "ARRAY" and @$allowed
ref $allowed eq "ARRAY" @$allowed
Truth table0%0/3
A and B
A= ref $allowed eq "ARRAY"B= @$allowed
ABresult
0X0
100
111
304 0 return scalar grep { $_ eq $name } @$allowed;
305 }
306  
307 0 ▶sub _interrupt_on {
Subroutine _interrupt_on: not called CC=7 SCAR=40.3
308 0 my ($options, $name) = @_;
309 0 my $on = $options->{interrupt_on};
310 0 ▶ return 0 unless defined $on;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $on 0 0 0
311 0 ▶ return exists $on->{$name} ? 1 : 0 if ref($on) eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
if ref $on eq "HASH" 0 0 0
exists $on->{$name} ? : 0 0 0
312 0 ▶ return scalar grep { $_ eq $name } @$on if ref($on) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $on eq "ARRAY" 0 0 0
313 0 ▶ return $on eq $name ? 1 : 0 unless ref($on);
Branch: 2 branches
BranchTrueFalseTotal
unless ref $on 0 0 0
$on eq $name ? : 0 0 0
314 0 return 0;
315 }
316  
317 0 ▶sub _deep_copy {
Subroutine _deep_copy: not called CC=2 SCAR=17.9
318 0 my ($value) = @_;
319 0 ▶ return undef unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
320 0 return Praxo::Json::parse(Praxo::Json::stringify($value));
321 }
322  
323 0 ▶sub _authorize {
Subroutine _authorize: not called CC=4 SCAR=30.0
324 0 my ($options, $action) = @_;
325 0 ▶ return unless $options->{policy};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"policy"} 0 0 0
326 0 my $decision = $options->{policy}->($action);
327 Praxo::Errors::praxo_error('POLICY_ERROR', 'policy denied the action')
328 0 ▶ unless ref($decision) eq 'HASH' && $decision->{allowed};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $decision eq "HASH" and $decision->{"allowed"} 0 0 0
Condition0%0/3
ref $decision eq "HASH" and $decision->{"allowed"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $decision eq "HASH" and $decision->{"allowed"}
ref $decision eq "HASH" $decision->{"allowed"}
Truth table0%0/3
A and B
A= ref $decision eq "HASH"B= $decision->{"allowed"}
ABresult
0X0
100
111
329 }
330  
331 0 ▶sub _emit {
Subroutine _emit: not called CC=2 SCAR=17.9
332 0 my ($options, $type, $session_id, $run_id, $data) = @_;
333 0 ▶ return unless $options->{events};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"events"} 0 0 0
334 0 $options->{events}->emit(Praxo::Models::event(
335 type => $type, session_id => $session_id, run_id => $run_id, data => $data,
336 ));
337 }
338  
339 package Praxo::Agent;
340  
341 0 ▶sub run_agent {
Subroutine run_agent: not called CC=1 SCAR=6.9
Pod undocumented
342 0 my ($options, $session, $prompt) = @_;
343 0 return Praxo::Agent::Agent->new($options)->run($session, $prompt);
344 }
345  
346 1 1;
« Plugin.pm ↑ Summary Adapters/OpenAICompatible.pm »