ExAgent.Coordination.Composition (ExAgent v3.0.0)

View Source

Trusted-host definition of a bounded agent sequence.

Stability — Candidate.

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 other than the step capabilities' tools/1, which ExAgent.new/1 also calls.

Resume a ready durable sequence or read its terminal result from the exact :continuation reference returned by ExAgent.Continuation.get/2. A stale or invalid reference gives a run error with reason :continuation_conflict. A matching revision that cannot resume gives {:continuation_not_ready, status}.

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(arg1)

@spec binding(t()) :: map()

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()) :: t()

Validate a sequence definition without executing user code other than the step capabilities' tools/1, which ExAgent.new/1 also calls.

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. A step agent whose capabilities fail the guard of ExAgent.new/1 (a 2.x hook, or capability tools missing from its inventory after a struct update) raises ArgumentError, here and when run/3 or resume/3 revalidate the definition.

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 or read its terminal result from the exact :continuation reference returned by ExAgent.Continuation.get/2. A stale or invalid reference gives a run error with reason :continuation_conflict. A matching revision that cannot resume gives {:continuation_not_ready, status}.

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

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

@spec run(t(), term(), keyword()) ::
  {:ok, ExAgent.Coordination.result()} | {:error, ExAgent.RunError.t()}

Execute a sequence using a required :continuation Writer configuration.

Optional :root_options restrict the shared scope; its :fixture, an open ExAgent.Fixture, records or replays every step and delegated child (it is never persisted; pass it again to resume/3). :step_options maps step IDs to ExAgent.run/3 options for that step, checked with the same rules: :deps, :model_settings, :max_payload_bytes, :max_history_bytes, :on_progress, :permissions, :approve, :estimate_cost, :deadline, :max_concurrent_requests and :max_concurrent_tools. The workflow owns :continuation, :message_history, :stream_text, :observability and :trace_context. Invalid workflow options raise ArgumentError before opening or claiming the continuation. For every direct step, both retention limits must be integers from 1 byte through 64 MiB. A supplied step option overrides the corresponding agent default. Each direct step's agent must also have valid usage limits, including when reading a completed run. :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. Pass a router or parallel flow to ExAgent.Coordination.Flow.run/3. A non-sequence definition fails before opening a continuation.

validate_binding(definition, stored)

@spec validate_binding(t() | ExAgent.Coordination.Flow.t(), term()) ::
  :ok
  | {:error,
     :invalid_composition_binding
     | :composition_definition_changed
     | :invalid_continuation_configuration}

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.