Architecture and ownership
View SourceExAgent separates an immutable agent blueprint (%ExAgent{}) from optional
runtime layers. A one-shot run needs no conversation process, database or
tracing service. Add each layer only when your application needs its guarantee;
every layer has a single clear owner and persistence boundary.
Looking for examples and a pattern picker?
Read Mental model and architecture for a visual walkthrough, decision table and progressive three-stage example.
Layer ownership
| Layer | What ExAgent owns | What your application owns |
|---|---|---|
%ExAgent{} | Reusable model, instructions, tools, output schema, capabilities and limit config. | Credentials, trusted callbacks, business logic and domain data. |
| Run | Model ⇄ tool loop, local JSON Schema/changeset validation, retries, result and usage. | Reconciling external side effects whose network outcome is uncertain. |
| Execution scope | Delegation ancestry, shared admission and subtree usage accounting. | Keeping auxiliary sub-agent calls inside that scope when they must inherit authority. |
| Server & Conversations | Supervised history/model state, bounded queue, backpressure, cancellation and events. | Authenticated namespaces, UI consumption and idle/eviction policy. |
| Session | Participants, turn policy and a single writer of shared structured state. | Trusted state transitions, policy decisions and state codecs. |
| Store & Continuation | Confirmed snapshots and atomic compare-and-swap continuation records. | Database lifecycle, reviewer authorization (authorize/3) and durable deployment. |
Agent definition (%ExAgent{})
└─ run / run_stream / resume / resume_stream
├─ Model → Stock ReqLLM (cloud or local Ollama/vLLM) or custom adapter
├─ Tool → JSON Schema + permissions + execution + JSON result
└─ run_child → inherited scope, permissions, deadlines and budgets
Server / Conversations → supervised runs & events → optional Store (ETS / Postgres)
Session → turns & shared state → optional Store (ETS / Postgres)
Events / :telemetry / OpenTelemetry → separate application-facing channelsCore invariants across layers
- Validated outputs vs. partial failures: A
:succeededresult always holds validated output. An operational failure returns%ExAgent.RunError{}with its cause and all known partial progress up to the failure. - Provisional streaming: Streaming deltas are for UI responsiveness only. Tools and final structured outputs never run until a complete, validated terminal model response arrives.
- Strict tool boundaries: Effective tool arguments are validated locally before execution. Permission denials, schema errors, retryable model errors, tool failures and uncertain effects remain distinct states.
- Inherited authority and honest accounting: Delegated children inherit
every ancestor's permissions and budgets. Parent usage includes its subtree,
and unknown token/cost counts stay explicitly unknown rather than
0. - Non-destructive compaction: Context compaction projects a smaller next model request while preserving canonical conversation history.
- Confirmed durability: A Store write must be confirmed before durable acknowledgement. Persisted approvals bind an exact execution boundary, resume with live trusted configuration and current authorization, and never blindly replay an uncertain external effect.
- Privacy-first observability: Your application owns the OpenTelemetry SDK and exporter. Default traces omit prompt/response content and never serialize arbitrary live model adapters or credentials.
Extension points
Implement ExAgent.Model, ExAgent.Store, ExAgent.PubSub,
ExAgent.Conversations.Registry or ExAgent.Session.TurnPolicy when your
application needs a custom model backend, storage engine, event bus, cluster
registry or multi-agent turn strategy. Tools, hooks, model codecs and state
codecs remain trusted application code. OTP supervision cleans up framework-owned
processes and resources; it cannot roll back arbitrary external IO.
Continue to Tools and output, Models and limits, Durability and approvals, Coordination or Observability.