A minimal ReAct-style agent that uses tools.
ReAct (Reason + Act) alternates between:
- Reasoning — the model decides what to do next.
- Acting — invoke a tool if needed.
- Observing — feed the tool's result back as a new message.
The loop continues until either:
- The model emits a final answer (no tool calls).
max_stepsis reached (default 8).
Conversation history
The agent maintains its own conversation; pass an optional
Candil.Conversation to start with a system prompt.
Stop words
If the model's response contains one of the configured stop words
(default "FINAL_ANSWER"), the loop terminates.
Example
defmodule MyApp.WeatherAgent do
use Candil.Agent,
name: "weather",
goal: "Answer weather questions",
tools: [Candil.MyTools.get_weather],
max_steps: 6
end
MyApp.WeatherAgent.run("What's the weather in Madrid?")
Summary
Functions
Run the agent synchronously. Returns {:ok, final_answer, trace} on
success or {:error, term()} on failure.
Types
Functions
Run the agent synchronously. Returns {:ok, final_answer, trace} on
success or {:error, term()} on failure.
Options
:backend—Candil.Backendmodule to use.:model— model id (string or atom).:max_steps— max loop iterations (default 8).:cancel_ref— cancellation ref fromCandil.Cancellation.new_ref/0.:conversation— pre-seeded conversation.