Inbound Mail Agent
HomebrewedSES receives hello@opglabs.com; the Lambda agent drops virus, quarantines spam, runs a cheap System 1 category rank (gpt-4o-mini or Jev), then fans out to Processing Q and Thank-you Q — with DynamoDB idempotency, an inbound dead letter queue, and bounce or complaint logging.
Amazon SES · Lambda · S3 · DynamoDB · SQS · SNS · CloudWatch · OpenAI gpt-4o-mini / Typesafe Jev · Terraform
Overview
Layer 2 Decide on the Mental Model. One Inbound Mail agent in the SES receipt Lambda (opglabs-prod-inbound-api). A second Lambda (mail-events) only logs bounce and complaint notifications.
Behavior
- Verdict-gated disposition. Virus FAIL drops immediately; spam FAIL quarantines and stops; only clean mail is stored under
inbound/and handed off. - No SES send on inbound. Sends run on Outbound Mail (Processing Q and Thank-you Q) so send retries cannot re-run categorize or double-claim inbound work.
- Routing (Anthropic). Clean mail is ranked by a low-cost LLM call — OpenAI
gpt-4o-minior Typesafe Jev — into an allowlisted category slug (orgeneral). See Building effective agents. - Parallelization (Anthropic). After rank, inbound enqueues Processing Q and Thank-you Q together (
action=queued). - Spam-scanned, still untrusted. Email body is wrapped as untrusted data after SES scan. The model evaluates request intent only.
- Idempotent claim. DynamoDB keyed by message id: terminal actions include
queued,forwarded,quarantined,dropped,skipped. - Retry then dead letter queue. A failed inbound async invoke is retried by Lambda (up to 2 times), then the inbound SQS DLQ. Each outbound queue has its own DLQ.
- Delivery events separate from processing. Bounce and complaint come via SNS into
mail-events.
Receipt flow
Clean mail is categorized (Routing), then fans out to both outbound queues (Parallelization); spam quarantines; virus drops. Diagram key: ✦ AI agent · second line = Anthropic workflow · purple = actor · white = service.
---
config:
theme: default
themeVariables:
background: "#ffffff"
fontSize: "14px"
---
flowchart TB
person[Person]
ses[SES plus S3 raw]
agentNode["✦ Inbound Mail agent
Routing"]
rejectNode["Drop virus or
quarantine spam"]
skipNode["Already done
skip resend"]
systemOne["✦ System 1 categorize
Routing"]
labelNode["Category label
e.g. project_inquiry"]
queuedNode["action queued
Parallelization"]
procQ[Processing Q]
thanksQ[Thank-you Q]
outbound["✦ Outbound Mail
Parallelization"]
mailEvents["mail-events
bounce and complaint"]
retry[Lambda retry]
dlq[Inbound DLQ]
alarm[CloudWatch alarm]
itSupport[IT Support]
person --> ses --> agentNode
ses -.-> mailEvents
agentNode -->|virus or spam FAIL| rejectNode
agentNode -->|already done| skipNode
agentNode -->|clean| systemOne
systemOne -->|top ranked label| labelNode
labelNode --> queuedNode
queuedNode --> procQ
queuedNode --> thanksQ
procQ --> outbound
thanksQ --> outbound
agentNode -->|error| retry
retry -->|retries exhausted| dlq
dlq --> alarm --> itSupport
classDef agent fill:#e8f0ee,stroke:#0f3d36,stroke-width:2px,color:#0d0d0d
classDef service fill:#fafaf8,stroke:#c8c8c2,stroke-width:1px,color:#0d0d0d
classDef actor fill:#f3eef8,stroke:#6b4f9a,stroke-width:2px,color:#0d0d0d
class agentNode,systemOne,outbound agent
class ses,rejectNode,skipNode,labelNode,queuedNode,procQ,thanksQ,mailEvents,retry,dlq,alarm service
class person,itSupport actor
Contact traffic hits hello@opglabs.com over SES. Quarantined mail is never processed for send. Clean mail is ranked into one of nine contact categories by a low-cost LLM call (gpt-4o-mini or Typesafe Jev); inbound then enqueues Outbound Mail Processing Q and Thank-you Q together. Inbound does not send mail itself.
This agent is part of the OPG Labs project (Project tab).