Allbert Assist — Jido Agent Demo
Mix.install(
[
{:jido, "~> 2.2"},
{:jido_action, "~> 2.2"},
{:jido_signal, "~> 2.1"},
{:jido_ai, "~> 2.1"}
],
config: [
jido_ai: [
model_aliases: %{
fast: "anthropic:claude-haiku-4-5",
capable: "anthropic:claude-sonnet-4-5",
local: "ollama:llama3.1"
}
],
req_llm: [
anthropic_api_key: System.get_env("LB_ANTHROPIC_API_KEY") || System.get_env("ANTHROPIC_API_KEY"),
openai_api_key: System.get_env("LB_OPENAI_API_KEY") || System.get_env("OPENAI_API_KEY"),
ollama_base_url: System.get_env("LB_OLLAMA_BASE_URL") || "http://localhost:11434"
]
]
)
1. Define a Tool (Jido.Action)
A Jido.Action is a pure, validated function the agent can call. Schemas
use Zoi for input validation.
defmodule Demo.Actions.Multiply do
use Jido.Action,
name: "multiply",
description: "Multiply two integers and return the product.",
schema: Zoi.object(%{a: Zoi.integer(), b: Zoi.integer()})
@impl true
def run(%{a: a, b: b}, _context), do: {:ok, %{product: a * b}}
end
# Direct call without an agent
Demo.Actions.Multiply.run(%{a: 6, b: 7}, %{})
2. Define an AI Agent
A Jido.AI.Agent wraps an LLM and a list of tools. The model alias :fast
resolves through config :jido_ai, :model_aliases.
defmodule Demo.Agent do
use Jido.AI.Agent,
name: "demo_agent",
description: "Demo agent that does arithmetic via tools.",
model: :fast,
tools: [Demo.Actions.Multiply],
system_prompt: """
You are a friendly assistant. When the user asks for arithmetic,
use the available tools rather than computing in your head.
"""
end
3. Run the Agent
Set ANTHROPIC_API_KEY (or another provider key) in Livebook’s secrets
panel before running this cell.
{:ok, pid} = Jido.AgentServer.start(agent: Demo.Agent)
{:ok, result} = Demo.Agent.ask_sync(pid, "What is 137 * 42?")
result
4. Streaming a Response
{:ok, stream} = Jido.AI.stream_text("Explain Phoenix LiveView in two sentences.", model: :fast)
stream |> Enum.each(&IO.write/1)
5. Structured Output
schema =
Zoi.object(%{
title: Zoi.string(),
bullets: Zoi.array(Zoi.string())
})
Jido.AI.generate_object(
"Summarize the Erlang BEAM in three short bullet points.",
schema,
model: :fast
)