Build agents with Elixir

View Source

ExAgent 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 buildStart here
Understand how every piece fits togetherMental model and architecture
Install ExAgent and run your first agentGetting started
Call Elixir functions as tools and return Ecto structsTools and structured output
Pick cloud or local models (Ollama/vLLM) and set budgetsModels, budgets and limits
Stream responses, manage conversations and wire LiveViewRuntime and events
Persist runs and pause for human approval across restartsDurability and approvals
Delegate work, hand off turns or run multi-agent workflowsCoordination
Load task instructions on demand or remember users across turnsSkills · Long-term memory
Test deterministically in CI and run evaluationsTesting and evaluations
Export traces to OpenTelemetry, Langfuse or OpikObservability
Connect external MCP tool servers or expose your ownMCP
Diagnose an error or inspect your setupTroubleshooting

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.md and 11 package skills directly into your repository with mix usage_rules.sync. ExDoc also publishes llms.txt, single-fetch llms-full.txt and 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.