agent

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 0 Imported by: 0

README

OpenTelemetry Semantic Conventions for Agentic AI

This package provides semantic conventions for observability in multi-agent AI systems. It extends the OpenTelemetry Semantic Conventions for Generative AI with agent-specific concepts like workflows, tasks, handoffs, and tool calls.

Status

Development - These conventions are under active development and may change.

Model Files

The semantic conventions are defined in YAML format following the same structure as OpenTelemetry Semantic Conventions:

model/
├── registry.yaml   # Attribute definitions
├── spans.yaml      # Span type definitions
└── events.yaml     # Event type definitions

These YAML files serve as the source of truth and can be used to generate code for multiple languages or validate instrumentation.

Overview

Modern AI applications increasingly use multi-agent architectures where specialized agents collaborate to accomplish complex tasks. This package defines semantic conventions for observing these systems, complementing OpenTelemetry's existing gen_ai.* namespace.

Namespace Structure
gen_ai.agent.*              # Agent identity (aligns with OTel)
gen_ai.agent.workflow.*     # Workflow/session tracking
gen_ai.agent.task.*         # Task execution
gen_ai.agent.handoff.*      # Agent-to-agent communication
gen_ai.agent.tool_call.*    # Tool/function invocations
Relationship to OpenTelemetry GenAI Conventions

These conventions are designed to work alongside OpenTelemetry's GenAI semantic conventions:

OTel GenAI This Package Purpose
gen_ai.system - LLM provider identification
gen_ai.request.model - Model used for requests
gen_ai.usage.* gen_ai.usage.* (reused) Token/cost tracking
gen_ai.agent.id gen_ai.agent.id (aligned) Agent identification
gen_ai.agent.name gen_ai.agent.name (aligned) Agent naming
gen_ai.tool.* - Tool definitions/schemas
- gen_ai.agent.workflow.* Workflow orchestration
- gen_ai.agent.task.* Task execution tracking
- gen_ai.agent.handoff.* Agent communication
- gen_ai.agent.tool_call.* Tool execution (not definitions)

Conventions

Agent Attributes

Core agent identification attributes, aligned with OTel's gen_ai.agent.*:

Attribute Type Description Example
gen_ai.agent.id string Unique agent instance identifier "synthesis-agent-1"
gen_ai.agent.name string Human-readable agent name "Synthesis Agent"
gen_ai.agent.type string Agent role/function category "synthesis", "research"
gen_ai.agent.version string Agent implementation version "1.0.0"
Workflow Attributes

Workflows represent end-to-end processing sessions that may involve multiple agents and tasks:

Attribute Type Description Example
gen_ai.agent.workflow.id string Unique workflow identifier "wf-550e8400-..."
gen_ai.agent.workflow.name string Workflow type/name "statistics-extraction"
gen_ai.agent.workflow.status string Current status "running", "completed"
gen_ai.agent.workflow.parent_id string Parent workflow for nesting "wf-parent-123"
gen_ai.agent.workflow.initiator string What started the workflow "user:123", "api_key:abc"
gen_ai.agent.workflow.task.count int Total tasks in workflow 5
gen_ai.agent.workflow.task.completed_count int Completed task count 3
gen_ai.agent.workflow.task.failed_count int Failed task count 1
gen_ai.agent.workflow.duration int64 Duration in milliseconds 45000
Task Attributes

Tasks represent individual units of work performed by an agent:

Attribute Type Description Example
gen_ai.agent.task.id string Unique task identifier "task-123"
gen_ai.agent.task.name string Task name "extract_gdp_stats"
gen_ai.agent.task.type string Task category "extraction", "verification"
gen_ai.agent.task.status string Current status "running", "completed"
gen_ai.agent.task.parent_id string Parent task for nesting "task-parent-456"
gen_ai.agent.task.retry_count int Number of retry attempts 2
gen_ai.agent.task.duration int64 Duration in milliseconds 1500
gen_ai.agent.task.llm.call_count int LLM calls made 3
gen_ai.agent.task.tool_call.count int Tool calls made 5
gen_ai.agent.task.error.type string Error category if failed "timeout", "rate_limit"
gen_ai.agent.task.error.message string Error message if failed "API timeout after 30s"
Handoff Attributes

