View Source README

Jido (自動)

自動 (Jido) - A flexible framework for building distributed Agents and Workflows in Elixir.

Hex Version Hex Docs CI Status Apache 2 License

Features

  • Actions: Discrete, composable units of functionality with consistent interfaces
  • Workflows: Robust execution runtime with logging, telemetry, and error handling
  • Agents: Stateful autonomous entities that can plan and execute workflows
  • Sensors: Event-driven data gathering components
  • Signals: Cloud Events-based messaging between components
  • Flexible Planning: Pluggable planners for agent decision making
  • Comprehensive Testing: Rich testing tools and helpers
  • Observable: Built-in telemetry and debugging tools

Installation

Add jido to your dependencies in mix.exs:

def deps do
  [
    {:jido, "~> 0.1.0"}
  ]
end

Getting Started

Creating an Action

Actions are the basic building blocks in Jido. Here's a simple arithmetic action:

defmodule MyApp.Actions.Add do
  use Jido.Action,
    name: "add",
    description: "Adds two numbers",
    schema: [
      value: [type: :number, required: true],
      amount: [type: :number, required: true]
    ]

  @impl true 
  def run(%{value: value, amount: amount}, _context) do
    {:ok, %{result: value + amount}}
  end
end

Creating a Simple Agent

Agents combine actions into autonomous behaviors:

defmodule MyApp.SimpleAgent do
  use Jido.Agent,
    name: "SimpleBot",
    description: "A simple agent that performs basic tasks",
    schema: [
      location: [type: :atom, default: :home],
      battery_level: [type: :integer, default: 100]
    ]

  @impl true
  def plan(%__MODULE__{} = agent) do
    {:ok,
     %Jido.ActionSet{
       agent: agent,
       plan: [
         {MyApp.Actions.Basic.Log, message: "Hello, world!"},
         {MyApp.Actions.Basic.Sleep, duration: 50},
         {MyApp.Actions.Basic.Log, message: "Goodbye, world!"}
       ]
     }}
  end
end

Starting an Agent Worker

Start an agent worker under your supervision tree:

# In your application.ex
children = [
  {Registry, keys: :unique, name: Jido.AgentRegistry},
  {Jido.Agent.Supervisor, pubsub: MyApp.PubSub}
]

# Start an agent instance
{:ok, pid} = Jido.Agent.Worker.start_link(MyApp.SimpleAgent.new())

Contributing

We welcome contributions! Please feel free to submit a PR.

To run tests:

mix test

License

Apache License 2.0 - See LICENSE.md for details.