Omni.Session.Title (Omni Agent v0.6.0)

Copy Markdown View Source

Generates titles for conversations.

Two strategies are exposed through a single entry point, generate/3:

  • Heuristic (:heuristic) — picks the first content-bearing message and truncates its text. No LLM call. A message bears content when it has a private[:title_seed] string (which wins over its content), or when text remains after stripping leading well-formed XML — so prompts wrapped in context markup (e.g. <context_history>...</context_history>) don't produce titles of truncated markup. Set a :title_seed by prompting with a %Omni.Message{} (see Omni.Agent.prompt/3); the seed is used verbatim (truncated, never XML-stripped).
  • Model (Omni.Model.ref() or %Omni.Model{}) — asks the given model to summarise the first few turns into a concise title.

Both branches return {:error, :no_text} when no usable text exists. Attachments, thinking blocks, tool uses, and tool results are filtered out — only text contributes.

This module is pure: it makes at most one HTTP call (in the model branch) and holds no state.

Summary

Functions

Generates a title for the given conversation.

Functions

generate(strategy, messages, opts \\ [])

@spec generate(
  :heuristic | Omni.Model.t() | Omni.Model.ref(),
  [Omni.Message.t()],
  keyword()
) ::
  {:ok, String.t()} | {:error, term()}

Generates a title for the given conversation.

When strategy is :heuristic, truncates the first content-bearing message — its private[:title_seed] if set, otherwise its text with leading well-formed XML stripped (see the moduledoc). When strategy is an Omni.Model.ref() (or %Omni.Model{}), asks the model to summarise the conversation.

Returns {:error, :no_text} when no extractable text exists — for the model branch, this is checked against the first four messages.

Options

Options are passed through to Omni.generate_text/3 when using the model strategy. Common options include :api_key and :plug (for testing).