Handoffs represent communication between agents:

Attribute Type Description Example
gen_ai.agent.handoff.id string Unique handoff identifier "ho-789"
gen_ai.agent.handoff.type string Handoff type "request", "delegate"
gen_ai.agent.handoff.status string Current status "pending", "accepted"
gen_ai.agent.handoff.from.agent.id string Source agent ID "research-agent-1"
gen_ai.agent.handoff.from.agent.type string Source agent type "research"
gen_ai.agent.handoff.to.agent.id string Target agent ID "synthesis-agent-1"
gen_ai.agent.handoff.to.agent.type string Target agent type "synthesis"
gen_ai.agent.handoff.from.task.id string Source task ID "task-123"
gen_ai.agent.handoff.to.task.id string Target task ID "task-456"
gen_ai.agent.handoff.payload.size int Payload size in bytes 2048
gen_ai.agent.handoff.latency int64 Latency in milliseconds 50
gen_ai.agent.handoff.error.message string Error message if failed "Agent unavailable"
Tool Call Attributes

Tool calls represent invocations of external tools/functions by agents. This is distinct from OTel's gen_ai.tool.* which describes tool definitions/schemas.

Attribute Type Description Example
gen_ai.agent.tool_call.id string Unique invocation identifier "tc-abc123"
gen_ai.agent.tool_call.name string Tool name "web_search"
gen_ai.agent.tool_call.type string Tool category "search", "database"
gen_ai.agent.tool_call.status string Execution status "running", "completed"
gen_ai.agent.tool_call.duration int64 Duration in milliseconds 250
gen_ai.agent.tool_call.request.size int Request payload size 512
gen_ai.agent.tool_call.response.size int Response payload size 4096
gen_ai.agent.tool_call.retry_count int Retry attempts 1
gen_ai.agent.tool_call.error.type string Error category "network", "timeout"
gen_ai.agent.tool_call.error.message string Error message "Connection refused"
gen_ai.agent.tool_call.http.method string HTTP method if applicable "POST"
gen_ai.agent.tool_call.http.url string HTTP URL if applicable "https://api.example.com"
gen_ai.agent.tool_call.http.status_code int HTTP status code 200
Event Attributes

Events provide a generic mechanism for domain-specific observability:

Attribute Type Description Example
gen_ai.agent.event.id string Unique event identifier "evt-xyz"
gen_ai.agent.event.name string Event name/type "statistic.extracted"
gen_ai.agent.event.category string Event category "agent", "domain"
gen_ai.agent.event.source string Event source "synthesis-agent"
gen_ai.agent.event.severity string Severity level "info", "error"

Enumerated Values

Status Values

Used by workflow, task, handoff, and tool_call status attributes:

Value Description
pending Not yet started
running Currently executing
completed Successfully finished
failed Finished with error
cancelled Cancelled before completion

Additional handoff-specific status values:

Value Description
accepted Handoff accepted by target agent
rejected Handoff rejected by target agent
Handoff Types
Value Description
request Request for action/information
response Response to a previous request
broadcast Broadcast to multiple agents
delegate Delegation of responsibility
Error Types
Value Description
timeout Operation timed out
rate_limit Rate limit exceeded
validation Input validation failed
internal Internal error
network Network error
auth Authentication/authorization error
Event Categories
Value Description
agent Agent lifecycle events
workflow Workflow-level events
tool Tool-related events
domain Domain-specific events
system System-level events
Severity Levels
Value Description
debug Debug information
info Informational
warn Warning
error Error

Usage

Quick Start with Middleware

The easiest way to instrument your agent system is using the middleware package, which provides reusable helpers that minimize code changes:

import (
    "github.com/agentplexus/omniobserve/agentops"
    "github.com/agentplexus/omniobserve/agentops/middleware"
    _ "github.com/agentplexus/omniobserve/agentops/postgres"
)

// 1. Create a store
store, _ := agentops.Open("postgres", agentops.WithDSN(dsn))
defer store.Close()

// 2. Start a workflow (in orchestrator)
ctx, workflow, _ := middleware.StartWorkflow(ctx, store, "my-workflow",
    middleware.WithInitiator("user:123"),
)
defer middleware.CompleteWorkflow(ctx)

