An open API service indexing awesome lists of open source software.

https://github.com/sagarmaddela/multi-format-autonomous-ai-system

This is a multi-agent system that processes inputs from Email, JSON, and PDF, classifies both format + business intent, routes to specialized agents, and dynamically chains a follow-up action based on extracted data (e.g., triggering an alert, generating a summary, flagging a risk).
https://github.com/sagarmaddela/multi-format-autonomous-ai-system

email-parsing fastapi genai langchain llama3 llm ollama pdf-parsing python

Last synced: 2 months ago
JSON representation

This is a multi-agent system that processes inputs from Email, JSON, and PDF, classifies both format + business intent, routes to specialized agents, and dynamically chains a follow-up action based on extracted data (e.g., triggering an alert, generating a summary, flagging a risk).

Awesome Lists containing this project

README

          

# πŸ€– Multi-Format Autonomous AI System with Contextual Decisioning & Chained Actions

A smart, multi-agent system capable of autonomously processing Emails, PDFs, and JSON inputs to classify format and business intent, extract relevant fields, and dynamically trigger follow-up actionsβ€”while logging everything in a shared memory for audit and traceability.

## πŸš€ Features

### πŸ” Classifier Agent

* Detects input format: `Email`, `PDF`, or `JSON`
* Identifies business intent: `RFQ`, `Complaint`, `Invoice`, `Regulation`, `Fraud Risk`
* Uses few-shot examples and schema matching
* Stores metadata in shared memory

### πŸ“© Email Agent

* Extracts sender, urgency, and request details
* Detects tone: `Polite`, `Escalation`, `Threatening`
* Triggers action:

* Escalation β†’ `POST /crm/escalate`
* Routine β†’ logs and closes

### πŸ“¦ JSON Agent

* Parses webhook-style JSON
* Validates schema (e.g., required fields, types)
* Flags anomalies and logs alerts to memory

### πŸ“„ PDF Agent

* Parses PDF using `Tika` and `PyPDF2`
* Extracts invoice or policy information
* Triggers alert if:

* Invoice total > 10,000
* Policy mentions "GDPR", "FDA", etc.

### 🧠 Shared Memory Store

* Maintains:

* Input metadata
* Extracted fields
* Chained actions taken
* Agent decision traces
* Implemented using Redis

### πŸ” Action Router

* Routes outcomes to simulated REST endpoints:

* `POST /crm/escalate`
* `POST /risk_alert`
* `POST /invoice/flag`

## πŸ“‚ Project Structure

```
multi_agent_system/
β”œβ”€ api/
β”‚ β”œβ”€ fake_crm.py
β”‚ β”œβ”€ fake_invoice_api.py
β”‚ β”œβ”€ fake_risk_api.py
β”‚ β”œβ”€ main.py
β”‚ └─ schemas.py
β”œβ”€ classifier_agent/
β”‚ └─ agent.py
β”œβ”€ email_agent/
β”‚ └─ agent.py
β”œβ”€ json_agent/
β”‚ └─ agent.py
β”œβ”€ logs/
β”œβ”€ memory/
β”‚ └─ store.py
β”œβ”€ pdf_agent/
β”‚ └─ agent.py
β”œβ”€ router/
β”‚ └─ action_router.py
β”œβ”€ samples/
β”‚ β”œβ”€ emails/
β”‚ β”‚ β”œβ”€ email_sample1.txt
β”‚ β”‚ β”œβ”€ email_sample2.txt
β”‚ β”‚ β”œβ”€ email_sample3.txt
β”‚ β”‚ β”œβ”€ email_sample4.txt
β”‚ β”‚ └─ email_sample5.txt
β”‚ β”œβ”€ json/
β”‚ β”‚ β”œβ”€ webhook1.json
β”‚ β”‚ β”œβ”€ webhook2.json
β”‚ β”‚ β”œβ”€ webhook3.json
β”‚ β”‚ β”œβ”€ webhook4.json
β”‚ β”‚ └─ webhook5.json
β”‚ └─ pdf/
β”‚ β”œβ”€ invoice_sample.pdf (private)
β”‚ └─ invoice_sample2.pdf (private)
β”œβ”€ tests/
β”‚ β”œβ”€ test_classifier.py
β”‚ β”œβ”€ test_email_agent.py
β”‚ β”œβ”€ test_json_agent.py
β”‚ └─ test_pdf_agent.py
β”œβ”€ utils/
β”‚ └─ llm_utils.py
β”œβ”€ .gitignore
β”œβ”€ docker-compose.yml
β”œβ”€ Dockerfile
β”œβ”€ LICENSE
β”œβ”€ README.md
β”œβ”€ requirements.txt
└─ supervisord.conf

```

