blib/lib/Langertha/Role/ServerTools.pm

filter: Statementstmt 100% 12 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 16 / 16 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
__ANON__
1.0
CRAP 1.0
« blib/lib/Langertha/Role/Runnable.pm ↑ Summary blib/lib/Langertha/Role/SystemPrompt.pm »
1 package Langertha::Role::ServerTools;
2 # ABSTRACT: Role for an engine whose wire accepts provider-native server-side tools
3 28 our $VERSION = '0.503';
4 28 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 28 ▶use Langertha::ServerTool;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 has server_tools => (
9 is => 'ro',
10 isa => 'ArrayRef',
11 278 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
12 28 );
13  
14  
15 47 ▶sub _server_tool_wire_check {
Subroutine _server_tool_wire_check: called CC=1 SCAR=0.0
16 47 my ( $self, $server_tool ) = @_;
17 47 return $server_tool->to( $server_tool->wire );
18 }
19  
20  
21  
22 28 1;
23  
24 __END__
25  
26 =pod
27  
28 =encoding UTF-8
29  
30 =head1 NAME
31  
32 Langertha::Role::ServerTools - Role for an engine whose wire accepts provider-native server-side tools
33  
34 =head1 VERSION
35  
36 version 0.503
37  
38 =head1 SYNOPSIS
39  
40 my $engine = Langertha::Engine::OpenAIResponses->new(
41 api_key => $ENV{OPENAI_API_KEY},
42 model => 'gpt-5.6-luna',
43 server_tools => [ { type => 'web_search' } ], # sent on every request
44 );
45  
46 say 'server tools ok' if $engine->supports('server_tools');
47  
48 =head1 DESCRIPTION
49  
50 Marks an engine whose wire takes provider-native server-side tool entries in
51 C<tools> -- tools the provider runs itself, such as C<web_search> -- and
52 contributes the C<server_tools> capability flag (ADR 0002). The flag says
53 I<that> the wire accepts them, not I<which> types a given model honors.
54  
55 The role holds the per-engine default list (L</server_tools>) and the
56 L</_server_tool_wire_check> hook. The wire envelope that consumes the engine
57 (L<Langertha::Role::ResponsesCompatible>) appends the defaults to every
58 request, so C<simple_chat>, C<chat_f> and C<chat_with_tools_f> all send them.
59 It does not require L<Langertha::Role::Tools>.
60  
61 Server-side calls come back on L<Langertha::Response/server_tool_calls>; see
62 L<Langertha::ServerTool> and ADR 0030.
63  
64 =head2 server_tools
65  
66 server_tools => [ { type => 'web_search' }, $server_tool_object ]
67  
68 Server-side tools sent with every chat request of this engine, after any
69 C<tools> of the request itself. Each entry is a L<Langertha::ServerTool> or a
70 provider-native hash that L<Langertha::ServerTool/from_hash> recognises for
71 the engine's wire; anything else (a bare string such as C<'web_search'>, a
72 function tool, a type Langertha does not list) croaks when the request is
73 built. Wrap an unlisted type as
74 C<< Langertha::ServerTool->new( wire => ..., spec => ..., unlisted => 1 ) >>.
75  
76 B<The request wins.> A default is left out when the request's own C<tools>
77 already carry a server tool of the same kind: the same C<type>, and for
78 C<mcp> the same C<server_label> as well. So a per-request
79 C<< { type => 'web_search', search_context_size => 'high' } >> replaces a
80 default C<web_search> instead of sending it twice. The kind is the C<type>
81 only, not the tool's target: a request C<file_search> over other
82 C<vector_store_ids> also replaces a default C<file_search>, so pass both
83 stores in the request when both should be searched.
84  
85 Defaults to an empty ArrayRef.
86  
87 =head2 _server_tool_wire_check
88  
89 my $spec = $engine->_server_tool_wire_check($server_tool);
90  
91 Engine hook, called once per L<Langertha::ServerTool> while a request is
92 built. Returns the native hash to send; may croak or rewrite it where the
93 provider diverges from the shared wire. The default returns the tool's native
94 hash unchanged. It runs after L<Langertha::ServerTool/to>, which already
95 refuses a remote C<mcp> tool without C<< require_approval => 'never' >>.
96  
97 =head1 SEE ALSO
98  
99 =over
100  
101 =item * L<Langertha::ServerTool>
102  
103 =item * L<Langertha::ServerToolCall>
104  
105 =item * L<Langertha::Role::Capabilities> - the C<server_tools> flag
106  
107 =back
108  
109 =head1 SUPPORT
110  
111 =head2 Issues
112  
113 Please report bugs and feature requests on GitHub at
114 L<https://github.com/Getty/langertha/issues>.
115  
116 =head2 IRC
117  
118 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
119  
120 =head1 CONTRIBUTING
121  
122 Contributions are welcome! Please fork the repository and submit a pull request.
123  
124 =head1 AUTHOR
125  
126 Torsten Raudssus <getty@cpan.org>
127  
128 =head1 COPYRIGHT AND LICENSE
129  
130 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
131  
132 This is free software; you can redistribute it and/or modify it under
133 the same terms as the Perl 5 programming language system itself.
134  
135 =cut
« blib/lib/Langertha/Role/Runnable.pm ↑ Summary blib/lib/Langertha/Role/SystemPrompt.pm »