ExAgent.Server (ExAgent v2.0.1)

View Source

Supervised owner of conversational history, model state and accumulated usage.

Runs execute in owned supervised tasks. Stopping or killing the Server kills its active worker; external effects and detached user processes cannot be undone. chat/3 waits for completion; send_message/3, steer/3 and stream/3 return an admission id for volatile work, not a durable execution acknowledgement.

With an opt-in Store, terminal success follows a confirmed checkpoint. A failed save returns ExAgent.CheckpointError, preserving the execution outcome and new state in memory. Mutations and queue draining then wait for checkpoint/1, which retries only saving. Adapter IO is synchronous and must be bounded by the adapter. Recovery restores conversation data, never replays tools or queued work.

Events use the agent topic and a sequence local to emitter_id. A living owner attempts one terminal emission per run; PubSub is not a durable event log.

Summary

Functions

Request cancellation; idempotent. Does not undo external effects.

Execute a run. Options include deps, model_settings, stream_text, estimate_cost, permissions and approve. Explicit message_history overrides accumulated context; run_id, on_event, on_progress and instruction management belong to the Server. A call timeout does not cancel work already owned by the Server.

Retry an unconfirmed snapshot only, without repeating execution.

Returns a specification to start this module under a supervisor.

Query the persisted continuation independently of PubSub delivery.

Persist a host-authorized decision; this call does not resume the run.

Resume the pending logical run with fresh host deps/options in a new owned worker.

Start with :agent and optional :agent_id, :name, :store, :pubsub, :namespace (trusted application string, nil for legacy), :metadata, :max_pending (8). Only Store not_found starts a new conversation; invalid/incompatible snapshots or load failures return a controlled error.

Run the same agentic loop with provisional text deltas and one complete terminal.

Functions

abort(server)

Request cancellation; idempotent. Does not undo external effects.

chat(server, prompt, opts \\ [])

Execute a run. Options include deps, model_settings, stream_text, estimate_cost, permissions and approve. Explicit message_history overrides accumulated context; run_id, on_event, on_progress and instruction management belong to the Server. A call timeout does not cancel work already owned by the Server.

checkpoint(server)

Retry an unconfirmed snapshot only, without repeating execution.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

continuation(server)

Query the persisted continuation independently of PubSub delivery.

decide(server, decision, opts)

Persist a host-authorized decision; this call does not resume the run.

health(server)

history(server)

reset(server)

resume(server, opts \\ [])

Resume the pending logical run with fresh host deps/options in a new owned worker.

send_message(server, prompt, opts \\ [])

set_model(server, model)

start_link(opts)

Start with :agent and optional :agent_id, :name, :store, :pubsub, :namespace (trusted application string, nil for legacy), :metadata, :max_pending (8). Only Store not_found starts a new conversation; invalid/incompatible snapshots or load failures return a controlled error.

Payload admission options are :max_input_bytes (1MiB), :max_pending_bytes and :max_history_bytes (8MiB each), integers1..64MiB. Bytes mean uncompressed Erlang external term size, including opts/deps/callback representation, not JSON, referenced resources or live RAM. Input/history errors reject before admission; pending count/bytes return :queue_full. Queued work rechecks input and history when dequeued; health exposes charged pending bytes.

History limits gate admission/restore, not output retention of the current run. Canonical history is never silently truncated. Application-created terms and mailbox traffic already exist before these checks. Caller timeout is not cancel.

steer(server, prompt, opts \\ [])

stream(server, prompt, opts \\ [])

Run the same agentic loop with provisional text deltas and one complete terminal.

usage(server)