Packages
nous
0.20.1
0.20.1
0.20.0
0.19.2
0.19.1
0.19.0
0.18.3
0.18.2
0.18.1
0.18.0
0.17.3
0.17.2
0.17.1
0.17.0
0.16.6
0.16.5
0.16.4
0.16.3
0.16.2
0.16.1
0.16.0
0.15.8
0.15.7
0.15.6
0.15.5
0.15.4
0.15.3
0.15.2
0.15.1
0.15.0
0.14.3
0.14.2
0.14.1
0.14.0
0.13.3
0.13.2
0.13.1
0.13.0
0.12.17
0.12.16
0.12.15
0.12.14
0.12.13
0.12.12
0.12.11
0.12.9
0.12.7
0.12.6
0.12.5
0.12.3
0.12.2
0.12.0
0.11.3
0.11.0
0.10.1
0.10.0
0.9.0
0.8.1
0.8.0
0.7.2
0.7.1
0.7.0
0.5.0
AI agent framework for Elixir with multi-provider LLM support
Current section
Files
Jump to
Current section
Files
README.md

# 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+.
```elixir
{: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](#check-tool-use-offline).
## 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.
```elixir
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
```
```elixir
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.
```elixir
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](docs/guides/liveview-integration.md#quick-start) 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.
```bash
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](docs/guides/evaluation.md#quick-start). 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](docs/guides/providers.md).
## Taking an agent into production
| When you need to… | Start here |
|---|---|
| Add another tool or pass application data | [Getting started](docs/getting-started.md) |
| Approve a sensitive action | [Permissions](docs/guides/permissions.md) |
| Return a validated record | [Structured output](docs/guides/structured_output.md) |
| Cancel a run or manage a supervised session | [LiveView integration](docs/guides/liveview-integration.md) |
| See what happened during a run | [Observability](docs/guides/observability.md) |
| Explore memory, workflows, research, or advanced evals | [All guides](docs/guides/guides.md) |
### 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 |
|---|---|
| [](https://livebook.dev/run?url=https%3A%2F%2Fraw.githubusercontent.com%2Fnyo16%2Fnous%2Fmaster%2Fnotebooks%2F01_intro_to_nous.livemd) [Intro to Nous](notebooks/01_intro_to_nous.livemd) | First call, first agent, streaming, reading `result.usage` |
| [](https://livebook.dev/run?url=https%3A%2F%2Fraw.githubusercontent.com%2Fnyo16%2Fnous%2Fmaster%2Fnotebooks%2F02_tools_and_agents.livemd) [Tools & Agents](notebooks/02_tools_and_agents.livemd) | Custom tools, permissions, an interactive approval handler |
| [](https://livebook.dev/run?url=https%3A%2F%2Fraw.githubusercontent.com%2Fnyo16%2Fnous%2Fmaster%2Fnotebooks%2F03_rag_knowledge_base.livemd) [RAG & Knowledge Base](notebooks/03_rag_knowledge_base.livemd) | Ingest, retrieve, and query a knowledge base with Kino inputs |
See the [examples collection](examples/examples.md) for runnable scripts and [AGENTS.md](AGENTS.md) for coding-agent integration.
## Contributing
Contributions welcome. See [CONTRIBUTING.md](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](https://github.com/nyo16/nous/blob/master/LICENSE)
## Credits
- Inspired by [Pydantic AI](https://ai.pydantic.dev/) — Nous brings the
same agent-shaped API to Elixir, layered on OTP for supervision and
Phoenix for the UI story.
- HTTP: [Req](https://github.com/wojtekmach/req) + [Finch](https://github.com/sneako/finch)