Jido behaviour (Jido v1.1.0-rc.2)
View Source自動 (Jido) - A foundational framework for building autonomous, distributed agent systems in Elixir.
This module provides the main interface for interacting with Jido components, including:
- Managing and interacting with Agents through a high-level API
- Listing and retrieving Actions, Sensors, and Domains
- Filtering and paginating results
- Generating unique slugs for components
Agent Interaction Examples
# Find and act on an agent
"agent-id"
|> Jido.get_agent_by_id()
|> Jido.act(:command, %{param: "value"})
# Act asynchronously
{:ok, agent} = Jido.get_agent_by_id("agent-id")
Jido.act_async(agent, :command)
# Send management commands
{:ok, agent} = Jido.get_agent_by_id("agent-id")
Jido.manage(agent, :pause)
Summary
Functions
Clones an existing agent with a new ID.
Callback used by the generated start_link/0
function.
This is where we actually call Jido.Supervisor.start_link.
Retrieves a running Agent by its ID.
Pipe-friendly version of get_agent that raises on errors.
Gets the current state of an agent.
Types
Callbacks
@callback config() :: keyword()
Functions
@spec clone_agent(String.t() | atom(), String.t() | atom(), keyword()) :: {:ok, pid()} | {:error, term()}
Clones an existing agent with a new ID.
Parameters
source_id
: ID of the agent to clonenew_id
: ID for the new cloned agentopts
: Optional keyword list of options to override for the new agent
Returns
{:ok, pid}
with the new agent's process ID{:error, reason}
if cloning fails
Examples
iex> {:ok, new_pid} = Jido.clone_agent("source-agent", "cloned-agent")
{:ok, #PID<0.125.0>}
@spec ensure_started(module()) :: Supervisor.on_start()
Callback used by the generated start_link/0
function.
This is where we actually call Jido.Supervisor.start_link.
Retrieves a running Agent by its ID.
Parameters
id
: String or atom ID of the agent to retrieveopts
: Optional keyword list of options::registry
: Override the default agent registry
Returns
{:ok, pid}
if agent is found and running{:error, :not_found}
if agent doesn't exist
Examples
iex> {:ok, agent} = Jido.get_agent("my-agent")
{:ok, #PID<0.123.0>}
# Using a custom registry
iex> {:ok, agent} = Jido.get_agent("my-agent", registry: MyApp.Registry)
{:ok, #PID<0.123.0>}
Pipe-friendly version of get_agent that raises on errors.
Parameters
id
: String or atom ID of the agent to retrieveopts
: Optional keyword list of options::registry
: Override the default agent registry
Returns
pid
if agent is found- Raises
RuntimeError
if agent not found
Examples
iex> "my-agent" |> Jido.get_agent!() |> Jido.cmd(:command)
:ok
Gets the current state of an agent.
Parameters
agent_or_id
: Agent pid, ID, or return value from get_agent
Returns
{:ok, state}
with the agent's current state{:error, reason}
if state couldn't be retrieved
Examples
iex> {:ok, state} = Jido.get_agent_state("my-agent")
{:ok, %Jido.Agent.Server.State{...}}