Planck.Agent.MessageBuilder (Planck.Agent v0.3.0)

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 Turn's buffers.

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(turn)

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

Build an assistant message from a Turn's buffers.

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([tool_result]) :: Planck.Agent.Message.t()
when call_id: String.t(),
     result: {:ok, term()} | {:ok, term(), map()} | {:error, term()},
     tool_result: {call_id, result}

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

Results must be in {:ok, string} | {: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.