NAME
Langertha::Role::Tools - Role for MCP tool calling support
VERSION
version 0.100
SYNOPSIS
use IO::Async::Loop;
use Net::Async::MCP;
use Future::AsyncAwait;
my $loop = IO::Async::Loop->new;
# Set up an MCP server with tools
my $mcp = Net::Async::MCP->new(server => $my_mcp_server);
$loop->add($mcp);
await $mcp->initialize;
# Create engine with MCP servers
my $engine = Langertha::Engine::Anthropic->new(
api_key => $ENV{ANTHROPIC_API_KEY},
model => 'claude-sonnet-4-5-20250929',
mcp_servers => [$mcp],
);
# Async tool-calling chat loop
my $response = await $engine->chat_with_tools_f(
'Use the available tools to answer my question'
);
DESCRIPTION
This role adds MCP (Model Context Protocol) tool calling support to Langertha engines. It provides the chat_with_tools_f method which implements the full async tool-calling loop:
- 1. Gather available tools from all configured MCP servers
- 2. Send chat request with tool definitions to the LLM
- 3. If the LLM returns tool calls, execute them via MCP
- 4. Feed tool results back to the LLM and repeat
- 5. When the LLM returns final text, return it
Engines that compose this role must implement four methods to handle the engine-specific tool format conversion. See "REQUIRED METHODS".
REQUIRED METHODS
Engines composing this role must implement:
format_tools(\@mcp_tools)-
Convert MCP tool definitions to the engine's native tool format.
response_tool_calls(\%response_data)-
Extract tool call objects from a parsed LLM response.
format_tool_results(\%response_data, \@results)-
Format tool execution results as messages to append to the conversation.
response_text_content(\%response_data)-
Extract the final text content from a parsed LLM response.
mcp_servers
mcp_servers => [$mcp1, $mcp2]
ArrayRef of Net::Async::MCP instances to use as tool providers.
tool_max_iterations
tool_max_iterations => 20
Maximum number of tool-calling round trips before aborting. Defaults to 10.
chat_with_tools_f
my $response = await $engine->chat_with_tools_f(@messages);
Async tool-calling chat loop. Accepts the same message arguments as simple_chat. Returns a Future that resolves to the final text response after all tool calls have been executed.
SEE ALSO
SUPPORT
Issues
Please report bugs and feature requests on GitHub at https://github.com/Getty/langertha/issues.
CONTRIBUTING
Contributions are welcome! Please fork the repository and submit a pull request.
AUTHOR
Torsten Raudssus <torsten@raudssus.de> https://raudss.us/
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by Torsten Raudssus.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.