Planck.Agent.MessageBuilder (Planck.Agent v0.1.7)

Copy Markdown View Source

Pure functions for constructing Planck.Agent.Message values.

No side effects — these functions take raw data and return messages. Used by Planck.Agent to build assistant and tool-result messages during the LLM loop.

Summary

Functions

Build an assistant message from a StreamBuffer.

Build a tool-result message from a list of {call_id, result} pairs.

Normalize a user prompt to a list of content parts.

Functions

build_assistant(stream_buffer)

@spec build_assistant(Planck.Agent.StreamBuffer.t()) :: Planck.Agent.Message.t()

Build an assistant message from a StreamBuffer.

Content order: thinking → text → tool calls. Fields that are empty strings or empty lists are omitted from the message content.

build_tool_result(results)

@spec build_tool_result([{String.t(), {:ok, String.t()} | {:error, term()}}]) ::
  Planck.Agent.Message.t()

Build a tool-result message from a list of {call_id, result} pairs.

Results must be in {:ok, string} | {:error, reason} form. Each value is truncated to 2000 lines / 50000 bytes.

normalize_content(text)

@spec normalize_content(String.t() | [Planck.AI.Message.content_part()]) :: [
  Planck.AI.Message.content_part()
]

Normalize a user prompt to a list of content parts.

A plain string is wrapped in a {:text, text} tuple. A list is returned as-is.