« blib/lib/SignalWire/Agents/Prefabs/InfoGatherer.pm
↑ Summary
blib/lib/SignalWire/Agents/Skills/Builtin/NativeVectorSearch.pm »
| 1 | package SignalWire::Agents::Skills::SkillBase; | ||||||||||
| 2 | # Copyright (c) 2025 SignalWire | ||||||||||
| 3 | # Licensed under the MIT License. | ||||||||||
| 4 | |||||||||||
| 5 | 19 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 19 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 19 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 19 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | # Required class-level constants (subclasses override via 'has' or '+') | ||||||||||
| 11 | 19 | has skill_name => (is => 'ro', required => 1); | |||||||||
| 12 | 19 | has skill_description => (is => 'ro', required => 1); | |||||||||
| 13 | 124 | ▶ | has skill_version => (is => 'ro', default => sub { '1.0.0' }); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | has supports_multiple_instances => (is => 'ro', default => sub { 0 }); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 16 | 131 | ▶ | has required_packages => (is => 'ro', default => sub { [] }); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 131 | ▶ | has required_env_vars => (is => 'ro', default => sub { [] }); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | # The agent this skill is attached to | ||||||||||
| 20 | 19 | has agent => (is => 'ro', required => 1, weak_ref => 1); | |||||||||
| 21 | # Config params passed at registration | ||||||||||
| 22 | 0 | ▶ | has params => (is => 'rw', default => sub { {} }); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 23 | |||||||||||
| 24 | # Extra SWAIG fields to merge into tool definitions | ||||||||||
| 25 | 131 | ▶ | has swaig_fields => (is => 'rw', default => sub { {} }); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 26 | |||||||||||
| 27 | 131 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 28 | 131 | my ($self) = @_; | |||||||||
| 29 | # Extract swaig_fields from params if present | ||||||||||
| 30 | 131 | ▶ | if (exists $self->params->{swaig_fields}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 1 | $self->swaig_fields(delete $self->params->{swaig_fields}); | |||||||||
| 32 | } | ||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | # --- Abstract interface (subclasses must override) --- | ||||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | sub setup { | ||||||||
|
Subroutine
setup: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 38 | 0 | my ($self) = @_; | |||||||||
| 39 | 0 | croak(ref($self) . " must implement setup()"); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | sub register_tools { | ||||||||
|
Subroutine
register_tools: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 43 | 0 | my ($self) = @_; | |||||||||
| 44 | 0 | croak(ref($self) . " must implement register_tools()"); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | # --- Default implementations --- | ||||||||||
| 48 | |||||||||||
| 49 | 66 | ▶ | sub define_tool { | ||||||||
|
Subroutine
define_tool: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 50 | 66 | my ($self, %opts) = @_; | |||||||||
| 51 | # Merge swaig_fields into the tool definition | ||||||||||
| 52 | 66 | my %merged = (%{ $self->swaig_fields }, %opts); | |||||||||
| 53 | 66 | return $self->agent->define_tool(%merged); | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 9 | ▶ | sub get_hints { | ||||||||
|
Subroutine
get_hints: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 57 | 9 | return []; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 10 | ▶ | sub get_global_data { | ||||||||
|
Subroutine
get_global_data: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 61 | 10 | return {}; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 23 | ▶ | sub get_prompt_sections { | ||||||||
|
Subroutine
get_prompt_sections: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 65 | 23 | my ($self) = @_; | |||||||||
| 66 | 23 | ▶ | return [] if $self->params->{skip_prompt}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 21 | return $self->_get_prompt_sections; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 2 | ▶ | sub _get_prompt_sections { | ||||||||
|
Subroutine
_get_prompt_sections: called CC=1 SCAR=0.0
| |||||||||||
| 71 | 2 | return []; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 1 | ▶ | sub cleanup { | ||||||||
|
Subroutine
cleanup: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 75 | # no-op by default | ||||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 10 | ▶ | sub validate_env_vars { | ||||||||
|
Subroutine
validate_env_vars: called CC=3 SCAR=13.1
Pod
undocumented
| |||||||||||
| 79 | 10 | my ($self) = @_; | |||||||||
| 80 | 10 | for my $var (@{ $self->required_env_vars }) { | |||||||||
| 81 | 0 | ▶ | return 0 unless $ENV{$var}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | } | ||||||||||
| 83 | 10 | return 1; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 15 | ▶ | sub get_parameter_schema { | ||||||||
|
Subroutine
get_parameter_schema: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 87 | return { | ||||||||||
| 88 | 15 | swaig_fields => { type => 'object', description => 'Additional SWAIG fields' }, | |||||||||
| 89 | skip_prompt => { type => 'boolean', description => 'Skip injecting prompt sections', default => 0 }, | ||||||||||
| 90 | tool_name => { type => 'string', description => 'Override the default tool name' }, | ||||||||||
| 91 | }; | ||||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 14 | ▶ | sub get_instance_key { | ||||||||
|
Subroutine
get_instance_key: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 95 | 14 | my ($self) = @_; | |||||||||
| 96 | 14 | my $base = $self->skill_name; | |||||||||
| 97 | 14 | ▶ | if ($self->params->{tool_name}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 4 | return $base . ':' . $self->params->{tool_name}; | |||||||||
| 99 | } | ||||||||||
| 100 | 10 | return $base; | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | 19 | 1; | |||||||||