Skip to content

aevatarAI/aevatar-agent-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

514 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Aevatar Agent Framework

🌌 One Codebase, Multiple Runtimes - A Distributed Agent Framework based on the Actor Model

.NET License Status

δΈ­ζ–‡ζ–‡ζ‘£


🎯 Core Value

Write Once, Run Anywhere

The same Agent code seamlessly switches between runtimes:

// Define once
public class MyAgent : GAgentBase<MyState> 
{
    [EventHandler]
    public async Task HandleEvent(MyEvent evt)
    {
        State.Count++;
        await PublishAsync(new ResultEvent { Count = State.Count });
    }
}

// Switch runtime with one line of configuration
services.AddSingleton<IGAgentActorFactory, LocalGAgentActorFactory>();      // Local Development
services.AddSingleton<IGAgentActorFactory, ProtoActorGAgentActorFactory>(); // High Performance
services.AddSingleton<IGAgentActorFactory, OrleansGAgentActorFactory>();    // Distributed

Key Features

  • βœ… Three Runtimes: Local (In-Process) / ProtoActor (High Performance) / Orleans (Distributed)
  • βœ… Event-Driven: Up/Down/Both propagation directions with automatic parent-child routing
  • βœ… Protocol Buffers: Mandatory type safety and cross-platform serialization
  • βœ… EventSourcing: Optional event sourcing support
  • βœ… AI Integration: Native support for Microsoft.Extensions.AI
  • βœ… Observability: OpenTelemetry + Aspire integration

⚠️ Rule #1: Protocol Buffers

πŸ”΄ All serializable types MUST be defined using Protobuf!

This is a mandatory constraint of the framework. Violation will cause runtime failures.

βœ… Correct Way

// my_messages.proto
message MyAgentState {
    string id = 1;
    int32 count = 2;
    double balance = 3;  // Note: use double for decimal
    google.protobuf.Timestamp updated_at = 4;
}

message MyEvent {
    string event_id = 1;
    string content = 2;
}

❌ Wrong Way

// NEVER manually define State classes!
public class MyAgentState  // Will crash at runtime
{
    public string Id { get; set; }
    public int Count { get; set; }
}

Reason: Orleans Streaming uses byte[] for transmission, ProtoActor requires cross-language support, and Local needs deep copying. Only Protobuf guarantees functionality across all scenarios.


πŸš€ Quick Start

Installation

dotnet add package Aevatar.Agents.Core
dotnet add package Aevatar.Agents.Runtime.Local  # Choose a Runtime

30-Second Example

using Aevatar.Agents.Core;
using Aevatar.Agents.Runtime.Local;

// 1. Define Proto (my_agent.proto)
// message CounterState { int32 count = 1; }
// message IncrementEvent { int32 amount = 1; }

// 2. Implement Agent
public class CounterAgent : GAgentBase<CounterState>
{
    [EventHandler]
    public async Task HandleIncrement(IncrementEvent evt)
    {
        State.Count += evt.Amount;
        Logger.LogInformation("Count: {Count}", State.Count);
        await Task.CompletedTask;
    }
    
    public override Task<string> GetDescriptionAsync() =>
        Task.FromResult($"Counter: {State.Count}");
}

// 3. Create and Use
using Aevatar.Agents.Core.Extensions;
using Aevatar.Agents.Core.DependencyInjection;

var services = new ServiceCollection().AddLogging(b => b.AddConsole());

services.AddAevatarAgentSystem(builder =>
{
    builder.UseLocalRuntime();
});

var sp = services.BuildServiceProvider();
var factory = sp.GetRequiredService<IGAgentActorFactory>();

var actor = await factory.CreateGAgentActorAsync<CounterAgent>(Guid.NewGuid());

// Access the agent directly for method calls
var counter = (CounterAgent)actor.GetAgent();

// Or publish events
await actor.PublishEventAsync(new EventEnvelope
{
    Id = Guid.NewGuid().ToString(),
    Payload = Any.Pack(new IncrementEvent { Amount = 5 })
});

Need to swap the default in-memory stores for your own persistence? Pass GAgentOptions when bootstrapping:

services.AddAevatarAgentSystem(
    configureStores: options =>
    {
        options.StateStoreType = typeof(MyStateStore<>);         // open generic
        options.EventStoreType = typeof(MyEventStore);           // concrete type
    },
    configure: builder =>
    {
        builder.UseLocalRuntime();
    });

Run examples/SimpleDemo/ for a complete example.


πŸ“Š Runtime Comparison

