Planck.Agent.Message (Planck.Agent v0.1.0)

Copy Markdown View Source

An agent-side message with metadata.

Wraps Planck.AI.Message content parts with an id, timestamp, and metadata map. Messages with a {:custom, atom()} role are UI-only and filtered out before the context is sent to the LLM.

Summary

Functions

Estimate the token count for a list of messages using a character-based approximation (4 characters ≈ 1 token). Fast enough for real-time display and compaction threshold checks; not a substitute for model tokenization.

Build a new message with a generated id and current UTC timestamp.

Convert a list of agent messages to Planck.AI.Message structs.

Types

role()

@type role() :: :user | :assistant | :tool_result | {:custom, atom()}

t()

@type t() :: %Planck.Agent.Message{
  content: [Planck.AI.Message.content_part()],
  id: non_neg_integer() | String.t(),
  metadata: map(),
  role: role(),
  timestamp: DateTime.t()
}

Functions

estimate_tokens(messages)

@spec estimate_tokens([t()]) :: non_neg_integer()

Estimate the token count for a list of messages using a character-based approximation (4 characters ≈ 1 token). Fast enough for real-time display and compaction threshold checks; not a substitute for model tokenization.

new(role, content, metadata \\ %{})

@spec new(role(), [Planck.AI.Message.content_part()], map()) :: t()

Build a new message with a generated id and current UTC timestamp.

to_ai_messages(messages)

@spec to_ai_messages([t()]) :: [Planck.AI.Message.t()]

Convert a list of agent messages to Planck.AI.Message structs.

{:custom, :summary} messages are converted to :user so the LLM sees compacted context. All other {:custom, _} messages are dropped.