Skip to content

Show the effect of AG UI combined with .Net, SignalR and sveltejs.

License

Notifications You must be signed in to change notification settings

GreenShadeZhang/ag-ui-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AG-UI Protocol Demo - Enhanced Edition

δΈ­ζ–‡ζ–‡ζ‘£ | εŠŸθƒ½θ―¦ζƒ…

A comprehensive and feature-rich demonstration of the Agent User Interaction Protocol (AG-UI) with 10+ demo scenarios, 6 interactive tools, and advanced debugging capabilities. This enhanced demo showcases real-time agent communication, complex workflows, and human-in-the-loop interactions.

πŸš€ New in Enhanced Edition

10 Demo Scenarios

  • 🌊 Basic Text Streaming - Real-time message streaming
  • πŸ”§ Tool Calling Workflow - Complete tool lifecycle
  • πŸ”„ State Synchronization - Snapshots and deltas
  • 🎯 Multi-Step Workflow - Complex agent processes
  • ⚠️ Error Scenarios - Error handling and recovery
  • ⚑ Custom Events - Application-specific events
  • 🀝 Human-in-the-Loop - Interactive confirmations
  • πŸ‘₯ Real-time Collaboration - Bidirectional state sharing
  • πŸ“Š Data Analysis Workflow - Complete analysis pipeline
  • πŸš€ Progressive Enhancement - Feature evolution

Advanced Tool Integration

  • 6 interactive tools with streaming arguments
  • Tool performance metrics and timing
  • Real-time tool status visualization
  • Category-based tool organization

Performance Monitoring

  • Real-time event statistics
  • Response time analytics
  • Tool call duration tracking
  • Error rate monitoring

Enhanced UI/UX

  • Scenario filtering by category
  • Interactive event log export
  • Advanced debugging panels
  • Performance metrics dashboard

Overview

This demo implements the AG-UI protocol to create a standardized interface between AI agents and frontend applications. It demonstrates:

  • Real-time streaming communication between agents and UI
  • Event-driven architecture following AG-UI specification
  • Tool calling mechanisms for human-in-the-loop workflows
  • State synchronization between agent and frontend
  • Multiple backend implementations (SignalR/.NET and Socket.IO/Node.js)
  • Performance monitoring and analytics
  • Advanced debugging and troubleshooting tools

Screenshots

Application Interface

AG-UI Demo Main Interface The AG-UI Protocol Demo interface showing demo scenarios (left), chat interface (center), and real-time event log (right)

Interactive Demo

AG-UI Demo Interaction Real-time demonstration of AG-UI protocol events including message streaming, tool calling, and state synchronization

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚    β”‚   Communication  β”‚    β”‚   Backend       β”‚
β”‚   (Svelte)      │◄──►│   Layer          │◄──►│   (.NET/Node)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                       β”‚                       β”‚
        β”‚                       β”‚                       β”‚
        β–Ό                       β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Enhanced       β”‚    β”‚  SignalR/        β”‚    β”‚  Smart Agent    β”‚
β”‚  AgentChat      β”‚    β”‚  Socket.IO       β”‚    β”‚  Services       β”‚
β”‚  Component      β”‚    β”‚  with Analytics  β”‚    β”‚  with Scenarios β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Features

✨ AG-UI Protocol Compliance

  • Complete implementation of AG-UI events
  • Lifecycle events (RUN_STARTED, RUN_FINISHED, STEP_STARTED, STEP_FINISHED, RUN_ERROR)
  • Text message streaming (TEXT_MESSAGE_START, TEXT_MESSAGE_CONTENT, TEXT_MESSAGE_END)
  • Tool call events (TOOL_CALL_START, TOOL_CALL_ARGS, TOOL_CALL_END, TOOL_CALL_RESULT)
  • State management (STATE_SNAPSHOT, STATE_DELTA, MESSAGES_SNAPSHOT)
  • Special events (CUSTOM, RAW)

πŸ”§ Multiple Backend Options

  • SignalR/.NET 8: Enterprise-grade real-time communication with smart scenario detection
  • Socket.IO/Node.js: Lightweight, flexible implementation

🎯 Enhanced Demonstration Features

  • 10 interactive demo scenarios: From basic streaming to complex workflows
  • 6 professional tools: User management, document search, code analysis, weather, confirmations
  • Real-time performance metrics: Event counting, response times, error tracking
  • Advanced state management: History tracking, delta visualization, JSON Patch support
  • Smart scenario detection: Backend automatically detects demo intent from user messages
  • Interactive event monitoring: Real-time AG-UI event log with filtering and details
  • Multi-scenario demonstrations: Pre-built scenarios for testing different AG-UI features
  • Human-in-the-loop workflows: User confirmation, preferences, and collaborative decision-making
  • Error handling showcase: Demonstration of error recovery and resilience patterns

πŸ“Š Demo Scenarios

  • 🌊 Basic Text Streaming: Real-time character-by-character message display
  • πŸ”§ Tool Calling Workflow: Complete tool lifecycle with argument streaming
  • πŸ”„ State Synchronization: STATE_SNAPSHOT and STATE_DELTA demonstrations
  • 🎯 Multi-Step Workflow: Complex tasks with multiple tools and state updates
  • ⚠️ Error Handling: Error scenarios and recovery patterns
  • ⚑ Custom Events: CUSTOM and RAW event demonstrations
  • 🀝 Human-in-the-Loop: User confirmation and collaborative workflows
  • πŸ‘₯ Real-time Collaboration: Bidirectional state sharing

