Jido (Jido v2.0.0-rc.4)
View Source自動 (Jido) - A foundational framework for building autonomous, distributed agent systems in Elixir.
Quick Start
Create a Jido supervisor in your application:
defmodule MyApp.Jido do
use Jido, otp_app: :my_app
endAdd to your supervision tree:
children = [MyApp.Jido]Start and manage agents:
{:ok, pid} = MyApp.Jido.start_agent(MyAgent, id: "agent-1")
pid = MyApp.Jido.whereis("agent-1")
agents = MyApp.Jido.list_agents()
:ok = MyApp.Jido.stop_agent("agent-1")Core Concepts
Jido agents are immutable data structures. The core operation is cmd/2:
{agent, directives} = MyAgent.cmd(agent, MyAction)- Agents — Immutable structs updated via commands
- Actions — Functions that transform agent state (may perform side effects)
- Directives — Descriptions of external effects (signals, processes, etc.)
For Tests
Use JidoTest.Case for isolation:
defmodule MyAgentTest do
use JidoTest.Case, async: true
test "agent works", %{jido: jido} do
{:ok, pid} = Jido.start_agent(jido, MyAgent)
# ...
end
endSee Jido.Agent for defining agents and Jido.Await for coordination.
Summary
Functions
Creates a Jido supervisor module.
Returns the count of running agents in a Jido instance.
Returns the AgentPool name for a specific pool in a Jido instance.
Returns the AgentSupervisor name for a Jido instance.
Check if an agent process is alive and responding.
Wait for an agent to reach a terminal status.
Wait for all agents to reach terminal status.
Wait for any agent to reach terminal status.
Wait for a child agent to reach a terminal status.
Request graceful cancellation of an agent.
Returns the default Jido instance name.
Generate a unique identifier.
Gets an Action by its slug.
Get a specific child's PID by tag.
Get the PIDs of all children of a parent agent.
Gets a Plugin by its slug.
Gets a Sensor by its slug.
Hibernate an agent using the given Jido instance.
Lists discovered Actions with optional filtering.
Lists all agents running in a Jido instance.
Lists discovered Demos with optional filtering.
Lists discovered Plugins with optional filtering.
Lists discovered Sensors with optional filtering.
Refreshes the Discovery catalog.
Returns the Registry name for a Jido instance.
Returns the Scheduler name for a Jido instance.
Start the default Jido instance for scripts and Livebook.
Starts an agent under a specific Jido instance.
Starts a Jido instance supervisor.
Stop a Jido instance.
Stops an agent by pid or id.
Returns the TaskSupervisor name for a Jido instance.
Thaw an agent using the given Jido instance.
Looks up an agent by ID in a Jido instance's registry.
Types
Functions
Creates a Jido supervisor module.
Options
:otp_app- Required. Your application name (e.g.,:my_app).
Example
defmodule MyApp.Jido do
use Jido, otp_app: :my_app
endThen add to your supervision tree in lib/my_app/application.ex:
children = [MyApp.Jido]Optionally configure in config/config.exs to customize defaults:
config :my_app, MyApp.Jido,
max_tasks: 2000,
agent_pools: []
@spec agent_count(atom()) :: non_neg_integer()
Returns the count of running agents in a Jido instance.
Examples
count = Jido.agent_count(MyApp.Jido)
# => 5
Returns the AgentPool name for a specific pool in a Jido instance.
Returns the AgentSupervisor name for a Jido instance.
Check if an agent process is alive and responding.
See Jido.Await.alive?/1 for details.
Wait for an agent to reach a terminal status.
See Jido.Await.completion/3 for details.
Wait for all agents to reach terminal status.
See Jido.Await.all/3 for details.
Wait for any agent to reach terminal status.
See Jido.Await.any/3 for details.
Wait for a child agent to reach a terminal status.
See Jido.Await.child/4 for details.
Request graceful cancellation of an agent.
See Jido.Await.cancel/2 for details.
@spec default_instance() :: atom()
Returns the default Jido instance name.
Used by Jido.start/1 for scripts and Livebook quick-start.
Generate a unique identifier.
Delegates to Jido.Util.generate_id/0.
Gets an Action by its slug.
Get a specific child's PID by tag.
See Jido.Await.get_child/2 for details.
Get the PIDs of all children of a parent agent.
See Jido.Await.get_children/1 for details.
Gets a Plugin by its slug.
Gets a Sensor by its slug.
@spec hibernate(atom(), Jido.Agent.t()) :: :ok | {:error, term()}
Hibernate an agent using the given Jido instance.
Lists discovered Actions with optional filtering.
Lists all agents running in a Jido instance.
Returns a list of {id, pid} tuples.
Examples
agents = Jido.list_agents(MyApp.Jido)
# => [{"agent-1", #PID<0.123.0>}, {"agent-2", #PID<0.124.0>}]
Lists discovered Demos with optional filtering.
Lists discovered Plugins with optional filtering.
Lists discovered Sensors with optional filtering.
Refreshes the Discovery catalog.
Returns the Registry name for a Jido instance.
Returns the Scheduler name for a Jido instance.
Start the default Jido instance for scripts and Livebook.
This is an idempotent convenience function - safe to call multiple times
(returns {:ok, pid} even if already started).
Examples
# In a script or Livebook
{:ok, _} = Jido.start()
{:ok, pid} = Jido.start_agent(Jido.default_instance(), MyAgent)
# With custom options
{:ok, _} = Jido.start(max_tasks: 2000)Options
Same as start_link/1, but :name defaults to Jido.Default.
@spec start_agent(atom(), module() | struct(), keyword()) :: DynamicSupervisor.on_start_child()
Starts an agent under a specific Jido instance.
Examples
{:ok, pid} = Jido.start_agent(MyApp.Jido, MyAgent)
{:ok, pid} = Jido.start_agent(MyApp.Jido, MyAgent, id: "custom-id")
Starts a Jido instance supervisor.
Options
:name- Required. The name of this Jido instance (e.g.,MyApp.Jido)
Example
{:ok, pid} = Jido.start_link(name: MyApp.Jido)
@spec stop(atom()) :: :ok
Stop a Jido instance.
Defaults to stopping the default instance (Jido.Default).
Examples
Jido.stop()
Jido.stop(MyApp.Jido)
Stops an agent by pid or id.
Examples
:ok = Jido.stop_agent(MyApp.Jido, pid)
:ok = Jido.stop_agent(MyApp.Jido, "agent-id")
Returns the TaskSupervisor name for a Jido instance.
@spec thaw(atom(), module(), term()) :: {:ok, Jido.Agent.t()} | :not_found | {:error, term()}
Thaw an agent using the given Jido instance.
Looks up an agent by ID in a Jido instance's registry.
Returns the pid if found, nil otherwise.
Examples
pid = Jido.whereis(MyApp.Jido, "agent-123")