Base event structure for agent communication.
Events are the primary mechanism for communication between agents in the Mojentic agent system. Each event carries information about its source, a correlation ID for tracking related events, and any domain-specific data.
Fields
source- The module of the agent that created this eventcorrelation_id- UUID for tracking related events in a workflow- Additional fields defined by specific event types
Examples
defmodule MyApp.Events.QuestionEvent do
use Mojentic.Event
@type t :: %__MODULE__{
source: module(),
correlation_id: String.t() | nil,
question: String.t()
}
defstruct [:source, :correlation_id, :question]
end
event = %MyApp.Events.QuestionEvent{
source: MyApp.QuestionAgent,
correlation_id: UUID.uuid4(),
question: "What is Elixir?"
}
Summary
Functions
Defines a module as an event type with required base fields.
Creates a new event with an auto-generated correlation ID if not provided.
Types
Functions
Defines a module as an event type with required base fields.
When you use Mojentic.Event, your module gets:
- Base fields:
sourceandcorrelation_id - These fields must be included in your struct definition
Example
defmodule MyEvent do
use Mojentic.Event
defstruct [:source, :correlation_id, :custom_field]
end
Creates a new event with an auto-generated correlation ID if not provided.
Parameters
module- The event module to createattrs- Keyword list or map of attributes
Examples
Mojentic.Event.new(QuestionEvent, source: MyAgent, question: "Hello?")
#=> %QuestionEvent{source: MyAgent, correlation_id: "...", question: "Hello?"}