Skip to content

Conversation

Copy link

Copilot AI commented Jun 10, 2025

This PR integrates CloudEvents support into the OAgents abstraction library while maintaining full backward compatibility with existing Event-based code.

Changes Made

Enhanced Event Class

The Event class now wraps CloudNative.CloudEvents.CloudEvent internally while preserving the existing API:

// Traditional usage still works
var evt = new Event
{
    Type = "user.action",
    Subject = "user-123", 
    Data = new Dictionary<string, string> { { "action", "login" } }
};

// New CloudEvent usage
var cloudEvent = new CloudEvent
{
    Type = "com.example.user.login",
    Source = new Uri("https://example.com/users"),
    Id = Guid.NewGuid().ToString(),
    Subject = "user-123",
    Data = new Dictionary<string, string> { { "action", "login" } }
};

// Seamless conversion between types
Event convertedEvent = cloudEvent; // Implicit conversion
CloudEvent backToCloudEvent = convertedEvent.CloudEvent;

Extended IAgent Interface

Added CloudEvent overloads alongside existing Event methods:

public interface IAgent
{
    // Existing Event methods (unchanged)
    Task HandleEvent(Event item);
    Task PublishEvent(string ns, string id, Event item);
    
    // New CloudEvent methods
    Task HandleEvent(CloudEvent item);
    Task PublishEvent(string ns, string id, CloudEvent item);
}

Updated Base Implementations

  • Orleans Agent: Supports CloudEvent with automatic conversion to Event for stream processing
  • Dapr Agent: Publishes CloudEvents directly with proper metadata for Dapr pub/sub

Package Dependencies

  • Added CloudNative.CloudEvents to Core, Orleans, and Dapr projects
  • Uses CloudEvents v2.8.0 for latest standards compliance

Benefits

  1. Standards Compliance: Follows CNCF CloudEvents specification
  2. Interoperability: Works with other CloudEvents-compliant systems
  3. Rich Metadata: Supports Source, Time, Id, and other CloudEvent properties
  4. Future-Proof: Aligns with industry event standards
  5. Zero Breaking Changes: All existing code continues to work unchanged

Validation

  • All sample applications build successfully
  • Integration tests verify seamless conversion between Event and CloudEvent
  • Backward compatibility maintained across Orleans and Dapr implementations

Fixes #48.

Co-authored-by: kostapetan <10728102+kostapetan@users.noreply.github.com>
Copilot AI changed the title [WIP] Switch to CloudEvents in the abstraction library Integrate CloudEvents into the abstraction library Jun 10, 2025
Copilot AI requested a review from kostapetan June 10, 2025 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch to CloudEvents in the abstraction library

2 participants