AshAi.ChatUI.Tools (ash_ai v1.5.6)

Copy Markdown View Source

Normalizes tool call and tool result data for generated chat UIs.

mix ash_ai.gen.chat templates delegate to extract/1 so the generated modules stay small and the parsing behavior is centralized in AshAi.

Advanced apps can override the generated delegation seam:

@chat_ui_tools MyApp.ChatUITools

Summary

Functions

A tool result's content in a form to store as JSON and show to people, such as in a message's tool_results.

Types

extracted_tool_data()

@type extracted_tool_data() :: %{
  tool_calls: [tool_call()],
  tool_results: [tool_result()]
}

tool_call()

@type tool_call() :: %{
  id: String.t(),
  name: String.t(),
  arguments: map(),
  arguments_preview: String.t()
}

tool_result()

@type tool_result() :: %{
  id: String.t(),
  name: String.t() | nil,
  content: term(),
  is_error: boolean(),
  content_preview: String.t()
}

Functions

extract(message)

@spec extract(map() | struct()) ::
  {:ok, extracted_tool_data()} | {:error, Ash.Error.t()}

storable_content(content)

@spec storable_content(term()) :: term()

A tool result's content in a form to store as JSON and show to people, such as in a message's tool_results.

Content parts become text, with images and other non-text parts described rather than carrying their data, and a list that is all text is joined. Other content is returned as it is. Store the result's exact content, images included, with AshAi.Transcript.to_parts/2.