AgentBox turns your email inbox into a smart AI-powered assistant.
It listens to incoming emails (via SendGrid Inbound Parse), analyzes the content, generates intelligent replies using OpenAI or Phronetic agents, and automatically sends responses — all while maintaining distinct personalities and prompts for each mailbox identity.
-
Email → AI → Reply Loop
Receives inbound emails and auto-responds using OpenAI or Phronetic API. -
Per-Identity Personalization
Each mailbox (e.g.agents@nhtech.link,recruitment@nhtech.link) has its own pre-prompt, post-prompt, CC address, and reply identity stored in Postgres. -
Dynamic Reply Identities
Replies are sent from the identity that received the message. -
Stats Dashboard
Tracks total emails processed, success/failure rates, average response time, and model usage. -
Simple REST API
Manage agents, create/update their roles, and view system statistics. -
CORS-Enabled
Ready for integration with any web dashboard or frontend.
Incoming Email (SendGrid Inbound Webhook)
↓
FastAPI /inbound_email
↓
Extract email text
↓
Lookup identity settings (Postgres)
↓
Call OpenAI or Phronetic
↓
Compose + Send reply via SendGrid
↓
Log stats in Postgres
| Component | Technology |
|---|---|
| Backend API | FastAPI |
| AI Engine | OpenAI GPT-4o / Phronetic Agent API |
| Database | PostgreSQL |
| Email Handling | SendGrid Inbound Parse + Send API |
| HTTP Client | httpx |
| ORM / DB Layer | asyncpg |
| HTML Parsing | BeautifulSoup4 |
| Environment | python-dotenv |
| Runtime | Uvicorn |
git clone https://github.com/your-org/agentbox.git
cd agentboxpython -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtSENDGRID_API_KEY=your_sendgrid_key
OPENAI_API_KEY=your_openai_key
PHRONETIC_API_KEY=optional_phronetic_key
PHRONETIC_AGENT_ID=agnt_eb688b3b-60dd-49d4-966c-76edda72705e
DATABASE_URL=postgresql://user:password@localhost:5432/agentbox
REPLY_FROM=agents@nhtech.link
AI_MODEL=gpt-4o-miniRun these SQL migrations manually (or through a tool like pgAdmin):
CREATE TABLE agent_identity_prompts (
id SERIAL PRIMARY KEY,
identity_email VARCHAR(255) UNIQUE NOT NULL,
job_role VARCHAR(255),
description TEXT,
pre_prompt TEXT,
post_prompt TEXT,
reply_from VARCHAR(255),
cc_email VARCHAR(255),
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE email_statistics (
id SERIAL PRIMARY KEY,
identity_email VARCHAR(255),
sender_email VARCHAR(255),
subject TEXT,
model_used VARCHAR(100),
used_phronetic BOOLEAN DEFAULT FALSE,
success BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT NOW(),
tokens_used INT DEFAULT 0,
response_time_ms INT DEFAULT 0,
error_message TEXT
);uvicorn main:app --reloadThe API will be live at:
http://localhost:8000
| Endpoint | Method | Description |
|---|---|---|
/inbound_email |
POST | Handles SendGrid inbound webhook and generates AI replies |
/agent_identity_prompts |
POST | Creates a new agent (auto-generates prompts via OpenAI) |
/stats |
GET | Returns summary + recent activity metrics |
/stats/{identity} (planned) |
GET | View per-identity stats (future) |
curl -X POST "http://localhost:8000/agent_identity_prompts" \
-H "Content-Type: application/json" \
-d '{
"identity_email": "recruitment@nhtech.link",
"job_role": "Recruitment Coordinator",
"description": "Handles job applications, schedules interviews, and responds with empathy and professionalism.",
"reply_from": "recruitment@nhtech.link",
"cc_email": "hr@nhtech.link"
}'curl http://localhost:8000/statsResponse:
{
"summary": {
"total_emails": 47,
"successful": 45,
"failed": 2,
"avg_response_time": 1245,
"phronetic_used": 18
},
"recent_activity": [
{
"identity_email": "recruitment@nhtech.link",
"sender_email": "applicant@example.com",
"subject": "Frontend Developer Position",
"model_used": "gpt-4o-mini",
"success": true,
"response_time_ms": 1221,
"created_at": "2025-10-10T19:45:22"
}
]
}-
Go to SendGrid → Settings → Inbound Parse
-
Add your domain (e.g.,
nhtech.link) -
Point the destination URL to your server’s endpoint:
https://yourdomain.com/inbound_email -
Enable “POST the raw email” option.
- FastAPI handles all webhooks and REST endpoints.
- PostgreSQL stores agent identity configurations and logs.
- OpenAI / Phronetic provides AI-generated email replies.
- SendGrid manages both inbound and outbound email flow.
- CORS enabled for all origins to support browser-based dashboards.
- Restrict CORS in production to trusted domains.
- Rotate API keys regularly.
- Run behind HTTPS (required by SendGrid).
- Add authentication for admin endpoints (
/agent_identity_prompts,/stats).
Contributions and extensions are welcome! Ideas include:
/stats/{identity}endpoint- Admin UI for managing agents
- Token cost dashboard
- WebSocket live feed for inbox monitoring
MIT License © 2025 NightHack Technology Pvt. Ltd.
“AgentBox — Because your inbox deserves an intelligent assistant.”
---
Would you like me to add a **“Quick Deploy to Render.com”** section next — with prebuilt environment variables and start command for one-click Render deployment?