Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Event-Driven Agentic Platform

A lightweight, multi-tenant, event-driven Agentic AI platform prototype built with FastAPI, MCP, and an orchestrator-agent architecture.

The platform demonstrates secure event routing, tenant isolation, correlation tracking, human approval for sensitive actions, controlled MCP tool execution, retry and failure handling, observability, auditability, PII protection, and modular agent workflows.


Table of Contents


Challenge

AI Engineering Lead – Agentic Platform Prototype

Design and prototype the core of a multi-tenant, event-driven agentic platform.

Minimum Working Path

FastAPI
   |
   v
Event Router
   |
   v
Orchestrator
   |
   v
Agent
   |
   v
MCP Tool
   |
   v
Response

Architecture

                         CLIENT
                           |
                           v
                        FASTAPI
                           |
                           v
                    AUTHENTICATION
                           |
                           v
                      EVENT ROUTER
                           |
                           v
                     ORCHESTRATOR
                           |
                           v
                         AGENT
                    +------+------+
                    |             |
                    v             v
             MODEL PROVIDER    MCP CLIENT
                    |             |
                    v             v
               AI MODEL       MCP SERVER
                                  |
                                  v
                          BUSINESS TOOLS
                                  |
                                  v
                              RESPONSE

Sensitive Action Flow

Agent
  |
  v
Sensitive Action
  |
  v
Approval Service
  |
  v
Human Approval
  |
  +-- Rejected --> Stop
  |
  +-- Approved
          |
          v
      MCP Tool
          |
          v
    Execute Action

Core Workflow

  1. A client sends an event through the FastAPI API.
  2. FastAPI validates the incoming request.
  3. Authentication identifies the tenant.
  4. The Event Router validates the event contract and extracts the tenant and correlation IDs.
  5. The Orchestrator coordinates the workflow.
  6. The Agent interprets the task and determines the required action.
  7. The Agent communicates with the MCP server through controlled tools.
  8. Sensitive actions can be routed through the Human Approval service.
  9. Approved actions are executed through MCP.
  10. The result is returned to the client.
  11. Observability and audit logs track the workflow.

Key Components

FastAPI

Provides the HTTP API layer and exposes the platform endpoints.

Authentication

Validates requests and provides the tenant identity used throughout the workflow.

Event Router

Responsible for:

  • Event validation
  • Event contract handling
  • Tenant identification
  • Correlation ID propagation
  • Routing events to the appropriate workflow

Orchestrator

Coordinates the overall agent workflow.

It acts as the control layer between the Event Router and Agent, ensuring that the correct processing sequence is followed.

Agent

Responsible for understanding the incoming task, identifying the intent, extracting required parameters, and selecting the appropriate tool.

The current prototype demonstrates refund-related task processing.

MCP Client

Provides controlled communication between the Agent and MCP server.

MCP Server

Exposes business operations as tools.

Example tools:

check_refund_eligibility
issue_refund

The prototype uses synthetic business data to demonstrate MCP-based tool integration.

Approval Service

Handles human approval for sensitive operations.

Example:

Pending
   |
   v
Human Review
   |
   v
Approved / Rejected

Model Provider

Provides an abstraction layer for AI model integration, allowing the Agent architecture to be extended with different models without tightly coupling the Agent to a specific provider.

PII Protection

Sensitive information is masked before being written to logs.

Observability

The platform records important workflow events such as:

AGENT_STARTED
TASK_RECEIVED
MCP_CALL
MCP_SUCCESS
MCP_FAILURE
MCP_RETRY

Auditability

Important actions are recorded with:

  • Tenant ID
  • Correlation ID
  • Action
  • Resource ID
  • Result

Multi-Tenant Isolation

Every event carries a tenant_id.

Example:

{
  "tenant_id": "tenant-a",
  "correlation_id": "corr-001"
}

The tenant context is propagated through the workflow:

Request
   |
   v
Event Router
   |
   v
Orchestrator
   |
   v
Agent
   |
   v
MCP

This allows business operations and audit records to remain associated with the correct tenant.

The architecture is designed so that customer context and data are not unintentionally shared across tenant boundaries.


Correlation Tracking

Each request receives a correlation_id.

Example:

corr-010

The same correlation ID is propagated across the workflow.

This makes it possible to trace:

Client Request
      |
      v
Event Router
      |
      v
Orchestrator
      |
      v
Agent
      |
      v
MCP
      |
      v
Business Operation

This is useful for debugging, monitoring, and auditing distributed agent workflows.


Retry and Failure Handling

MCP operations use retry handling.

Example:

Attempt 1
   |
   v
Failure
   |
   v
Attempt 2
   |
   v
Failure
   |
   v
Attempt 3
   |
   v
Success / Final Failure

The prototype uses a maximum of three attempts for MCP operations.

If all attempts fail, the Agent returns a controlled failure response rather than silently failing.


