View Source Jido.Agent.Runtime.PubSub (Jido v1.0.0-rc.5)
Handles PubSub event management for Jido Agent Runtimes.
This module provides functionality for:
- Event emission
- Topic management
- Event subscription
- Signal generation
- Signal processing
All events are broadcast through Phoenix.PubSub and follow a consistent format using Jido.Signal structs.
Summary
Functions
Emits an event to the agent's topic.
Generates a full topic string for an agent ID.
Subscribes the current process to an agent's topic.
Unsubscribes the current process from an agent's topic.
Functions
@spec emit(Jido.Agent.Runtime.State.t(), atom(), map()) :: :ok | {:error, term()}
Emits an event to the agent's topic.
Parameters
- state: The Runtime state
- event_type: The type of event to emit
- payload: The event payload
Returns
- on successful emission
- on failure
Examples
PubSub.emit(state, :started, %{agent_id: "agent-123"})
PubSub.emit(state, :state_changed, %{from: :idle, to: :running})
Generates a full topic string for an agent ID.
Parameters
- agent_id: The unique identifier for the agent
Returns
- String topic in format "jido.agent.{agent_id}"
Examples
iex> PubSub.generate_topic("agent-123")
"jido.agent.agent-123"
@spec subscribe(Jido.Agent.Runtime.State.t()) :: :ok | {:error, term()}
Subscribes the current process to an agent's topic.
Parameters
- state: The Runtime state containing PubSub configuration
Returns
- :ok on successful subscription
- on failure
@spec unsubscribe(Jido.Agent.Runtime.State.t()) :: :ok | {:error, term()}
Unsubscribes the current process from an agent's topic.
Parameters
- state: The Runtime state containing PubSub configuration
Returns
- :ok on successful unsubscription
- on failure