AgentObs. Events
(agent_obs v0.1.5)
View Source
Defines and validates standardized event schemas for AgentObs.
This module provides the core event schema that is backend-agnostic and represents the contract between instrumentation code and handler implementations.
Event Types
AgentObs supports four primary event types:
:agent- Agent loop or invocation tracking:tool- Tool call execution tracking:llm- LLM API call tracking:prompt- Prompt template rendering tracking
Event Phases
Each event type has three phases:
:start- Emitted when the operation begins:stop- Emitted when the operation completes successfully:exception- Emitted when the operation fails
Metadata Structures
Each event type and phase combination has a standardized metadata structure. See individual functions for details.
Summary
Functions
Returns the list of supported event phases.
Returns the list of supported event types.
Normalizes event metadata, converting values to standard formats.
Validates event metadata for a given event type and phase.
Types
Functions
@spec event_phases() :: [event_phase()]
Returns the list of supported event phases.
@spec event_types() :: [event_type()]
Returns the list of supported event types.
@spec normalize_metadata(event_type(), event_phase(), metadata()) :: metadata()
Normalizes event metadata, converting values to standard formats.
This includes:
- Converting atom keys to strings where appropriate
- Normalizing role atoms to strings
- Ensuring consistent data types
Examples
iex> AgentObs.Events.normalize_metadata(:llm, :start, %{model: "gpt-4", input_messages: [%{role: :user, content: "Hi"}]})
%{model: "gpt-4", input_messages: [%{role: "user", content: "Hi"}]}
@spec validate_event(event_type(), event_phase(), metadata()) :: validation_result()
Validates event metadata for a given event type and phase.
Returns :ok if metadata is valid, {:error, reason} otherwise.
Examples
iex> AgentObs.Events.validate_event(:agent, :start, %{name: "my_agent", input: "task"})
:ok
iex> AgentObs.Events.validate_event(:agent, :start, %{name: "my_agent"})
{:error, "Missing required field: input"}