// 3. Instrument agent HTTP handlers (automatic task creation)
handler := middleware.AgentHandler(middleware.AgentHandlerConfig{
    AgentID:   "synthesis-agent",
    AgentType: "synthesis",
    Store:     store,
})(yourHandler)

// 4. Use instrumented client for inter-agent calls (automatic handoff tracking)
client := middleware.NewAgentClient(http.DefaultClient, middleware.AgentClientConfig{
    FromAgentID: "orchestrator",
    Store:       store,
})
resp, _ := client.PostJSON(ctx, "http://synthesis:8004/extract", body, "synthesis-agent")

// 5. Wrap tool calls (automatic timing and error tracking)
results, _ := middleware.ToolCall(ctx, "web_search", func() ([]Result, error) {
    return searchService.Search(query)
}, middleware.WithToolType("search"))
Middleware Components
Component Purpose Code Changes
middleware.StartWorkflow() Create workflow, attach to context ~3 lines in orchestrator
middleware.AgentHandler() Wrap HTTP handlers as tasks ~5 lines per agent
middleware.NewAgentClient() Track inter-agent calls as handoffs ~5 lines shared
middleware.ToolCall() Instrument tool/function calls ~3 lines per call site
Convenience Wrappers
// Search tools
results, _ := middleware.SearchToolCall(ctx, "web_search", query, searchFn)

// Database tools
rows, _ := middleware.DatabaseToolCall(ctx, "user_query", sql, queryFn)

// API tools
data, _ := middleware.APIToolCall(ctx, "weather_api", "GET", url, apiFn)

// With automatic retry tracking
result, _ := middleware.RetryToolCall(ctx, "flaky_api", 3, retryableFn)
Context Propagation

The middleware automatically propagates observability context:

  • Go context: Workflow, task, agent, and store attached to context.Context
  • HTTP headers: X-AgentOps-Workflow-ID, X-AgentOps-Task-ID, X-AgentOps-Agent-ID

This enables distributed tracing across agent boundaries without manual header management.

Direct Attribute Usage

For manual instrumentation or OpenTelemetry integration:

import (
    "github.com/agentplexus/omniobserve/semconv/agent"
    "go.opentelemetry.io/otel/attribute"
)

// Set span attributes
span.SetAttributes(
    attribute.String(agent.AgentID, "synthesis-agent-1"),
    attribute.String(agent.AgentType, "synthesis"),
    attribute.String(agent.WorkflowID, "wf-123"),
    attribute.String(agent.TaskName, "extract_statistics"),
    attribute.String(agent.TaskStatus, agent.StatusRunning),
)

// Record tool call
span.SetAttributes(
    attribute.String(agent.ToolCallID, "tc-456"),
    attribute.String(agent.ToolCallName, "web_search"),
    attribute.Int64(agent.ToolCallDuration, 250),
)

Compatibility

These conventions are designed to be compatible with:

References

License

Apache 2.0 - See LICENSE for details.

Documentation

Overview

Package agent provides OpenTelemetry semantic conventions for Agentic AI.

These conventions extend OpenTelemetry Semantic Conventions to support multi-agent systems, complementing the existing gen_ai.* namespace with agent-specific concepts like workflows, tasks, handoffs, and tool calls.

Namespace Structure

The conventions use a hierarchical namespace under gen_ai.agent.*:

gen_ai.agent.*              Aligned with OTel GenAI agent attributes
gen_ai.agent.workflow.*     Workflow/session-level attributes
gen_ai.agent.task.*         Task-level attributes
gen_ai.agent.handoff.*      Agent-to-agent communication
gen_ai.agent.tool_call.*    Tool/function invocation attributes
gen_ai.agent.event.*        Generic event attributes

Relationship to OpenTelemetry

This package is designed to work alongside OpenTelemetry's GenAI conventions:

  • gen_ai.agent.id, gen_ai.agent.name align with OTel's agent spans
  • gen_ai.usage.* attributes are reused for token/cost tracking
  • gen_ai.agent.tool_call.* is distinct from gen_ai.tool.* (definitions vs invocations)

Usage

Use the constants in this package when setting span attributes:

span.SetAttributes(
    attribute.String(agent.AgentID, "synthesis-agent-1"),
    attribute.String(agent.AgentType, "synthesis"),
    attribute.String(agent.TaskName, "extract_statistics"),
    attribute.String(agent.TaskStatus, agent.StatusRunning),
)

