AgentObs.Events (agent_obs v0.1.6)

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

event_phase()

@type event_phase() :: :start | :stop | :exception

event_type()

@type event_type() :: :agent | :tool | :llm | :prompt

metadata()

@type metadata() :: map()

validation_result()

@type validation_result() :: :ok | {:error, String.t()}

Functions

event_phases()

@spec event_phases() :: [event_phase()]

Returns the list of supported event phases.

event_types()

@spec event_types() :: [event_type()]

Returns the list of supported event types.

normalize_metadata(event_type, phase, metadata)

@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"}]}

validate_event(event_type, phase, metadata)

@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"}