Human-in-the-Loop

Sensitive actions require explicit approval.

For example:

Check Refund Eligibility
        |
        v
Sensitive Refund Action
        |
        v
Create Approval
        |
        v
Human Approval
        |
        v
Approved
        |
        v
Execute MCP Tool

This prevents the Agent from automatically executing sensitive business operations without authorization.


Project Structure

Event-Driven-Agentic-Platform/
|
├── app/
│   ├── agent/
│   │   └── agent.py
│   │
│   ├── models/
│   │   └── events.py
│   │
│   ├── orchestrator/
│   │   └── orchestrator.py
│   │
│   ├── router/
│   │   ├── approval_router.py
│   │   ├── event_router.py
│   │   └── request_router.py
│   │
│   ├── services/
│   │   ├── approval.py
│   │   ├── auth.py
│   │   └── model_provider.py
│   │
│   ├── utils/
│   │   └── pii.py
│   │
│   ├── mcp/
│   │   └── server.py
│   │
│   └── main.py
│
├── .gitignore
├── requirements.txt
└── README.md

Technologies

  • Python
  • FastAPI
  • FastMCP
  • MCP
  • Pydantic
  • Uvicorn
  • AsyncIO

Setup

1. Clone the repository

git clone https://github.com/maaran77/Event-Driven-Agentic-Platform.git
cd Event-Driven-Agentic-Platform

2. Create a virtual environment

python -m venv venv

3. Activate the environment

Windows PowerShell:

venv\Scripts\Activate.ps1

4. Install dependencies

pip install -r requirements.txt

5. Start the MCP Server

uvicorn app.mcp.server:app --host 127.0.0.1 --port 8001

6. Start the Agentic Platform

In another terminal:

uvicorn app.main:app --reload

The API will be available at:

http://127.0.0.1:8000

Swagger documentation:

http://127.0.0.1:8000/docs

Example Event

{
  "event_id": "evt-010",
  "event_type": "agent.requested",
  "tenant_id": "tenant-a",
  "correlation_id": "corr-010",
  "payload": {
    "message": "Check order ORD-1001 and tell me if it is eligible for a refund"
  }
}

Example Response

{
  "status": "processed",
  "event_id": "evt-010",
  "tenant_id": "tenant-a",
  "correlation_id": "corr-010",
  "agent_result": {
    "status": "completed",
    "order_id": "ORD-1001",
    "mcp_result": {
      "success": true,
      "order_id": "ORD-1001",
      "amount": 2499,
      "eligible": true,
      "reason": "Within refund window"
    }
  }
}

Sensitive Action Example

For a sensitive action such as issuing a refund, the workflow can become:

Client
  |
  v
FastAPI
  |
  v
Event Router
  |
  v
Orchestrator
  |
  v
Agent
  |
  v
Approval Service
  |
  v
Human Approval
  |
  v
MCP Server
  |
  v
issue_refund
  |
  v
Response

An approved action returns information such as:

{
  "status": "approved_and_executed",
  "approval_id": "approval-id",
  "tenant_id": "tenant-a",
  "action": "issue_refund",
  "resource_id": "ORD-1001",
  "mcp_result": {
    "success": true,
    "order_id": "ORD-1001",
    "refund_amount": 2499,
    "status": "refund_issued"
  }
}

Assessment Coverage

The prototype addresses the key architecture requirements:

Requirement Implementation
Multi-tenancy Tenant ID propagation and isolation
Event-driven architecture Event Router + event contracts
Agent boundaries Dedicated Agent component
Orchestration Dedicated Orchestrator
MCP integration MCP Client + MCP Server
Human approval Approval Service
Authentication Auth Service
Retries MCP retry handling
Failure handling Controlled failure responses
Observability Structured logging
Auditability Audit logs
Correlation tracking Correlation IDs
PII protection PII masking
Model abstraction Model Provider service
Controlled tool access MCP tool boundary

Future Improvements

The prototype can be extended with:

  • Persistent approval storage
  • Production authentication and authorization
  • Redis/Kafka-based event streaming
  • Database-backed tenant isolation
  • Production LLM providers
  • Tenant-specific model configuration
  • Model fallback strategies
  • Prompt and model version management
  • Cost monitoring
  • Distributed tracing
  • Production-grade observability
  • Advanced PII detection
  • Role-based access control

Project

Event-Driven Agentic Platform

Developed as a prototype for the Mini Hackathon – AI Engineering Lead: Agentic Platform Prototype challenge.

The implementation focuses on demonstrating the core architecture and working execution path rather than production-scale infrastructure.

About

A lightweight multi-tenant, event-driven Agentic AI platform prototype built with FastAPI, MCP, and an orchestrator-agent architecture, featuring tenant isolation, human approval, retry handling, observability, auditability, PII protection, and controlled tool execution.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages