A2UIAgent.Format behaviour (A2UIAgent v0.1.1)

Copy Markdown View Source

An inference format: how the model is told to write A2UI, and how its output is read back.

A format module builds a format value from the active catalogs (new/2), renders the system prompt snippet (prompt/1) and creates parsers (parser/1). A format spec names a format module and the options it is created with, {module, options} (or just the module); create/3 turns a spec into a format for a set of catalogs, the way an agent does once per request after negotiating catalogs.

A2UIAgent.DirectJson and A2UIAgent.Express are the built-in formats.

A format that implements the optional callbacks catalogs/1, base_rules/1, catalog_instructions/2 and examples/2 (the pieces its prompt is made of) can also be packaged as skills (A2UIAgent.SkillGenerator).

Summary

Types

A format module with its options.

Callbacks

The catalog-independent rules of the prompt.

The prompt's part for one catalog (by id), or for all of them (nil).

The format's active catalogs, in order.

The prompt's examples for one catalog (by id), or for all of them (nil).

Creates the format for catalogs (default catalog first). Options include :examples, a list of example turns (each a list of messages).

A fresh parser for the format's catalogs.

The system prompt snippet.

Functions

Creates the format a spec names for catalogs, passing examples.

Types

spec()

(since 0.1.0)
@type spec() :: module() | {module(), keyword()}

A format module with its options.

Callbacks

base_rules(struct)

(since 0.1.0) (optional)
@callback base_rules(struct()) :: String.t()

The catalog-independent rules of the prompt.

catalog_instructions(struct, arg2)

(since 0.1.0) (optional)
@callback catalog_instructions(struct(), String.t() | nil) :: String.t()

The prompt's part for one catalog (by id), or for all of them (nil).

catalogs(struct)

(since 0.1.0) (optional)
@callback catalogs(struct()) :: [A2UICore.Catalog.t()]

The format's active catalogs, in order.

examples(struct, arg2)

(since 0.1.0) (optional)
@callback examples(struct(), String.t() | nil) ::
  {:ok, String.t()} | {:error, A2UICore.Error.t()}

The prompt's examples for one catalog (by id), or for all of them (nil).

new(list, keyword)

(since 0.1.0)
@callback new([A2UICore.Catalog.t()], keyword()) ::
  {:ok, struct()} | {:error, A2UICore.Error.t()}

Creates the format for catalogs (default catalog first). Options include :examples, a list of example turns (each a list of messages).

parser(struct)

(since 0.1.0)
@callback parser(struct()) :: struct()

A fresh parser for the format's catalogs.

prompt(struct)

(since 0.1.0)
@callback prompt(struct()) :: {:ok, String.t()} | {:error, A2UICore.Error.t()}

The system prompt snippet.

Functions

create(module, catalogs, examples)

(since 0.1.0)
@spec create(spec(), [A2UICore.Catalog.t()], [[map()]] | nil) ::
  {:ok, struct()} | {:error, A2UICore.Error.t()}

Creates the format a spec names for catalogs, passing examples.