Modules
An agent: model + instructions + tools + output spec, runnable as a loop that alternates between calling the model and executing tools until a final result is produced.
A DynamicSupervisor that owns ExAgent.Server processes.
Composable middleware that observes/transforms an agent run at well-defined
points. This is ExAgent's "capabilities" spine, modelled the Elixir way: a
behaviour whose callbacks default to no-ops via use ExAgent.Capability, so
a capability overrides only the hooks it cares about.
Behaviour for shrinking a conversation history when it grows too large, so a long-running session stays within a model's context window.
A capability that runs a compactor on before_model_request, shrinking the
canonical history (and the request about to be sent) when it grows too large.
A compactor that summarizes older messages and keeps a recent window verbatim.
Orchestration patterns on top of ExAgent.Session and the core loop.
Helpers for turning token usage into an estimated cost, used together with
the max_budget_cents field of ExAgent.UsageLimits.
Versioned, serializable event envelope — ExAgent's UI/runtime contract.
A client for Model Context Protocol servers
over the stdio transport, exposing a server's tools as ExAgent.Tools.
Pure JSON-RPC 2.0 encoding/decoding for the Model Context Protocol, plus the
mapping from an MCP tool spec to an ExAgent.Tool.
Message and part types exchanged between the agent and a model.
Request & response part structs.
A retry prompt: validation errors (list of maps) or a plain message, sent back to the model so it can correct itself.
A system / instruction prompt part.
A plain text chunk returned by the model.
A reasoning / chain-of-thought part (provider-dependent).
The model asking the agent to run a tool.
The return value of a tool call, fed back to the model.
A user prompt part (text or multimodal content list).
A message sent to the model.
A message returned by the model.
Token accounting for a single model response.
Behaviour that every provider model implements.
Advisory declaration of what a given model/provider supports, so callers and future capabilities can negotiate gracefully per model — e.g. whether the provider can do native JSON-schema output, forced tool calls, or extended thinking.
The per-request contract handed to a model. It bundles the tools the agent has prepared (function tools + output tools), the negotiated output mode, and the structured-output schema (if any).
A tool or output validator can return/raise this to ask the model to try
again. In Elixir we mostly use {:error, reason} tuples, but this exception
exists for the rescue-based escape hatch.
Per-request knobs sent to the model. Provider-specific options that are not
first-class fields can be carried in the immutable :extra map.
Anthropic Messages API provider, or any endpoint that speaks the same format
(e.g. Z.AI's /api/anthropic, which serves GLM models natively in Anthropic
form).
OpenAI Chat Completions provider. Talks the real API over Req.
OpenRouter provider.
A deterministic, in-process model for development and tests.
Structured output via Ecto schemas and changesets.
Per-tool admission control: :allow, :ask or :deny, matched against tool
names with glob patterns — the same model opencode uses for tool safety.
Implementation for providers that speak the Anthropic Messages API:
POST {base_url}/v1/messages.
Shared implementation for any provider that speaks the OpenAI Chat
Completions wire format (/v1/chat/completions). This covers OpenAI itself
and OpenRouter (and DeepSeek, Groq, Together, etc.).
Turn a Req asynchronous response into a lazy Stream of Server-Sent-Events.
Behaviour for broadcasting ExAgent.Events.
In-process PubSub backed by a duplicate-key Registry
(ExAgent.PubSub.Registry, started by the application supervisor).
No-op PubSub (default). Broadcasts are discarded; subscribe/2 is
unsupported. Use when you don't need to observe events (e.g. pure one-shot
ExAgent.run/3).
Delegates to Phoenix.PubSub when available, with no hard dependency.
Structured error returned by providers for transport/API failures.
The context object threaded through dynamic instructions, tool calls and output validators during a single run.
Convert Elixir type expressions (as written in :: annotations / typespecs)
into JSON Schema fragments — the foundation for deftool and structured
output.
A supervised, stateful wrapper around ExAgent.run/3.
A serializable checkpoint of an ExAgent.Server's conversational state.
A coordinated, multi-participant interaction with shared state.
A member of an ExAgent.Session: either an :agent (typically backed by an
ExAgent.Server) or a :human (a real person driving via LiveView/a channel).
A handle placed in RunContext.deps so tools running inside an agent run can
read the session's shared state and propose changes — without ever holding
a mutable reference to it.
Decides the order in which session participants take turns.
Cycles participants in an explicitly given order, forever. Use it when participants act in a fixed, possibly uneven sequence — D&D initiative order, priority-based triage, etc.
Cycles participants in insertion order, forever (each full pass is a "round"). The simplest fair policy — good for chat, brainstorming, or any turn-taking where everyone gets equal time.
A coordinator-driven turn order: a supervisor participant alternates with each worker in turn, forever.
Behaviour for persisting ExAgent.Server.Snapshots (and, in Phase 3, session
snapshots).
In-process, ETS-backed ExAgent.Store implementation (dev/test default).
A durable ExAgent.Store backed by PostgreSQL, for resume across crashes and
multiple nodes.
Telemetry event helpers.
A tool the model may call.
Define tools as plain Elixir functions, with their JSON Schema derived from
:: type annotations and @doc strings — no hand-written schemas.
Raised/returned when the model behaves in a way the loop cannot recover from (retries exhausted, no progress, usage limits hit).
Run-level safety net: caps on requests, token usage, tool calls and cost, enforced at well-defined points in the agent loop.