Agent.pm

filter: Statementstmt 11.9% 20 / 167 Branchbran 0.0% 0 / 88 Conditioncond 0.0% 0 / 76 MC/DCmcdc 0.0% 0 / 41 Subroutinesub 22.2% 6 / 27 Podpod 0.0% 0 / 1 totaltotal 6.5% 26 / 400 CC 81 SCAR 52.9
CC
81
Cov
6%
run
552.0
_apply_interrupt
272.0
_invoke_tool
210.0
CRAP 199.1
« Plugin.pm ↑ Summary JsonSchema.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 require_policy => 0,
89 require_tool_scope => 0,
90 interrupt_on => [],
91 on_interrupt_decision => undef,
92 on_interrupt => undef,
93 }, $class;
94 }
95  
96 package Praxo::Agent::StaticModel;
97  
98 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
99 0 my ($class, $content) = @_;
100 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
101 }
102  
103 0 ▶sub generate {
Subroutine generate: not called CC=1 SCAR=6.9
104 0 my ($self, $request) = @_;
105 return Praxo::Models::response(
106 0 message => Praxo::Models::message_assistant($self->{content}),
107 );
108 }
109  
110 package Praxo::Agent::Agent;
111  
112 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
113 0 my ($class, $options) = @_;
114 Praxo::Errors::praxo_error(
115 'AGENT_INVALID_OPTIONS',
116 'agent: require policy: policy is required',
117 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
118 Praxo::Errors::praxo_error(
119 'AGENT_INVALID_OPTIONS',
120 'agent: require tool scope: allowed_tools must not be empty',
121 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
122 0 return bless { options => $options }, $class;
123 }
124  
125 0 ▶sub run {
Subroutine run: not called CC=23 SCAR=63.1
126 0 my ($self, $session, $prompt) = @_;
127 0 my $options = $self->{options};
128 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
129 0 my $run_id = 'run-' . int(time() * 1000);
130 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
131 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
132 unshift @messages, Praxo::Models::message_text(
133 Praxo::Models::SYSTEM, $options->{system_prompt},
134 0 );
135 }
136 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
137 0 my $usage = Praxo::Models::usage();
138 0 _emit($options, 'run.started', $session->{id}, $run_id);
139 0 my $step = 0;
140 0 my $result;
141 0 my $ok = eval {
142 0 for $step (1 .. $max_steps) {
143 _authorize($options, Praxo::Models::action(
144 kind => 'model.generate', session_id => $session->{id},
145 0 ));
146 0 ▶ if ($options->{context}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"context"}) 0 0 0
147 0 my ($compacted, $context_ok) = $options->{context}->compact(\@messages);
148 0 ▶ Praxo::Errors::praxo_error('AGENT_CONTEXT_BUDGET', 'context budget') unless $context_ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $context_ok 0 0 0
149 0 @messages = @$compacted;
150 }
151 my $request = Praxo::Models::request(
152 messages => \@messages,
153 tools => $options->{tools} ? $options->{tools}->specs() : [],
154 tool_choice => $options->{tool_choice},
155 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$options->{'tools'} ? : 0 0 0
156 0 my $response = $options->{model}->generate($request);
157 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
158 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
159 Praxo::Errors::praxo_error('AGENT_MAX_TOKENS', 'token budget')
160 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
161 0 my $message = $response->{message};
162 0 push @messages, $message;
163 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
164 0 ▶ if (!@$calls) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$calls) 0 0 0
165 0 _emit($options, 'run.completed', $session->{id}, $run_id);
166 $result = Praxo::Models::run_result(
167 run_id => $run_id,
168 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
169 steps => $step,
170 usage => $usage,
171 );
172 0 last;
173 }
174 0 for my $call (@$calls) {
175 0 push @messages, _invoke_tool($options, $call, $run_id, $session->{id});
176 }
177 }
178 0 ▶ if (!$result) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result) 0 0 0
179 0 Praxo::Errors::praxo_error('AGENT_MAX_STEPS', 'maximum steps');
180 }
181 0 1;
182 };
183 0 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
184 0 my $error = $@;
185 0 _emit($options, 'run.failed', $session->{id}, $run_id, {
186 error => "$error",
187 });
188 0 die $error;
189 }
190 0 return $result;
191 }
192  
193 0 ▶sub _invoke_tool {
Subroutine _invoke_tool: not called CC=14 SCAR=53.5
194 0 my ($options, $call, $run_id, $session_id) = @_;
195 0 my $original_name = $call->{name};
196 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
197 0 ▶ Praxo::Errors::praxo_error(
Branch: 1 branch
BranchTrueFalseTotal
unless _tool_allowed($options, $original_name) 0 0 0
198 'AGENT_INVALID_OPTIONS',
199 "agent: tool $original_name is not allowed",
200 ) unless _tool_allowed($options, $original_name);
201 0 _authorize($options, Praxo::Models::action(
202 kind => 'tool.invoke', session_id => $session_id,
203 tool_name => $original_name, arguments => $original_arguments,
204 ));
205 Praxo::Errors::praxo_error('TOOL_NOT_FOUND', 'tool is not registered')
206 0 ▶ unless $options->{tools};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"tools"} 0 0 0
207 Praxo::Errors::praxo_error(
208 'AGENT_INVALID_OPTIONS',
209 "agent: tool $call->{name} is not allowed",
210 0 ▶ ) unless _tool_allowed($options, $call->{name});
Branch: 1 branch
BranchTrueFalseTotal
unless _tool_allowed($options, $call->{"name"}) 0 0 0
211 0 my ($skip, $result) = _apply_interrupt(
212 $options, $call, $run_id, $session_id,
213 );
214 0 ▶ if ($skip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip) 0 0 0
215 return Praxo::Models::message_tool(
216 Praxo::Json::stringify($result // ''),
217 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
218 );
219 }
220 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
221 || !Praxo::Json::equals($call->{arguments} // {}, $original_arguments)) {
222 _authorize($options, Praxo::Models::action(
223 kind => 'tool.invoke', session_id => $session_id,
224 tool_name => $call->{name}, arguments => $call->{arguments},
225 0 ));
226 }
227 0 my $tool = $options->{tools}->get($call->{name});
228 _emit($options, 'tool.call', $session_id, $run_id, {
229 name => $call->{name}, arguments => $call->{arguments} // {},
230 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
231 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
232 return Praxo::Models::message_tool(
233 Praxo::Json::stringify($value),
234 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
235 );
236 }
237  
238 0 ▶sub _apply_interrupt {
Subroutine _apply_interrupt: not called CC=16 SCAR=56.1
239 0 my ($options, $call, $run_id, $session_id) = @_;
240 0 ▶ return (0, undef) unless _interrupt_on($options, $call->{name});
Branch: 1 branch
BranchTrueFalseTotal
unless _interrupt_on($options, $call->{"name"}) 0 0 0
241 0 my $handler = $options->{on_interrupt_decision};
242 0 my $approval = $options->{on_interrupt};
243 Praxo::Errors::praxo_error(
244 'AGENT_INTERRUPT_UNHANDLED',
245 'agent: approval handler not configured: ' . $call->{name},
246 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
247 _emit($options, 'tool.interrupt', $session_id, $run_id, {
248 name => $call->{name},
249 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
250 });
251 0 my $interrupt = Praxo::Models::interrupt(
252 run_id => $run_id,
253 session_id => $session_id,
254 call => $call,
255 );
256 0 ▶ if ($handler) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler) 0 0 0
257 0 my $decision = $handler->($interrupt);
258 0 ▶ Praxo::Errors::praxo_error(
Branch: 1 branch
BranchTrueFalseTotal
unless ref $decision eq "HASH" 0 0 0
259 'AGENT_INTERRUPT_DECISION_INVALID',
260 'agent: invalid interrupt decision',
261 ) unless ref($decision) eq 'HASH';
262 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
263 0 ▶ if ($action eq Praxo::Models::INTERRUPT_APPROVE()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "approve") 0 0 0
264 0 return (0, undef);
265 }
266 0 ▶ if ($action eq Praxo::Models::INTERRUPT_EDIT()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "edit") 0 0 0
267 Praxo::Errors::praxo_error(
268 'AGENT_INTERRUPT_DECISION_INVALID',
269 'agent: edit requires arguments',
270 0 ▶ ) unless defined $decision->{arguments};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $decision->{"arguments"} 0 0 0
271 0 $call->{arguments} = _deep_copy($decision->{arguments});
272 0 return (0, undef);
273 }
274 0 ▶ if ($action eq Praxo::Models::INTERRUPT_REJECT()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "reject") 0 0 0
275 Praxo::Errors::praxo_error(
276 'AGENT_APPROVAL_DENIED',
277 'agent: tool call denied by approval: ' . $call->{name}
278 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
279 );
280 }
281 0 ▶ if ($action eq Praxo::Models::INTERRUPT_RESPOND()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "respond") 0 0 0
282 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
283 }
284 Praxo::Errors::praxo_error(
285 0 'AGENT_INTERRUPT_DECISION_INVALID',
286 'agent: invalid interrupt decision: ' . $action,
287 );
288 }
289 0 my $approved = $approval->($interrupt);
290 Praxo::Errors::praxo_error(
291 'AGENT_APPROVAL_DENIED',
292 'agent: tool call denied by approval: ' . $call->{name},
293 0 ▶ ) unless $approved;
Branch: 1 branch
BranchTrueFalseTotal
unless $approved 0 0 0
294 0 return (0, undef);
295 }
296  
297 0 ▶sub _tool_allowed {
Subroutine _tool_allowed: not called CC=4 SCAR=30.0
298 0 my ($options, $name) = @_;
299 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
300 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
301 0 return scalar grep { $_ eq $name } @$allowed;
302 }
303  
304 0 ▶sub _interrupt_on {
Subroutine _interrupt_on: not called CC=7 SCAR=40.3
305 0 my ($options, $name) = @_;
306 0 my $on = $options->{interrupt_on};
307 0 ▶ return 0 unless defined $on;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $on 0 0 0
308 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
309 0 ▶ return scalar grep { $_ eq $name } @$on if ref($on) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $on eq "ARRAY" 0 0 0
310 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
311 0 return 0;
312 }
313  
314 0 ▶sub _deep_copy {
Subroutine _deep_copy: not called CC=2 SCAR=17.9
315 0 my ($value) = @_;
316 0 ▶ return undef unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
317 0 return Praxo::Json::parse(Praxo::Json::stringify($value));
318 }
319  
320 0 ▶sub _authorize {
Subroutine _authorize: not called CC=4 SCAR=30.0
321 0 my ($options, $action) = @_;
322 0 ▶ return unless $options->{policy};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"policy"} 0 0 0
323 0 my $decision = $options->{policy}->($action);
324 Praxo::Errors::praxo_error('POLICY_ERROR', 'policy denied the action')
325 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
326 }
327  
328 0 ▶sub _emit {
Subroutine _emit: not called CC=2 SCAR=17.9
329 0 my ($options, $type, $session_id, $run_id, $data) = @_;
330 0 ▶ return unless $options->{events};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"events"} 0 0 0
331 0 $options->{events}->emit(Praxo::Models::event(
332 type => $type, session_id => $session_id, run_id => $run_id, data => $data,
333 ));
334 }
335  
336 package Praxo::Agent;
337  
338 0 ▶sub run_agent {
Subroutine run_agent: not called CC=1 SCAR=6.9
Pod undocumented
339 0 my ($options, $session, $prompt) = @_;
340 0 return Praxo::Agent::Agent->new($options)->run($session, $prompt);
341 }
342  
343 1 1;
« Plugin.pm ↑ Summary JsonSchema.pm »