References

Index

Constants

View Source
const (
	// AgentID is the unique identifier of the agent instance.
	// Type: string
	// Example: "synthesis-agent-1", "verification-agent-2"
	AgentID = "gen_ai.agent.id"

	// AgentName is the human-readable name of the agent.
	// Type: string
	// Example: "Synthesis Agent", "Research Agent"
	AgentName = "gen_ai.agent.name"

	// AgentType categorizes the agent's role or function.
	// Type: string
	// Example: "synthesis", "verification", "research", "orchestration"
	AgentType = "gen_ai.agent.type"

	// AgentVersion is the version of the agent implementation.
	// Type: string
	// Example: "1.0.0", "2.1.3"
	AgentVersion = "gen_ai.agent.version"
)
View Source
const (
	// WorkflowID is the unique identifier of the workflow/session.
	// Type: string
	// Example: "wf-550e8400-e29b-41d4-a716-446655440000"
	WorkflowID = "gen_ai.agent.workflow.id"

	// WorkflowName is the name or type of the workflow.
	// Type: string
	// Example: "statistics-extraction", "document-analysis"
	WorkflowName = "gen_ai.agent.workflow.name"

	// WorkflowStatus is the current status of the workflow.
	// Type: string
	// Enum: "pending", "running", "completed", "failed", "cancelled"
	WorkflowStatus = "gen_ai.agent.workflow.status"

	// WorkflowParentID is the parent workflow ID for nested workflows.
	// Type: string
	WorkflowParentID = "gen_ai.agent.workflow.parent_id"

	// WorkflowInitiator identifies what initiated the workflow.
	// Type: string
	// Example: "user:123", "api_key:abc", "system:scheduler"
	WorkflowInitiator = "gen_ai.agent.workflow.initiator"

	// WorkflowTaskCount is the total number of tasks in the workflow.
	// Type: int
	WorkflowTaskCount = "gen_ai.agent.workflow.task.count"

	// WorkflowTaskCompletedCount is the number of completed tasks.
	// Type: int
	WorkflowTaskCompletedCount = "gen_ai.agent.workflow.task.completed_count"

	// WorkflowTaskFailedCount is the number of failed tasks.
	// Type: int
	WorkflowTaskFailedCount = "gen_ai.agent.workflow.task.failed_count"

	// WorkflowDuration is the total duration in milliseconds.
	// Type: int64
	WorkflowDuration = "gen_ai.agent.workflow.duration"
)
View Source
const (
	// TaskID is the unique identifier of the task.
	// Type: string
	TaskID = "gen_ai.agent.task.id"

	// TaskName is the human-readable name of the task.
	// Type: string
	// Example: "extract_gdp_statistics", "verify_sources"
	TaskName = "gen_ai.agent.task.name"

	// TaskType categorizes the type of task.
	// Type: string
	// Example: "extraction", "verification", "synthesis", "research"
	TaskType = "gen_ai.agent.task.type"

	// TaskStatus is the current status of the task.
	// Type: string
	// Enum: "pending", "running", "completed", "failed", "cancelled"
	TaskStatus = "gen_ai.agent.task.status"

	// TaskParentID links to the parent task for nested tasks.
	// Type: string
	TaskParentID = "gen_ai.agent.task.parent_id"

	// TaskRetryCount is the number of retry attempts.
	// Type: int
	TaskRetryCount = "gen_ai.agent.task.retry_count"

	// TaskDuration is the task duration in milliseconds.
	// Type: int64
	TaskDuration = "gen_ai.agent.task.duration"

	// TaskErrorType categorizes the error if the task failed.
	// Type: string
	// Example: "timeout", "rate_limit", "validation", "internal"
	TaskErrorType = "gen_ai.agent.task.error.type"

	// TaskErrorMessage is the error message if the task failed.
	// Type: string
	TaskErrorMessage = "gen_ai.agent.task.error.message"

	// TaskLLMCallCount is the number of LLM calls made during the task.
	// Type: int
	TaskLLMCallCount = "gen_ai.agent.task.llm.call_count"

	// TaskToolCallCount is the number of tool calls made during the task.
	// Type: int
	TaskToolCallCount = "gen_ai.agent.task.tool_call.count"
)
View Source
const (
	// HandoffID is the unique identifier of the handoff.
	// Type: string
	HandoffID = "gen_ai.agent.handoff.id"

	// HandoffType categorizes the type of handoff.
	// Type: string
	// Enum: "request", "response", "broadcast", "delegate"
	HandoffType = "gen_ai.agent.handoff.type"

	// HandoffStatus is the current status of the handoff.
	// Type: string
	// Enum: "pending", "accepted", "rejected", "completed", "failed"
	HandoffStatus = "gen_ai.agent.handoff.status"

	// HandoffFromAgentID is the agent initiating the handoff.
	// Type: string
	HandoffFromAgentID = "gen_ai.agent.handoff.from.agent.id"

	// HandoffFromAgentType is the type of the source agent.
	// Type: string
	HandoffFromAgentType = "gen_ai.agent.handoff.from.agent.type"

	// HandoffToAgentID is the agent receiving the handoff.
	// Type: string
	HandoffToAgentID = "gen_ai.agent.handoff.to.agent.id"

	// HandoffToAgentType is the type of the target agent.
	// Type: string
	HandoffToAgentType = "gen_ai.agent.handoff.to.agent.type"

	// HandoffFromTaskID is the task ID in the source agent.
	// Type: string
	HandoffFromTaskID = "gen_ai.agent.handoff.from.task.id"

	// HandoffToTaskID is the task ID in the target agent.
	// Type: string
	HandoffToTaskID = "gen_ai.agent.handoff.to.task.id"

	// HandoffPayloadSize is the size of the handoff payload in bytes.
	// Type: int
	HandoffPayloadSize = "gen_ai.agent.handoff.payload.size"

	// HandoffLatency is the time from initiation to acceptance in ms.
	// Type: int64
	HandoffLatency = "gen_ai.agent.handoff.latency"

	// HandoffErrorMessage is the error message if handoff failed.
	// Type: string
	HandoffErrorMessage = "gen_ai.agent.handoff.error.message"
)
View Source
const (
	// ToolCallID is the unique identifier of the tool invocation.
	// Type: string
	ToolCallID = "gen_ai.agent.tool_call.id"

	// ToolCallName is the name of the tool being invoked.
	// Type: string
	// Example: "web_search", "database_query", "api_call"
	ToolCallName = "gen_ai.agent.tool_call.name"

	// ToolCallType categorizes the type of tool.
	// Type: string
	// Example: "search", "database", "api", "file", "compute"
	ToolCallType = "gen_ai.agent.tool_call.type"

	// ToolCallStatus is the status of the tool invocation.
	// Type: string
	// Enum: "running", "completed", "failed"
	ToolCallStatus = "gen_ai.agent.tool_call.status"

	// ToolCallDuration is the duration of the tool invocation in ms.
	// Type: int64
	ToolCallDuration = "gen_ai.agent.tool_call.duration"

	// ToolCallRequestSize is the size of the request payload in bytes.
	// Type: int
	ToolCallRequestSize = "gen_ai.agent.tool_call.request.size"

	// ToolCallResponseSize is the size of the response payload in bytes.
	// Type: int
	ToolCallResponseSize = "gen_ai.agent.tool_call.response.size"

	// ToolCallRetryCount is the number of retry attempts.
	// Type: int
	ToolCallRetryCount = "gen_ai.agent.tool_call.retry_count"

	// ToolCallErrorType categorizes the error if the tool call failed.
	// Type: string
	ToolCallErrorType = "gen_ai.agent.tool_call.error.type"

	// ToolCallErrorMessage is the error message if the tool call failed.
	// Type: string
	ToolCallErrorMessage = "gen_ai.agent.tool_call.error.message"

	// ToolCallHTTPMethod is the HTTP method used (for HTTP-based tools).
	// Type: string
	ToolCallHTTPMethod = "gen_ai.agent.tool_call.http.method"

	// ToolCallHTTPURL is the URL called (for HTTP-based tools).
	// Type: string
	ToolCallHTTPURL = "gen_ai.agent.tool_call.http.url"

	// ToolCallHTTPStatusCode is the HTTP status code returned.
	// Type: int
	ToolCallHTTPStatusCode = "gen_ai.agent.tool_call.http.status_code"
)
View Source
const (
	// EventID is the unique identifier of the event.
	// Type: string
	EventID = "gen_ai.agent.event.id"

	// EventName is the name/type of the event.
	// Type: string
	// Example: "agent.task.started", "agent.handoff.completed"
	EventName = "gen_ai.agent.event.name"

	// EventCategory categorizes the event.
	// Type: string
	// Example: "agent", "workflow", "tool", "domain", "system"
	EventCategory = "gen_ai.agent.event.category"

	// EventSource identifies the source of the event.
	// Type: string
	// Example: "synthesis-agent", "orchestrator"
	EventSource = "gen_ai.agent.event.source"

	// EventSeverity is the severity level of the event.
	// Type: string
	// Enum: "debug", "info", "warn", "error"
	EventSeverity = "gen_ai.agent.event.severity"
)
View Source
const (
	// GenAISystem identifies the GenAI system (reused from OTel).
	// Type: string
	// Example: "openai", "anthropic", "google_ai"
	GenAISystem = "gen_ai.system"

	// GenAIRequestModel is the model used for the request.
	// Type: string
	// Example: "gpt-4", "claude-3-opus", "gemini-pro"
	GenAIRequestModel = "gen_ai.request.model"

	// GenAIUsageInputTokens is the number of input/prompt tokens.
	// Type: int
	GenAIUsageInputTokens = "gen_ai.usage.input_tokens" //nolint:gosec // Not a credential, semantic convention attribute name

	// GenAIUsageOutputTokens is the number of output/completion tokens.
	// Type: int
	GenAIUsageOutputTokens = "gen_ai.usage.output_tokens" //nolint:gosec // Not a credential, semantic convention attribute name

	// GenAIUsageTotalTokens is the total tokens (input + output).
	// Type: int
	GenAIUsageTotalTokens = "gen_ai.usage.total_tokens" //nolint:gosec // Not a credential, semantic convention attribute name

	// GenAIUsageCost is the cost in USD.
	// Type: float64
	GenAIUsageCost = "gen_ai.usage.cost"
)
View Source
const (
	StatusPending   = "pending"
	StatusRunning   = "running"
	StatusCompleted = "completed"
	StatusFailed    = "failed"
	StatusCancelled = "cancelled"
	StatusAccepted  = "accepted"
	StatusRejected  = "rejected"
)

