Nous AI
Give a model an Elixir function, stream the answer into your application, and check that a prompt or model change still calls the right tool. Nous runs the tool loop, validates arguments, and returns the answer, conversation context, and usage together.
Installation
Add Nous to your application's dependencies and run mix deps.get. Use Elixir 1.18+ and OTP 27+.
{:nous, "~> 0.20.1"}
For the live walkthrough, set OPENAI_API_KEY and start iex -S mix, or change the model string to a tool-capable model on your local server. To try the agent without credentials, jump to the offline check.
Quick Start
Give the agent a tool
Put this module in lib/my_app/weather.ex or paste it into IEx. The fixed forecasts make it easy to see whether the agent actually used your data. Replace the lookup with your application's function when you're ready.
defmodule MyApp.Weather do
@forecasts %{"paris" => "sunny, 24°C", "oslo" => "light rain, 9°C", "tokyo" => "cloudy, 18°C"}
def tool do
Nous.Tool.from_function(&lookup/2,
name: "get_weather",
description: "Get the current weather for a city.",
parameters: %{
"type" => "object",
"properties" => %{"city" => %{"type" => "string"}},
"required" => ["city"]
}
)
end
defp lookup(_ctx, %{"city" => city}) do
forecast = Map.get(@forecasts, String.downcase(city), "no forecast available")
"#{city}: #{forecast}"
end
end
agent = Nous.new("openai:gpt-4o-mini", tools: [MyApp.Weather.tool()])
{:ok, result} = Nous.run(agent, "Use get_weather to check the weather in Tokyo.")
IO.puts(result.output)
result.usage.tool_calls
The answer should mention cloudy skies and 18°C. The tool count tells you whether the model called your function. Continue the conversation by passing context: result.context to the next run.
Stream the run into LiveView
Capture the view's PID before starting the background task. Inside the task, run the same agent with streaming enabled.
Nous.run(agent, prompt, stream: true, notify_pid: view)
The view receives {:tool_result, result} when the tool finishes and {:agent_delta, text} as the model writes. The LiveView walkthrough includes the form, event handlers, and failure path.
Check tool use offline
The packaged example uses a scripted model and the same Tokyo forecast. From a Mix project with Nous installed, save a baseline and compare a second run.
mix nous.eval --task Nous.Eval.Examples.Basic --k 3 --seed 1 --set-baseline weather-demo
mix nous.eval --task Nous.Eval.Examples.Basic --k 3 --seed 1 --baseline weather-demo
Expect five cases and 15 passing samples. The Tokyo case checks that the agent called get_weather with the city argument. To see a regression, use a checkout of Nous and follow the editable exercise. Changing one tool description breaks the weather cases while the arithmetic cases still pass.
Supported Providers
Switch hosted or local models using a provider:model string. For a single text response, call Nous.generate_text/3. For a stream of plain text chunks, call Nous.stream_text/3. See the provider list and configuration.
Taking an agent into production
| When you need to… | Start here |
|---|---|
| Add another tool or pass application data | Getting started |
| Approve a sensitive action | Permissions |
| Return a validated record | Structured output |
| Cancel a run or manage a supervised session | LiveView integration |
| See what happened during a run | Observability |
| Explore memory, workflows, research, or advanced evals | All guides |
Run in Livebook
No clone, no mix — these open straight from the hex page and install Nous via Mix.install/2:
| Notebook | What it covers |
|---|---|
First call, first agent, streaming, reading result.usage |
|
| Custom tools, permissions, an interactive approval handler | |
| Ingest, retrieve, and query a knowledge base with Kino inputs |
See the examples collection for runnable scripts and AGENTS.md for coding-agent integration.
Contributing
Contributions welcome. See CONTRIBUTING.md for setup, test commands, code-quality checks, project layout, and the security rules that apply to all code in the repo.
License
Apache 2.0 - see LICENSE
Credits
- Inspired by Pydantic AI — Nous brings the same agent-shaped API to Elixir, layered on OTP for supervision and Phoenix for the UI story.
- HTTP: Req + Finch