---

## πŸ’‘ Example Workflow

1. User uploads an Email.
2. **Classifier Agent** β†’ Detects: `Email` + `Complaint`
3. **Email Agent** β†’ Tone: `Angry`, Urgency: `High`
4. **Action Router** β†’ Calls `POST /crm/escalate`
5. **Memory** β†’ Logs full trace for audit

---

## πŸ§ͺ Sample Inputs

* `email_sample1.txt`: Escalated complaint email
* `invoice_sample.pdf`: Invoice with line items
* `webhook1.json`: Webhook with anomalies

---

## πŸ“Έ Screenshots

| Email Classification | PDF Invoice Parsing | JSON Anomaly |
| ------------------------------- | --------------------------- | ----------------------------- |
| ![email](screenshots/email_output.png) | ![pdf](screenshots/pdf_output.png) | ![json](screenshots/json_output.png) |

---

## Detailed Working Video

![video](screenshots/final.mp4)

---

## πŸ›  Tech Stack

* **Python** + **FastAPI** for microservice architecture
* **LangChain** + **llama3** LLMs for intent classification and field extraction
* **PyPDF2** for PDF parsing
* **Redis** for shared memory
* **Docker** for containerization

---

## 🧰 How to Run

```bash

# 1. Clone the repository
git clone https://github.com/SagarMaddela/Multi-Format-Autonomous-AI-System.git
cd Multi-Format-Autonomous-AI-System

# 2. Install and run the LLaMA3 model using Ollama
# (Make sure Ollama is installed: https://ollama.com)
ollama pull llama3
ollama run llama3

```

---

## 🐳 Docker

```bash

docker compose up --build

```

## Postman or curl

# Make a GET request
GET/http://localhost:8000/ - Then u will get a response like this

```bash
{
"message": "Classifier API is up and running"
}

```

# Make a POST request
POST/http://localhost:8000/classify -->
Go to body --> form-data --> Change the key to file and attach your sample file (email/pdf/json) as value , then u will get some response like this ( A sample response )

```bash

{
"classification": {
"format": "email",
"intent": "complaint",
"confidence": 0.9,
"trace_id": "6aadf26f-0260-4c0b-b4df-97a635974fe0",
"logged_at": "2025-06-07T17:47:32.233307"
},
"agent_output": {
"urgency": "high",
"type": "complaint",
"tone": "angry",
"trigger_action": true,
"action": "escalated",
"agent": "EmailAgent",
"trace_id": "4e328014-47d1-4b40-b0c6-509b63bdd6d3",
"logged_at": "2025-06-07T17:47:50.759806"
},
"action_output": {
"action_triggered": "escalate",
"target_url": "http://localhost:9000/crm/escalate",
"status_code": 200,
"trace_id": "b282fc0c-14a8-4923-8241-78bf41c02950",
"timestamp": "2025-06-07T17:47:50.764720",
"logged_at": "2025-06-07T17:47:50.764763"
}
}
```

## 🧠 Agent Flow Diagram

```bash

+-----------+
| Input |
+-----------+
|
|
|
+-----------------------------------------------------------------------+
| SHARED MEMORY | |
| | |
| | |
| +-----------+ |
| | Classifier| |
| | Agent | |
| +-----------+ |
| | |
| | |
| ------------------------------------------------ |
| | | | |
| | | | |
| +-----------+ +-----------+ +-----------+ |
| | Email | | Json | | PDF | |
| | Agent | | Agent | | Agent | |
| +-----------+ +-----------+ +-----------+ |
| \ | / |
| \ | / |
| \ | / |
| +---------------------------------------------+ |
| | Action Router | |
| +---------------------------------------------+ |
| |
+----------------------------------------------------------------------+

```

---

## πŸ‘¨β€πŸ’» Developed By
Sagar Maddela
venkatasagar.maddela2004@gmail.com

---

## πŸ“„ License

This project is licensed under the MIT License.

---

## πŸ™Œ Acknowledgements

Special thanks to Flowbit Private Limited for providing the challenge specification.

For questions or contributions, feel free to raise an issue or pull request!

All rights reserved Β© 2025