githubEdit

eyeAgent Events Overview

Understanding the agent event system architecture and how events flow through your application.

Architecture

The event system is built on a centralized EventBus managed by the AgentControlHub. Events flow through a structured pipeline:

Agent Action

AgentControlHub

EventBus.Publish()

Registered Handlers

Key Components

EventBus

The EventBus is a generic publish-subscribe system that:

  • Manages typed event subscriptions

  • Dispatches events to registered handlers

  • Provides automatic type checking

  • Returns IDisposable subscriptions for cleanup

AgentControlHub

The control hub serves as the central dispatcher:

  • Receives events from various agent subsystems

  • Publishes events to the EventBus

  • Also notifies the IAgentEventListener interface (if provided)

  • Manages agent status transitions

IEvent Interface

All events implement the IEvent marker interface:

This allows the EventBus to handle any event type generically while maintaining type safety.

Event Flow

1. Agent Actions Generate Events

When an agent performs an action, it generates corresponding events:

2. Events Are Dispatched

The control hub publishes events to the EventBus:

3. Handlers Are Invoked

All registered handlers for that event type are called:

Event Listeners vs Event Registration

The agent supports two event notification patterns:

Generic, type-safe event subscription:

Advantages:

  • Subscribe to specific events only

  • Type-safe event handling

  • Easy to unsubscribe

  • Supports multiple handlers per event

  • No interface implementation required

2. IAgentEventListener (Interface-based)

Implement the IAgentEventListener interface to receive all agent events:

Advantages:

  • Receive all events in one place

  • Structured interface

  • Good for comprehensive monitoring

Disadvantages:

  • Must implement all interface methods

  • Less flexible than selective subscription

Event Timing

Events are dispatched synchronously on the calling thread. For async operations:

Event Categories

Lifecycle Events

Events that track the agent's operational state:

  • AgentStatusChanged - Status transitions

Conversation Events

Events related to conversation management:

  • Creation, loading, deletion

  • Title and summary updates

  • Item loading

Tool Events

Events during tool execution:

  • ToolCall - Tool invocation by agent

  • ToolStatusEvent - Execution status updates

  • ToolOutputEvent - Tool results

  • McpApprovalRequest - MCP tool approval request

Streaming Events (Deltas)

Real-time content updates:

  • Delta<ITextChunk> - Text streaming

  • Delta<IImageChunk> - Image streaming

  • Delta<IAudioChunk> - Audio streaming

  • Delta<IAnnotationChunk> - Annotation streaming

Audio Events

Audio-specific events:

  • AudioBufferStateChanged - Buffer state transitions

  • AudioRateLimitsUpdated - Rate limit changes

Metadata Events

General agent metadata:

  • Usage - Token usage

  • Exception - Errors

Best Practices

✅ Do

  • Use RegisterEvent<T>() for selective event handling

  • Dispose subscriptions when no longer needed

  • Handle exceptions within event handlers

  • Use async handlers when needed

  • Check event properties before accessing

❌ Don't

  • Subscribe to events you don't need

  • Forget to dispose event subscriptions

  • Throw unhandled exceptions in handlers

  • Block the event thread with long operations

  • Assume event delivery order

Example: Event Monitoring System

Next Steps

Last updated