Status values for workflow, task, and handoff status attributes.

View Source
const (
	HandoffTypeRequest   = "request"
	HandoffTypeResponse  = "response"
	HandoffTypeBroadcast = "broadcast"
	HandoffTypeDelegate  = "delegate"
)
View Source
const (
	ErrorTypeTimeout    = "timeout"
	ErrorTypeRateLimit  = "rate_limit"
	ErrorTypeValidation = "validation"
	ErrorTypeInternal   = "internal"
	ErrorTypeNetwork    = "network"
	ErrorTypeAuth       = "auth"
)
View Source
const (
	EventCategoryAgent    = "agent"
	EventCategoryWorkflow = "workflow"
	EventCategoryTool     = "tool"
	EventCategoryDomain   = "domain"
	EventCategorySystem   = "system"
)
View Source
const (
	SeverityDebug = "debug"
	SeverityInfo  = "info"
	SeverityWarn  = "warn"
	SeverityError = "error"
)
View Source
const (
	EventNameTaskStarted       = "gen_ai.agent.task.started"
	EventNameTaskCompleted     = "gen_ai.agent.task.completed"
	EventNameTaskFailed        = "gen_ai.agent.task.failed"
	EventNameHandoffInitiated  = "gen_ai.agent.handoff.initiated"
	EventNameHandoffCompleted  = "gen_ai.agent.handoff.completed"
	EventNameToolCallInvoked   = "gen_ai.agent.tool_call.invoked"
	EventNameToolCallCompleted = "gen_ai.agent.tool_call.completed"
	EventNameWorkflowStarted   = "gen_ai.agent.workflow.started"
	EventNameWorkflowCompleted = "gen_ai.agent.workflow.completed"
	EventNameRetryAttempted    = "gen_ai.agent.retry.attempted"
)

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL