NAME

Langertha::Role::HermesTools - Hermes-style tool calling via XML tags

VERSION

version 0.304

SYNOPSIS

package Langertha::Engine::MyEngine;
use Moose;
extends 'Langertha::Engine::Remote';

with 'Langertha::Role::Tools';
with 'Langertha::Role::HermesTools';

DESCRIPTION

This role implements tool calling via Hermes-style XML tags. Instead of using an API's native tools parameter, tool definitions are injected into the system prompt as <tools> XML and the model responds with <tool_call> XML tags containing JSON. This works with any chat model regardless of native tool API support.

Engines composing this role get implementations of the five methods required by Langertha::Role::Tools: "format_tools", "response_tool_calls", "extract_tool_call", "format_tool_results", and "response_text_content". It also provides "build_tool_chat_request" to inject tools into the system prompt instead of passing them as an API parameter.

hermes_call_tag

hermes_call_tag => 'function_call'

The XML tag name used for tool calls in the model's output. Both the prompt template and the response parser use this tag. Defaults to tool_call.

hermes_response_tag

hermes_response_tag => 'function_response'

The XML tag name used when sending tool results back to the model. Defaults to tool_response.

hermes_tool_instructions

hermes_tool_instructions => 'You are a helpful assistant that can call functions.'

The instruction text prepended to the Hermes tool system prompt. Customize this to change the model's behavior without altering the structural XML template. The default instructs the model to call functions without making assumptions about argument values.

hermes_tool_prompt

The full system prompt template used for Hermes tool calling. Must contain a %s placeholder where the tools JSON will be inserted. Built automatically from "hermes_tool_instructions" and "hermes_call_tag". Override this only if you need full control over the prompt structure.

hermes_extract_content

my $content = $self->hermes_extract_content($data);

Extracts raw text content from a parsed LLM response for Hermes tool call parsing. Defaults to OpenAI response format (choices[0].message.content). Override this method in engines with non-OpenAI response structures.

format_tools

Returns the MCP tool definitions as-is for JSON encoding into the Hermes system prompt.

build_tool_chat_request

Builds a chat request with tool definitions injected into the system prompt as XML, rather than passing them as an API parameter.

response_tool_calls

Parses <tool_call> XML tags from the model's text output and returns an ArrayRef of tool call HashRefs with name and arguments.

extract_tool_call

Extracts tool name and arguments from a Hermes tool call HashRef.

response_text_content

Extracts the final text content from the response, stripping any <tool_call> XML tags.

format_tool_results

Formats tool execution results as <tool_response> XML messages for the next conversation turn.

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.