ExAgent
A production agent framework for Elixir. Define tools as ordinary functions, get Ecto-validated structs back, stream live updates into Phoenix, and pause sensitive actions for human approval across restarts. Start with one function call — every OTP, persistence and coordination layer is opt-in.
What ExAgent simplifies
- Zero hand-written JSON Schemas:
deftoolderives tool schemas from Elixir type annotations and validates arguments before your function ever runs. - Typed, self-correcting outputs: Pass an
Ecto.Schemaembedded_schemamodule (with optionalchangeset/2) asoutput:; JSON Schema and changeset errors feed back to the model automatically (up tooutput_retries) until a valid struct is returned. - One loop for buffered, streamed & local models: Powered by stock ReqLLM across OpenAI, Anthropic, Google Gemini, OpenRouter and local Ollama / vLLM / llama.cpp endpoints (including thinking models and malformed tool-envelope auto-retry). Supported provider profiles
- LiveView-ready supervised conversations:
ExAgent.ServerandExAgent.Conversationshandle history, bounded queues, turn steering, cancellation, demand-paced events and SSE / AI SDK / AG-UI adapters. - Crash-safe human approvals:
ExAgent.Continuationcheckpoints runs in PostgreSQL or ETS and never replays an unconfirmed external side effect. - Multi-agent coordination with shared budgets: Scoped delegation, handoffs,
shared-state
Sessions and durableComposition/Flowworkflows inherit ancestor permissions, deadlines and spend limits. - Skills, MCP, observability & offline CI: On-demand Agent Skills, MCP
client & server,
:telemetry+ optional OpenTelemetry (Langfuse / Opik), recorded cassettes andmix exagent.evalquality gates.
Installation
def deps do
[{:exagent, "~> 3.0.0"}]
end
Verified on Elixir 1.18.4 / OTP 28 and Elixir 1.20.0 / OTP 29. A one-shot run
needs no database. Credentials and .env loading
Quick start
agent = ExAgent.new(model: "test", instructions: "Be concise.")
{:ok, result} = ExAgent.run(agent, "Hello!")
%{output: result.output, status: result.status, requests: result.request_count}
# => %{output: "a test response", status: :succeeded, requests: 1}
"test" runs 100% offline using the same execution loop as real providers. With
ANTHROPIC_API_KEY set, swap to model: "anthropic:claude-sonnet-5-5" (see
Models and limits for OpenAI, Gemini,
OpenRouter, Ollama, vLLM and per-tenant credentials). In Phoenix,
mix igniter.install exagent --chat --yes scaffolds a
complete LiveView chat
with PostgreSQL checkpoints and durable approvals.
Tools and typed output
For the MyApp.Forecast Ecto output schema below, add
{:ecto, "~> 3.14 and >= 3.14.3"} to your application's dependencies.
defmodule MyApp.Weather do
use ExAgent.Tools
@doc "Get the weather for a city."
deftool get_weather(_ctx, city :: String.t(), days :: integer()) do
{:ok, "#{city}: sunny for #{days} day(s)"}
end
end
defmodule MyApp.Forecast do
use Ecto.Schema
@primary_key false
embedded_schema do
field :city, :string
field :temp_c, :float
end
def changeset(forecast, attrs) do
forecast
|> Ecto.Changeset.cast(attrs, [:city, :temp_c])
|> Ecto.Changeset.validate_required([:city, :temp_c])
|> Ecto.Changeset.validate_number(:temp_c, greater_than: -100, less_than: 100)
end
end
alias ExAgent.Message.Part.ToolCall
# Offline; with a key use model = "anthropic:claude-sonnet-5-5"
model = %ExAgent.Models.Test{
script: [
{:tool_calls, [%ToolCall{tool_name: "get_weather", args: %{"city" => "Madrid", "days" => 1}}]},
{:tool_calls,
[%ToolCall{tool_name: "final_result", args: %{"city" => "Madrid", "temp_c" => 21.5}}]}
]
}
agent = ExAgent.new(model: model, tools: MyApp.Weather.tools(), output: MyApp.Forecast)
{:ok, result} = ExAgent.run(agent, "What is the weather in Madrid?")
result.output
# => %MyApp.Forecast{city: "Madrid", temp_c: 21.5}
ExAgent derives both JSON Schemas automatically, validates get_weather's
arguments before invoking it, checks MyApp.Forecast.changeset/2 on the model's
answer (sending validation errors back for correction), and returns a real
%MyApp.Forecast{} struct.
Tools and structured output covers
permissions, guardrails, sandboxes and approval gates.
Layers at a glance
Start with the top row and add layers only as your application needs them — see Mental model and architecture for a full pattern decision table.
| Layer | Entry points | What it simplifies | Guide |
|---|---|---|---|
| Run | ExAgent.run/3, ExAgent.run_stream/3 |
Stateless tool loops & typed Ecto outputs | Tools and output |
| Conversation | ExAgent.Server, ExAgent.Conversations, ExAgent.Chat |
Supervised history, streaming & LiveView events | Runtime and events |
| Durability & approvals | store:, ExAgent.Continuation, ExAgent.resume/3 |
Crash-safe checkpoints & human approval pauses | Durability and approvals |
| Coordination | ExAgent.Coordination, ExAgent.Session, ExAgent.Handoff |
Delegation, shared state & durable workflows | Coordination |
Sync coding-agent guidance (LLMs)
ExAgent ships a dedicated machine-optimized documentation track for coding
agents (usage-rules.md, 11 package skills, llms.txt, single-fetch
llms-full.txt, and contract sheets). To sync ExAgent's rules and skills into
your app automatically, add {:usage_rules, "~> 1.3.1", only: :dev, runtime: false}
to deps/0 and configure project/0:
usage_rules: [
file: "AGENTS.md",
usage_rules: [:exagent],
skills: [location: ".agents/skills", package_skills: [:exagent]]
]
Run mix deps.get && mix usage_rules.sync --yes. Codex and Cursor read
AGENTS.md and .agents/skills; for Claude Code use file: "CLAUDE.md" and
location: ".claude/skills". Re-sync after upgrading ExAgent. The installed
dependency also includes usage-rules.md and
usage-rules/skills/<name>/SKILL.md for direct reading.
UsageRules package skills
Documentation and examples
ExAgent separates human tutorials from LLM contract references:
- For humans: Start at Welcome, Mental model and architecture, Getting started or the Documentation index. Upgrading? Read Migration and the changelog.
- For LLMs & coding agents: Open
Coding-agent integration notes,
llms.txt/llms-full.txton HexDocs, or sync the bundled skills withmix usage_rules.sync. - Runnable examples: From a checkout,
mix run examples/demo.exsruns offline; theexamples/directory covers Server, Sessions, Flow, durable approvals and evaluations.
Contributing
Bug reports and pull requests are welcome on
GitHub. Include a minimal
public-API example, the package and Elixir/OTP versions and a sanitized error;
keep credentials and application data out of reports. Source changes follow
AGENTS.md and pass the offline checks:
EXAGENT_OFFLINE=1 MIX_ENV=test mix compile --warnings-as-errors
EXAGENT_OFFLINE=1 MIX_ENV=test mix test --warnings-as-errors
License
Copyright (c) 2025 kukapu. Licensed under the MIT License; see LICENSE.