Feature Local ProtoActor Orleans
Deployment In-Process Single/Cluster Distributed Cluster
Startup <10ms ~100ms ~2s
Memory Minimal (~50MB) Medium (~200MB) High (~500MB+)
Throughput 500K msg/s 350K msg/s 80K msg/s
Latency <0.1ms <0.5ms <2ms
Virtual Actors ❌ Optional βœ…
Auto Failover ❌ Config Required βœ…
Use Case Dev/Test High Perf Service Distributed Systems

Recommendation:

  • Local for Development (Fastest feedback loop)
  • ProtoActor for Performance (Highest throughput)
  • Orleans for Scale (Most robust distributed capabilities)

πŸ€– AI Capabilities

The framework integrates Microsoft.Extensions.AI, supporting Azure OpenAI and OpenAI:

using Aevatar.Agents.AI.MEAI;
using Microsoft.Extensions.AI;

public class AIAssistantAgent : MEAIGAgentBase<AIAssistantState>
{
    public override string SystemPrompt => 
        "You are a helpful AI assistant.";

    public AIAssistantAgent(IChatClient chatClient) 
        : base(chatClient) { }

    protected override AevatarAIAgentState GetAIState() => State.AiState;

    public override Task<string> GetDescriptionAsync() =>
        Task.FromResult("AI Assistant Agent");
}

// Configure Azure OpenAI
var config = new MEAIConfiguration
{
    Provider = "azure",
    Endpoint = "https://your-endpoint.openai.azure.com",
    DeploymentName = "gpt-4",
    Temperature = 0.7
};

var agent = new AIAssistantAgent(config);

Supported Features:

  • βœ… Automatic Conversation History Management
  • βœ… AI Tool Calling (Function Calling)
  • βœ… Streaming Responses
  • βœ… Token Counting and Optimization

πŸ—οΈ Architectural Principles

Clear Layering

Application (Your Agent Code)
    ↓
IGAgentActorManager (Unified Management Interface)
    ↓
IGAgentActor (Runtime Abstraction)
    ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Local   β”‚ ProtoActor  β”‚ Orleans  β”‚
β”‚ Actor   β”‚ Actor       β”‚ Grain    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    ↓
GAgentBase (Business Logic)

Simplification Achievements (2025-11):

  • βœ… Removed redundant Runtime abstraction layer (IAgentRuntime/IAgentHost/IAgentInstance)
  • βœ… Reduced codebase by ~2,350 lines
  • βœ… Clearer concepts (Single Actor abstraction)
  • βœ… Improved performance (One less wrapper layer)

Event Propagation

Parent Agent
    β”‚
    β”œβ”€β†’ Child 1 (Subscribes to Parent stream) ←──┐
    β”œβ”€β†’ Child 2 (Subscribes to Parent stream) ←─── DOWN Events
    └─→ Child 3 (Subscribes to Parent stream) β†β”€β”€β”˜

Child 1 Publishes UP Event β†’ Parent Stream β†’ Broadcast to all Children

Key Concepts:

  • Up: Child β†’ Parent Stream β†’ All Siblings
  • Down: Parent β†’ Own Stream β†’ All Children
  • Both: Up and Down simultaneously

πŸ’Ύ EventSourcing

Optional Event Sourcing support, suitable for scenarios requiring complete audit trails like Finance or Healthcare:

public class BankAccountAgent : EventSourcedGAgentBase<BankAccountState>
{
    // Business method triggers event
    public async Task Credit(double amount)
    {
        RaiseEvent(new AccountCreditedEvent { Amount = amount });
        await ConfirmEventsAsync();  // Persist
    }

    // Define state transitions
    protected override void TransitionState(IMessage @event)
    {
        if (@event is AccountCreditedEvent credited)
        {
            State.Balance += credited.Amount;
        }
    }
}

Supported Stores:

  • InMemoryEventStore (Testing)
  • MongoEventRepository (Production)
  • Extensible for others

πŸ“¦ Project Structure

