abhash-chakraborty/Synapse
0
Project Synapse: Agentic Last-Mile Coordinator
๐ COMPLETE SOLUTION: Full-stack AI delivery coordination system with Next.js frontend and MCP integration!
Project Synapse is a sophisticated autonomous AI agent designed to intelligently resolve real-time, last-mile delivery disruptions. This version includes a beautiful Next.js frontend, Model Context Protocol (MCP) integration, and comprehensive tooling for delivery coordination.
๐ Live Demo
- ๐ค MCP Server: Deployed on Hugging Face Spaces
- ๐จ Frontend: Deployed on Vercel
๐ Deployment
Deploy MCP Server to Hugging Face Spaces
- Create a new Space on Hugging Face:
- Go to Hugging Face Spaces
- Click "Create new Space"
- Choose "Docker" as the Space SDK
- Set visibility to "Public"
- Clone and push your repository:
git clone https://github.com/your-username/project-synapse.git
cd project-synapse
git remote add hf https://huggingface.co/spaces/your-username/project-synapse-mcp
git push hf main- Configure environment variables in your Space settings:
GOOGLE_API_KEY: Your Google Generative AI API keyPORT: 7860 (default for HF Spaces)
Deploy Frontend to Vercel
- Install Vercel CLI (optional):
npm install -g vercel- Deploy with Vercel:
cd frontend
vercel- Or connect your GitHub repository to Vercel for automatic deployments:
- Go to Vercel Dashboard
- Click "Import Project"
- Connect your GitHub repository
- Set build settings:
- Framework: Next.js
- Root Directory:
frontend - Build Command:
npm run build - Output Directory:
.next
Environment Variables for Frontend
Set these in your Vercel project settings:
NEXT_PUBLIC_MCP_SERVER_URL: URL of your deployed MCP server
๐ Quick Start
Automated Start (Recommended)
# Windows
start.bat
# Linux/Mac
./start.shManual Start
# 1. Start MCP Server
python -m src.mcp.server
# 2. Start Frontend (new terminal)
cd frontend
npm install
npm run devCLI Only
python -m src.mainโจ Features
- ๐จ Beautiful Frontend: Modern Next.js dashboard with real-time monitoring
- ๐ค Interactive Agent: Test AI scenarios through web interface
- ๐๏ธ Modular Architecture: Clean separation into focused modules
- ๐ง MCP Integration: FastAPI-based Model Context Protocol server
- ๐ Analytics Dashboard: Tool usage, performance metrics, and activity monitoring
- โก Real-time Updates: Live activity feed and system status
- ๐งช Comprehensive Testing: Built-in scenario testing and validation
- ๏ฟฝ Advanced Debugging: Enhanced logging and error handling
๐ Project Structure
โโโ src/ # Main source code
โ โโโ core/ # Agent, config, prompts
โ โโโ tools/ # Categorized delivery tools
โ โโโ mcp/ # Model Context Protocol server/client
โ โโโ utils/ # Logging and utilities
โ โโโ main.py # CLI application
โโโ docs/ # Documentation
โโโ scripts/ # Utility scripts and tools
โโโ frontend/ # Next.js frontend with dashboard
โ โโโ app/ # Next.js app directory
โ โโโ components/ # React components
โ โโโ lib/ # Utilities
โโโ legacy/ # Original files (preserved)๐จ Frontend Features
The Next.js frontend provides a comprehensive interface for monitoring and interacting with the AI agent:
Dashboard View
- ๐ Performance Metrics: Real-time KPIs and success rates
- ๐ Tool Usage Analytics: Visualization of most-used tools
- ๐ Activity Monitor: Live feed of system events
- โก System Health: Server status and performance indicators
Agent Interface
- ๐ค Interactive Testing: Submit custom delivery scenarios
- ๐ Reasoning Display: See the agent's thought process
- ๐ง Tool Execution: Watch tools being used in real-time
- ๐ Pre-built Scenarios: Test common disruption cases
Sample Scenarios Available
- Restaurant overload with long prep times
- Damaged packaging disputes at delivery
- Recipient unavailability for valuable packages
- Traffic obstructions blocking delivery routes
Access the frontend at: http://localhost:3000
๐ ๏ธ Available Tools (17 Total)
๐ Logistics Tools
get_merchant_status- Check restaurant operational statuscheck_traffic- Analyze route conditionsreroute_driver- Optimize driver assignmentsget_nearby_merchants- Find alternative vendors
๐ฅ Customer Tools
notify_customer- Send notificationscontact_recipient_via_chat- Real-time communicationsuggest_safe_drop_off- Secure delivery locationsfind_nearby_locker- Parcel locker optionsrequest_address_clarification- Resolve ambiguous addresses
โ๏ธ Dispute Tools
initiate_mediation_flow- Start dispute resolutioncollect_evidence- Gather photos and statementsanalyze_evidence- Determine faultissue_instant_refund- Process refundsexonerate_driver- Clear driver of faultlog_merchant_packaging_feedback- Record issues
๐ Verification Tools
verify_delivery_attempt- GPS validationinitiate_qr_code_verification- OTP alternatives
๐ MCP Server
The project includes a full Model Context Protocol server:
# Start MCP server
python src/mcp/server.py
# Available at: http://localhost:8000
# API Documentation
# http://localhost:8000/docsClient Usage
from src.mcp.client import SynapseMCPClient
import asyncio
async def example():
async with SynapseMCPClient() as client:
result = await client.call_tool(
"get_merchant_status",
merchant_name="Pizza Palace"
)
print(result)
asyncio.run(example())๐งช Testing & Validation
python scripts/test.py # Comprehensive test suite
python scripts/setup.py --test # Setup validation
python scripts/demo.py # Feature demonstrations
python scripts/start.py check # Quick health check๐ก Example Scenarios
Try these in the CLI:
- Merchant Overload: "Driver reports Pizza Palace is overloaded with 45-minute wait"
- Delivery Dispute: "Customer complains food arrived spilled, customer ID CUST123"
- Address Issues: "Driver cannot find address: Room 301, near big temple"
- Failed Delivery: "Customer says driver never arrived but marked as failed"
๐ฎ Frontend (Next.js) - Coming Soon
cd frontend
npm run setup
npm run devPlanned Features:
- ๐ Real-time delivery dashboard
- ๐ฌ Interactive dispute resolution
- ๐ Agent analytics and monitoring
- ๐ง Tool usage visualization
๐ Documentation
docs/QUICKSTART.md- 3-step setup guidedocs/REFACTORING_SUMMARY.md- What changed and whydocs/PROJECT_STRUCTURE.md- Clean project organizationfrontend/README.md- Frontend development guide
๐ฏ Key Capabilities
The agent autonomously handles:
- Merchant Issues: Overloaded restaurants, delays, alternatives
- Customer Communication: Notifications, chat, instructions
- Dispute Resolution: Evidence collection, fault analysis, refunds
- Delivery Verification: GPS validation, secure confirmations
- Address Resolution: Landmark-based navigation assistance
๐ง Requirements
- Python 3.9+
- Google API Key (Generative AI)
- Node.js 18+ (for frontend)
๐ License
MIT License - See LICENSE file for details.
๐ Ready to revolutionize delivery coordination with modular AI architecture!
Migration Note: Original files preserved in legacy/ directory. New modular structure provides the same functionality with better organization and extensibility.