NAME

Langertha::Chat - Chat abstraction wrapping an engine with optional overrides

VERSION

version 0.302

SYNOPSIS

use Langertha::Engine::OpenAI;
use Langertha::Chat;

my $engine = Langertha::Engine::OpenAI->new(
    api_key => $ENV{OPENAI_API_KEY},
    model   => 'gpt-4o',
);

my $chat = Langertha::Chat->new(
    engine        => $engine,
    system_prompt => 'You are a helpful assistant.',
    plugins       => ['Langfuse'],
);

my $reply = $chat->simple_chat('Hello!');

# With MCP tool calling
my $chat_tools = Langertha::Chat->new(
    engine      => $engine,
    mcp_servers => [$mcp],
    plugins     => ['Langfuse'],
);
my $result = $chat_tools->simple_chat_with_tools('List files in /tmp');

DESCRIPTION

Langertha::Chat wraps any engine that consumes Langertha::Role::Chat and adds optional overrides for model, system prompt, and temperature, plus plugin lifecycle hooks via Langertha::Role::PluginHost.

Use this class when you want to share a single engine instance across multiple chat contexts with different configurations, or when you need plugin observability (e.g. Langertha::Plugin::Langfuse) without modifying the engine itself.

engine

The LLM engine to delegate chat requests to. Must consume Langertha::Role::Chat.

system_prompt

Optional system prompt. When set, prepended to messages for each request, overriding any system prompt on the engine itself.

model

Optional model name override. When set, overrides the engine's chat_model via %extra pass-through.

temperature

Optional temperature override. When set, overrides the engine's temperature.

mcp_servers

ArrayRef of Net::Async::MCP instances for tool calling.

tool_max_iterations

Maximum tool-calling round trips. Defaults to 10.

simple_chat

my $response = $chat->simple_chat('Hello!');

Sends a synchronous chat request. Fires plugin_before_llm_call and plugin_after_llm_response hooks.

simple_chat_f

my $response = await $chat->simple_chat_f('Hello!');

Async version of "simple_chat".

simple_chat_stream

my $content = $chat->simple_chat_stream(sub { print shift->content }, 'Hi');

Synchronous streaming chat. Calls $callback with each chunk.

simple_chat_with_tools

my $text = $chat->simple_chat_with_tools(@messages);

Synchronous tool-calling chat loop. Gathers tools from "mcp_servers", sends chat requests, executes tool calls, and iterates until the LLM returns a final text response. Fires plugin hooks at each step: plugin_before_llm_call, plugin_after_llm_response, plugin_before_tool_call, and plugin_after_tool_call.

simple_chat_with_tools_f

my $text = await $chat->simple_chat_with_tools_f(@messages);

Async version of "simple_chat_with_tools".

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.