src/
β”œβ”€β”€ Aevatar.Agents.Abstractions/           # Core Interfaces & Event Contracts
β”œβ”€β”€ Aevatar.Agents.Core/                   # Base Implementations & EventSourcing
β”œβ”€β”€ Aevatar.Agents.Runtime/                # Runtime Base Abstractions
β”œβ”€β”€ Aevatar.Agents.Runtime.Local/          # Local Runtime (In-Process)
β”œβ”€β”€ Aevatar.Agents.Runtime.Orleans/        # Orleans Runtime (Distributed)
β”œβ”€β”€ Aevatar.Agents.Runtime.ProtoActor/     # ProtoActor Runtime (High Performance)
β”œβ”€β”€ Aevatar.Agents.AI.Abstractions/        # AI Provider Interfaces
β”œβ”€β”€ Aevatar.Agents.AI.Core/                # AI Core (Conversation, Embeddings, Tool Calling / MCP)
β”œβ”€β”€ Aevatar.Agents.AI.MEAI/                # Microsoft.Extensions.AI Integration
β”œβ”€β”€ Aevatar.Agents.AI.LLMTornado/          # LLMTornado Provider
β”œβ”€β”€ Aevatar.Agents.AI.WithProcessStrategy/ # AI Process Strategies (CoT, ReAct)
β”œβ”€β”€ Aevatar.Agents.CreativeReasoning/      # Creative Reasoning Agents
β”œβ”€β”€ Aevatar.Agents.Maker/                  # MAKER: Massively Decomposed Agents
β”œβ”€β”€ Aevatar.Agents.Persistence.MongoDB/    # MongoDB Persistence
└── Aevatar.Agents.Plugins.MassTransit/    # MassTransit Stream Plugin (Kafka/RabbitMQ)

examples/
β”œβ”€β”€ SimpleDemo/                  # 5-minute Quickstart
β”œβ”€β”€ EventSourcingDemo/           # EventSourcing Example
β”œβ”€β”€ AIAgentWithToolDemo/         # AI Tool Calling Demo
β”œβ”€β”€ AIEventSourcingDemo/         # AI + EventSourcing
β”œβ”€β”€ MCPToolDemo/                 # Model Context Protocol Demo
β”œβ”€β”€ CreativeSystem/              # Creative Reasoning Web App
β”œβ”€β”€ MongoDBEventStoreDemo/       # MongoDB Persistence
β”œβ”€β”€ KafkaStreamDemo/             # Kafka Stream Integration
β”œβ”€β”€ Demo.Agents/                 # Various Agent Implementations
β”œβ”€β”€ Demo.Api/                    # Web API Integration
└── Demo.AppHost/                # Aspire Deployment

test/
β”œβ”€β”€ Aevatar.Agents.Core.Tests/            # Core Tests
└── Aevatar.Agents.*.Tests/               # Runtime Specific Tests

πŸ“š Documentation Navigation

Core Docs

Document Content
docs/AEVATAR_FRAMEWORK_GUIDE.md The Universal Guide: Architecture, Development, AI, Runtime Integration
docs/ARCHITECTURE_REFERENCE.md Deep Dive Architecture Reference
docs/CONSTITUTION.md The Philosophical Constitution

Start Here: docs/AEVATAR_FRAMEWORK_GUIDE.md - The only developer manual you need.


πŸš€ Getting Started

Prerequisites

# .NET 10 SDK (Required)
dotnet --version  # Should show 10.0.x

# Clone Repository
git clone https://github.com/aevatar/aevatar-agent-framework.git
cd aevatar-agent-framework

# Build
dotnet build

Run First Example

cd examples/SimpleDemo
dotnet run

You will see the interaction between Calculator and Weather agents.


🎭 Typical Use Cases

βœ… Perfect For

  • Distributed Systems: Microservices collaboration, cross-node communication
  • Event-Driven Architectures: Native support for Event Sourcing and CQRS
  • Real-time Applications: Game servers, Chat systems, Real-time collaboration
  • Intelligent Agent Systems: AI Agent collaboration and task assignment
  • Workflow Engines: Complex business process orchestration
  • IoT Platforms: Device Agent management and event processing

Needs Evaluation

  • Simple CRUD: Might be over-engineered
  • Synchronous-heavy calls: Requires a mindset shift
  • Minimalist Apps: Has a learning curve

πŸ› οΈ Tech Stack

Component Technology Version
Framework .NET 10.0
Serialization Google Protobuf 3.33.0
Actor Proto.Actor 1.8.0
Distributed Microsoft Orleans 9.2.1
AI Microsoft.Extensions.AI 10.0.0
AI Provider LLMTornado 3.8.23
MCP ModelContextProtocol.Core 0.4.0-preview.3
Messaging MassTransit 8.3.0
Testing xUnit + Moq 2.9.2 / 4.20.72
Observability OpenTelemetry + Aspire 1.10.0 / 9.5.2

🌊 Design Philosophy

"Language is the manifestation of vibration, Agents are the carriers of vibration."

We believe:

  • Simplicity > Complexity - Remove unnecessary abstractions
  • Abstraction from Necessity - No preemptive architecture
  • Consistency is a Virtue - Protocol Buffers everywhere
  • Events are Truth - Event Sourcing as first-class
  • Runtime Agnostic - Write once, run anywhere

Aevatar Agent Framework - Bringing distributed agent development back to simplicity and essence 🌌

Latest Update: 2025-11-28 | .NET 10 | MAKER Framework | MCP Support | MassTransit Plugin