AI.Util (fnord v0.9.40)

View Source

Summary

Functions

Creates an assistant message struct (AI.Message.Assistant).

This is the tool call request struct (AI.Message.FunctionCall), which must immediately precede the matching tool_msg/3 (same id). In the Responses API native shape, tool call requests are standalone items, not nested in an assistant message.

A guard to identify system messages (struct or legacy raw-map form).

Returns the maximum message length allowed.

Returns a short context block describing the current project and git state. Suitable for prepending to any agent's system prompt.

Builds a "transcript" of the research process by converting the messages into text. This is most commonly used to generate a transcript of the research performed in a conversation for various agents and tool calls.

Creates a system message struct (AI.Message.System), used to define the assistant's behavior for the conversation. The struct still matches the %{role: ..., content: ...} raw-map shape so existing pattern matches keep working.

Creates a tool output struct (AI.Message.FunctionCallOutput). Must immediately follow the matching assistant_tool_msg/3 (same id).

Creates a user message struct (AI.Message.User).

Extracts the user's most recent query from the conversation messages.

Types

msg()

@type msg() :: AI.Message.t()

msg_list()

@type msg_list() :: [msg()]

tool_call()

@type tool_call() :: %{
  id: binary(),
  type: binary(),
  function: %{name: binary(), arguments: binary()}
}

tool_call_parsed()

@type tool_call_parsed() :: %{
  id: binary(),
  type: binary(),
  function: %{name: binary(), arguments: map()}
}

Functions

assistant_msg(msg)

@spec assistant_msg(binary()) :: AI.Message.Assistant.t()

Creates an assistant message struct (AI.Message.Assistant).

assistant_tool_msg(id, func, args)

@spec assistant_tool_msg(any(), binary(), binary()) :: AI.Message.FunctionCall.t()

This is the tool call request struct (AI.Message.FunctionCall), which must immediately precede the matching tool_msg/3 (same id). In the Responses API native shape, tool call requests are standalone items, not nested in an assistant message.

id is coerced to a binary for the same reason as tool_msg/3.

cosine_similarity(vec1, vec2)

@spec cosine_similarity([float()], [float()]) :: float()

is_system_msg?(msg)

(macro)

A guard to identify system messages (struct or legacy raw-map form).

max_msg_length()

@spec max_msg_length() :: non_neg_integer()

Returns the maximum message length allowed.

project_context()

@spec project_context() :: binary()

Returns a short context block describing the current project and git state. Suitable for prepending to any agent's system prompt.

research_transcript(msgs)

@spec research_transcript([msg()]) :: binary()

Builds a "transcript" of the research process by converting the messages into text. This is most commonly used to generate a transcript of the research performed in a conversation for various agents and tool calls.

system_msg(msg)

@spec system_msg(binary()) :: AI.Message.System.t()

Creates a system message struct (AI.Message.System), used to define the assistant's behavior for the conversation. The struct still matches the %{role: ..., content: ...} raw-map shape so existing pattern matches keep working.

tool_msg(id, func, output)

@spec tool_msg(any(), binary(), any()) :: AI.Message.FunctionCallOutput.t()

Creates a tool output struct (AI.Message.FunctionCallOutput). Must immediately follow the matching assistant_tool_msg/3 (same id).

The func argument is kept for source compatibility and used for the spill-to-tempfile filename heuristic; FunctionCallOutput itself does not carry the function name (it pairs to the FunctionCall by call_id).

id is coerced to a binary - real OpenAI call_ids are strings, but test fixtures and a few legacy code paths use integers.

user_msg(msg)

@spec user_msg(binary()) :: AI.Message.User.t()

Creates a user message struct (AI.Message.User).

user_query(messages)

@spec user_query([msg()]) :: binary() | nil

Extracts the user's most recent query from the conversation messages.