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/counter_agent.ex 27 lines
defmodule AgentJido.Demos.CounterAgent do
  @moduledoc """
  A simple counter agent demonstrating core Jido concepts:
  - Agent as immutable data structure
  - Actions with validated params
  - Signals and signal routing
  - Direct strategy (synchronous execution)
  """
  use Jido.Agent,
    name: "counter_agent",
    description: "Simple counter demonstration",
    schema: [
      count: [type: :integer, default: 0]
    ]

  alias AgentJido.Demos.Counter.{IncrementAction, DecrementAction, ResetAction}

  @impl true
  def signal_routes(_ctx) do
    [
      {"counter.increment", IncrementAction},
      {"counter.decrement", DecrementAction},
      {"counter.reset", ResetAction}
    ]
  end
end