πŸ› οΈ Available Tools

  • getUserPreferences: User settings and configuration management
  • searchDocuments: Knowledge base search with filtering and pagination
  • confirmAction: Human-in-the-loop confirmation workflows
  • analyzeCode: Code analysis with security, performance, and style checks
  • weatherLookup: External API integration demonstration
  • createReminder: Task and reminder creation
  • saveUserPreferences: Persistent user configuration
  • generateChart: Data visualization tools
  • Error handling: Robust connection and error management

Quick Start

Prerequisites

  • Node.js 18+ and npm
  • .NET 8 SDK (for SignalR backend)
  • Modern web browser

Installation

# Clone the repository
git clone <repository-url>
cd ag-ui-demo1

# Install frontend dependencies
cd frontend
npm install

# Install Node.js backend dependencies
cd ../backend/nodejs-mock-server
npm install

# Return to project root
cd ../..

Running the Demo

Option 1: Socket.IO Backend (Node.js) - Recommended for Development

Terminal 1: Start Node.js Backend

cd backend/nodejs-mock-server
npm run dev
# Or: npm start

This starts the Node.js backend on port 5001

Terminal 2: Start Frontend

cd frontend
npm run dev

This starts the frontend on port 5173

Option 2: SignalR Backend (.NET)

Terminal 1: Start .NET Backend

cd backend/dotnet-signalr-server
dotnet run

This starts the .NET SignalR backend on port 5000

Terminal 2: Start Frontend

cd frontend
npm run dev

This starts the frontend on port 5173

Option 3: Frontend Only (for testing against external backends)

cd frontend
npm run dev

Access the Application

Using the Demo

  1. Select Backend: Choose between Socket.IO (Node.js) or SignalR (.NET) using the radio buttons
  2. View Guide: Click "Show Guide" to see available scenarios and protocol documentation
  3. Try Demo Scenarios: Use the colored demo buttons to trigger specific AG-UI feature demonstrations
  4. Monitor Events: Watch the Event Log panel to see real-time AG-UI events
  5. Observe State: Check the Agent State panel to see state synchronization in action
  6. Track Tools: Monitor the Tool Calls panel to see tool execution lifecycle
  7. Interactive Chat: Type messages to have natural conversations with the agent

Project Structure

β”œβ”€β”€ frontend/                 # Svelte frontend application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”‚   β”œβ”€β”€ components/   # UI components
β”‚   β”‚   β”‚   β”‚   └── AgentChat.svelte
β”‚   β”‚   β”‚   β”œβ”€β”€ SignalRAgent.ts    # SignalR client
β”‚   β”‚   β”‚   β”œβ”€β”€ SocketIOAgent.ts   # Socket.IO client
β”‚   β”‚   β”‚   └── types.ts           # AG-UI type definitions
β”‚   β”‚   β”œβ”€β”€ App.svelte        # Main application
β”‚   β”‚   └── main.ts
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ dotnet-signalr-server/     # .NET SignalR implementation
β”‚   β”‚   β”œβ”€β”€ AgentHub.cs            # SignalR Hub with AG-UI events
β”‚   β”‚   └── Program.cs
β”‚   └── nodejs-mock-server/        # Node.js Socket.IO implementation
β”‚       β”œβ”€β”€ server.js              # Express + Socket.IO server
β”‚       └── package.json
└── docs/                    # Multilingual documentation
    β”œβ”€β”€ en/                  # English documentation
    β”œβ”€β”€ zh/                  # Chinese documentation
    └── README.md           # This file

AG-UI Protocol Implementation

This demo showcases the complete AG-UI protocol implementation:

Event Types Implemented

  1. Lifecycle Events

    • RUN_STARTED: Agent execution begins
    • RUN_FINISHED: Agent execution completes
    • RUN_ERROR: Agent execution fails
    • STEP_STARTED: Agent step begins
    • STEP_FINISHED: Agent step completes
  2. Message Events

    • TEXT_MESSAGE_START: Message streaming begins
    • TEXT_MESSAGE_CONTENT: Message content chunks
    • TEXT_MESSAGE_END: Message streaming completes
  3. Tool Events

    • TOOL_CALL_START: Tool execution begins
    • TOOL_CALL_ARGS: Tool arguments streaming
    • TOOL_CALL_END: Tool call completes
    • TOOL_CALL_RESULT: Tool execution result
  4. State Events

    • STATE_SNAPSHOT: Complete state synchronization
    • STATE_DELTA: Incremental state updates

Tool System

The demo includes several example tools demonstrating the AG-UI tool calling pattern:

const tools = [
  {
    name: "getUserPreferences",
    description: "Get user preferences and settings",
    parameters: {
      type: "object",
      properties: {
        userId: { type: "string", description: "The user ID" }
      },
      required: ["userId"]
    }
  },
  // More tools...
];

Development

Adding New Tools

  1. Define tool in frontend/src/App.svelte:
const newTool = {
  name: "myTool",
  description: "Description of what this tool does",
  parameters: {
    type: "object",
    properties: {
      param1: { type: "string", description: "Parameter description" }
    },
    required: ["param1"]
  }
};
  1. Handle tool execution in backend
  2. Test tool calling in the frontend interface

Customizing AG-UI Events

Extend the event handling in AgentChat.svelte:

function handleAgentEvent(event: AGUIEvent) {
  switch (event.type) {
    case EventType.CUSTOM:
      // Handle custom events
      break;
    // ... other cases
  }
}

Documentation

Comprehensive documentation is available in multiple languages:

Available Documentation

  • Architecture Guide
  • Development Setup
  • API Reference
  • Troubleshooting
  • Contributing Guidelines

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Update documentation
  6. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Resources

Support

For questions and support:

About

Show the effect of AG UI combined with .Net, SignalR and sveltejs.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published