ai.Agent

The default runner. A spec-mode LLM function's direct call runs `Agent.new(client = client).run(Fn@spec(...)).value`; construct it yourself to set the other fields (`$` call-site parameters are a future phase).

Reference version

Signature

class ai.Agent

The default runner. A spec-mode LLM function's direct call runs Agent.new(client = client).run(Fn@spec(...)).value; construct it yourself to set the other fields ($ call-site parameters are a future phase).

The class itself is not generic: none of its configuration involves the output type. Out lives on run, where it is inferred from the spec argument, so no call site needs to name it.

Source:<builtin>/ai/runner.bamlbytes 117818897

Fields

max_steps

int

schema_attempts

int

Static methods

function

new

<__effect_param_0>(
max_steps: int = …,
schema_attempts: int = …,
client: ai.Client | null = …,
tool_errors: ai.tools.ErrorMode = …,
on_event: ((ai.events.Event) -> void throws __effect_param_0) | null = …
) -> ai.Agent throws baml.errors.InvalidArgument

Instance methods

function

_attempt_turn

<Out>(
self,
spec: ai.FunctionSpec<Out>,
attempts_left: int
) -> ai.ModelTurn throws baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure

(internal) One accepted model turn, with the within-turn repair loop: when a Complete turn's candidate does not parse, commit the failed turn and a correction request as ordinary events and invoke again, under a fixed attempt budget. Everything that happened is on the record; a repair attempt does not consume a step. Token usage of every attempt is added to total.

function

_emit_from

(self, j: ai.Journal, seen: int) -> int

(internal) Emit any events appended since seen to on_event; returns the new count.

function

_has_media_output

<Out>(self, turn: ai.ModelTurn) -> bool throws baml.errors.UnknownError

(internal) Does this turn carry content a media-shaped Out can be built from? Mirrors the Ok(None) condition of sys_llm's parse_llm_output_for_target: nothing to build from means fall back to the ordinary text parse. Always false when Out holds no media.

function

_media_value

<Out>(
self,
provider: string
) -> Out throws baml.errors.UnknownError | ai.errors.ParseFailed

(internal) Build a media-shaped Out from the turn's content blocks. Only called when _has_media_output holds; the shape-specific errors below are the ported sys_llm messages, thrown after the turn is already on the record.

function

_parses

<Out>(
self,
candidate: string
) -> bool throws baml.errors.UnknownError
function

_validated_schema_attempts

(self) -> int throws baml.errors.InvalidArgument

Implementations

ai.Runner for ai.Agent

Error = baml.errors.InvalidArgument | baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure

Instance methods

Source:<builtin>/ai/runner.bamlbytes 1313918895