LlmComposer.FunctionCallHelpers (llm_composer v0.19.3)

Copy Markdown View Source

Helpers for building assistant messages and tool-result messages when handling function (tool) calls returned by LLM providers.

This module provides a default implementation for composing the assistant message that preserves the original assistant response and its function calls. Providers can optionally implement build_assistant_with_tools/3 to customize behavior.

Summary

Functions

Build an assistant message that preserves the original assistant response and its function calls so it can be sent back to the provider along with tool result messages.

Convert executed function-call results into :tool_result messages which include the mapping back to the tool call id in metadata["tool_call_id"].

Functions

build_assistant_with_tools(provider_mod, resp, user_msg, opts \\ [])

@spec build_assistant_with_tools(
  module(),
  LlmComposer.LlmResponse.t(),
  LlmComposer.Message.t(),
  keyword()
) :: LlmComposer.Message.t()

Build an assistant message that preserves the original assistant response and its function calls so it can be sent back to the provider along with tool result messages.

If provider_mod exports build_assistant_with_tools/3, this function will delegate to that implementation; otherwise it uses a sensible default.

build_tool_result_messages(executed_calls)

@spec build_tool_result_messages(list()) :: [LlmComposer.Message.t()]

Convert executed function-call results into :tool_result messages which include the mapping back to the tool call id in metadata["tool_call_id"].