ExAgent.Coordination.Composition (ExAgent v2.2.1)

View Source

Experimental trusted-host definition of a bounded agent sequence.

run/3 executes a durable, fail-fast sequence in one attempt. resume/3 restores admitted ready boundaries without replaying completed steps. No agent, mapping, model codec or other callback runs during construction or binding validation.

Definitions contain live host agents/codecs and must not be serialized. Only binding/1 returns portable data. That binding cannot reconstruct a definition, grant authority, or prove that host code has not changed under the same version. Hosts must version agent definitions (including instructions/tools/settings), policy, model/codec, output contracts and input mappings when their meaning changes. Runtime Model bindings and tool inventories remain separate admission checks.

Summary

Functions

Return the explicitly versioned portable identity of a trusted definition.

Validate a sequence definition without executing user code.

Resume a ready durable sequence from its exact public continuation reference.

Execute a sequence using a required :continuation Writer configuration.

Validate stored identity against a freshly supplied trusted definition, without IO.

Types

t()

@opaque t()

Functions

binding(definition)

@spec binding(t()) :: {:ok, map()} | {:error, atom()}

Return the explicitly versioned portable identity of a trusted definition.

This is not an executable continuation frame. It contains no functions, agent structs, model state, credentials, dependency objects or tracing context. Host references themselves must be nonsecret. A mutated definition is revalidated.

new(opts)

@spec new(keyword()) :: {:ok, t()} | {:error, atom()}

Validate a sequence definition without executing user code.

Required keyword options: :id, :version (nonempty UTF-8 strings, at most 512 bytes each), and :steps (1..255 atom-keyed maps with unique IDs). Optional kind: :sequence and failure_policy: :fail_fast are the only supported choices. Unknown or duplicate options are rejected.

Each step requires :id, an ExAgent struct in :agent, versioned references :definition, :policy, :model_ref, :output_ref, and :model_codec with dump/1 and load/2 functions. References use the existing %{id: ..., version: ...} convention (string keys also accepted). A mapping requires both :input (a pure arity-2 function) and :input_version (a version string). It will receive the initial input and confirmed outputs by step ID when execution is integrated. Without mapping, the first input is initial input and successors use prior output.

The complete encoded identity binding, including fingerprint, is limited to 65,536 JSON bytes. This is a definition limit, not a runtime journal reservation.

resume(definition, reference, opts \\ [])

Resume a ready durable sequence from its exact public continuation reference.

Administrative recovery is explicit (ExAgent.Continuation.recover/3); this function never recovers an expired claim or refreshes a reference. Confirmed completed steps are data only. Options match run/3.

run(definition, input, opts \\ [])

Execute a sequence using a required :continuation Writer configuration.

Optional :root_options restrict the shared scope; :step_options maps step IDs to ordinary run options. :observability and :trace_context are ephemeral. Returns a portable confirmed result, or a RunError with the confirmed partial. A failed checkpoint retains its retry token; retrying it never executes a step.

validate_binding(definition, stored)

@spec validate_binding(t(), term()) :: :ok | {:error, atom()}

Validate stored identity against a freshly supplied trusted definition, without IO.

Malformed/future bindings reject as :invalid_composition_binding; well-formed changed identities reject as :composition_definition_changed. Never load host definitions or resolve modules from the stored binding. This check alone is not runtime admission, approval, or validation of a continuation's journal/ledger.