blib/lib/SignalWire/Agents/Prefabs/InfoGatherer.pm

filter: Statementstmt 96.8% 31 / 32 Branchbran 100% 4 / 4 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 1 totaltotal 89.5% 43 / 48 CC 4 SCAR 5.6
CC
4
Cov
95%
BUILD
3.0
__ANON__
2.0
__ANON__
1.1
CRAP 1.7
« blib/lib/SignalWire/Agents/Skills/Builtin/Datetime.pm ↑ Summary blib/lib/SignalWire/Agents/Skills/SkillBase.pm »
1 package SignalWire::Agents::Prefabs::InfoGatherer;
2 # Copyright (c) 2025 SignalWire
3 # Licensed under the MIT License.
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use JSON qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 extends 'SignalWire::Agents::Agent::AgentBase';
10  
11 0 ▶has questions => (is => 'ro', default => sub { [] });
Subroutine __ANON__: not called CC=1 SCAR=1.2
12  
13 13 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.0
Pod undocumented
14 13 my ($self, $args) = @_;
15  
16 # Set defaults
17 13 ▶ $self->name('info_gatherer') if $self->name eq 'agent';
Branch: 1 branch
BranchTrueFalseTotal
if $self->name eq "agent" 12 1 13
18 13 ▶ $self->route('/info_gatherer') if $self->route eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if $self->route eq "/" 12 1 13
19 13 $self->use_pom(1);
20  
21 13 my $questions = $self->questions;
22  
23 # Set global data
24 13 $self->set_global_data({
25 questions => $questions,
26 question_index => 0,
27 answers => [],
28 });
29  
30 # Build prompt
31 13 $self->prompt_add_section(
32 'Information Gathering',
33 'You are an information-gathering assistant. Your job is to ask the user a series of questions and collect their answers.',
34 bullets => [
35 'Ask questions one at a time in order',
36 'Wait for the user to answer before asking the next question',
37 'Confirm answers when the question requires confirmation',
38 'Use start_questions to begin and submit_answer for each response',
39 ],
40 );
41  
42 # Register tools
43 $self->define_tool(
44 name => 'start_questions',
45 description => 'Start the question-gathering process and return the first question',
46 parameters => { type => 'object', properties => {} },
47 2 ▶ handler => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
48 2 my ($a, $raw) = @_;
49 2 require SignalWire::Agents::SWAIG::FunctionResult;
50 2 ▶ my $first = $questions->[0]{question_text} // 'No questions configured';
Condition50%1/2
$questions->[0]{"question_text"} // "No questions configured"
l!l
20
MC/DC0%0/1
$questions->[0]{"question_text"} // "No questions configured"
$questions->[0]{"question_text"}
Truth table50%1/2
A
A= $questions->[0]{"question_text"}
Aresult
11
00
51 2 return SignalWire::Agents::SWAIG::FunctionResult->new(response => $first);
52 },
53 13 );
54  
55 $self->define_tool(
56 name => 'submit_answer',
57 description => 'Submit an answer to the current question',
58 parameters => {
59 type => 'object',
60 properties => {
61 answer => { type => 'string', description => 'The answer' },
62 confirmed_by_user => { type => 'boolean', description => 'User confirmed this answer' },
63 },
64 required => ['answer'],
65 },
66 2 ▶ handler => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
67 2 my ($a, $raw) = @_;
68 2 require SignalWire::Agents::SWAIG::FunctionResult;
69 2 return SignalWire::Agents::SWAIG::FunctionResult->new(
70 response => "Answer recorded: $a->{answer}",
71 );
72 },
73 13 );
74 }
75  
76 2 1;
« blib/lib/SignalWire/Agents/Skills/Builtin/Datetime.pm ↑ Summary blib/lib/SignalWire/Agents/Skills/SkillBase.pm »