Build agents with Elixir
View SourceExAgent 3.0 · Elixir / OTP
Start with one function call.
Add OTP supervision, approvals and coordination only when you need them.
Define tools as ordinary Elixir functions, validate structured output with Ecto changesets, stream live updates into Phoenix, and pause high-risk tool calls for human approval across deploys — all over one coherent agent loop powered by stock ReqLLM.
Run your first agent → How ExAgent works For LLMs & coding agents
Package version
These pages document ExAgent 3.0. Upgrading from 1.x or 2.x? Read Migration and check Supported features and limits.
A small, working beginning
Run this inside any Mix project with {:exagent, "~> 3.0.0"} — no API keys,
database or network needed:
agent = ExAgent.new(model: "test", instructions: "Be concise.")
{:ok, result} = ExAgent.run(agent, "Hello!")
result.output
# => "a test response""test" runs the exact same loop as Anthropic, OpenAI, Gemini, OpenRouter,
Ollama or vLLM. Once your app handles results cleanly, swap model: to a real
provider without changing a single line of business logic.
What ExAgent simplifies
Building production agents in Elixir usually forces you to hand-roll the same plumbing over and over: JSON Schema generation, changeset retry loops when a model emits malformed JSON, streaming GenServers with backpressure, crash-safe human approvals that never double-execute a side effect, and offline test harnesses. ExAgent turns each of those into an opt-in layer:
- 1. Run
- What it gives you: Stateless tool loops and Ecto-validated typed outputs.
What it simplifies: No hand-written JSON Schemas, manual retry loops or raw HTTP parsing. Start here for extraction, classification and Oban jobs. - 2. Server
- What it gives you: Supervised conversations with history, bounded queues, streaming deltas, Phoenix LiveView scaffolding and SSE / AI SDK / AG-UI adapters.
What it simplifies: No custom GenServer state machines for cancellation, backpressure or reconnection. - 3. Store & Approvals
- What it gives you: Confirmed checkpoints (ETS for in-VM dev/tests, PostgreSQL for production) and explicit pause/resume boundaries.
What it simplifies: Survive crashes and deploys with PostgreSQL without ever replaying an unconfirmed payment, email or mutation. - 4. Coordination
- What it gives you: Scoped delegation, handoffs, shared-state sessions and durable multi-step workflows.
What it simplifies: Compose specialists with inherited budgets, permissions and cancellation instead of ad-hoc message passing.
Unsure which layer fits your problem? Read Mental model and architecture for a 5-minute walkthrough and a concrete pattern decision table.
Learn by task
| What you want to build | Start here |
|---|---|
| Understand how every piece fits together | Mental model and architecture |
| Install ExAgent and run your first agent | Getting started |
| Call Elixir functions as tools and return Ecto structs | Tools and structured output |
| Pick cloud or local models (Ollama/vLLM) and set budgets | Models, budgets and limits |
| Stream responses, manage conversations and wire LiveView | Runtime and events |
| Persist runs and pause for human approval across restarts | Durability and approvals |
| Delegate work, hand off turns or run multi-agent workflows | Coordination |
| Load task instructions on demand or remember users across turns | Skills · Long-term memory |
| Test deterministically in CI and run evaluations | Testing and evaluations |
| Export traces to OpenTelemetry, Langfuse or Opik | Observability |
| Connect external MCP tool servers or expose your own | MCP |
| Diagnose an error or inspect your setup | Troubleshooting |
Two documentation tracks: humans and LLMs
ExAgent ships two distinct documentation tracks generated from the same release:
- For human developers — Start with Mental model, Getting started and the task guides above. Each guide focuses on what a feature does, why it helps and how to use it with complete, realistic Elixir examples.
- For LLMs and coding agents — Point your AI assistant at
Coding-agent integration notes, the machine-dense contract
sheets (Tools & models contracts
and Runtime & ops contracts), or
sync the bundled
usage-rules.mdand 11 package skills directly into your repository withmix usage_rules.sync. ExDoc also publishesllms.txt, single-fetchllms-full.txtand per-page Markdown files (see the links in the footer).
Browse the Modules tab or press / for the complete API reference, or open the Documentation index for the full map including Phoenix, Oban and OTLP integration recipes.