core beginner

Counter Agent

A real Jido agent that counts up and down using Actions, Signals, and signal routing. Demonstrates the core agent pattern: immutable state, validated actions, and LiveView integration.

getting-started state actions signals

Related guides and notebooks

lib/agent_jido/demos/counter/actions/increment_action.ex 18 lines
defmodule AgentJido.Demos.Counter.IncrementAction do
  @moduledoc """
  Increments the counter by a specified amount.
  """
  use Jido.Action,
    name: "increment",
    description: "Increments the counter",
    schema: [
      by: [type: :integer, default: 1, doc: "Amount to increment by"]
    ]

  @impl true
  def run(%{by: amount}, context) do
    current = Map.get(context.state, :count, 0)
    {:ok, %{count: current + amount}}
  end
end