Inbox Agent — AI Classification, Extraction & Evaluation Specification

Status: Implementation Baseline
Audience: Cursor, Charter, engineering, QA
Purpose: Define the AI decision layer used to understand mail while preserving deterministic, auditable behavior.

1. Objectives

The Inbox Agent uses AI to convert unstructured email content into structured, reviewable signals that support inbox triage, search, contact intelligence, follow-up, and future automation. AI output is advisory unless an explicitly authorized workflow permits an action.

Core principles:

2. Processing Boundary

AI processing occurs against the canonical MailMessage, with mailbox-specific context supplied from MessageInstance when relevant. A single logical message may have multiple instances; content classification must not be duplicated merely because the same message exists in more than one mailbox/folder/account context.

Processing stages:

  1. Canonical message eligibility check.
  2. Content normalization and quoted-history/signature handling.
  3. Lightweight deterministic extraction.
  4. AI classification.
  5. AI entity/action extraction.
  6. Confidence and validation gates.
  7. Persistence of immutable inference result.
  8. Policy evaluation.
  9. Optional human review or downstream workflow.

3. Classification Taxonomy

The implementation must support a versioned taxonomy rather than hard-coded UI labels. Initial semantic dimensions should include:

Taxonomy values are extensible. Unknown/unclassified is always a valid value.

4. Structured Extraction

AI may extract:

Each extracted item must carry:

Do not silently overwrite canonical contact data with inferred values. Contact consolidation is a separate governed process.

5. Thread Context

Models may use prior canonical messages in the conversation/thread when needed. Thread context must:

6. Inference Contract

Every model call used for persisted decisions must produce schema-validated output. Persist at minimum:

Invalid structured output must not be coerced into valid business data without an explicit repair/validation step.

7. Confidence and Human Review

Confidence thresholds are configuration, not embedded constants.

Recommended behavior:

Any future automatic action must have an independent policy threshold stricter than the threshold for simply displaying an AI suggestion.

8. Deterministic Policy Layer

The model describes the message; application policy decides what may happen.

Examples of deterministic checks:

No model response may directly invoke provider mutation.

9. Prompt and Model Versioning

Prompts are source-controlled implementation assets. Changes that can alter persisted semantics require a new prompt/version identifier. Model changes must be independently versioned.

Reprocessing must create a new inference record rather than erase the previous result. The application may designate one result as current while retaining history for audit and evaluation.

10. Evaluation Framework

Evaluation must cover classification, extraction, summaries, abstention, and policy-supporting signals.

Maintain a curated evaluation corpus containing representative:

Metrics should include:

High-impact false positives must be weighted more heavily than cosmetic classification errors.

11. Golden Set and Regression Gates

A human-reviewed golden set is required before classification behavior is considered production-ready. Each material prompt/model/taxonomy change must run against the golden set.

Release gates:

Evaluation results must be reproducible from model/prompt/schema version metadata.

12. Security and Prompt Injection

Email content is untrusted data. Instructions contained in email bodies, attachments, signatures, or quoted messages must never be treated as system/developer instructions.

The AI layer must not:

13. Failure Handling

Failures are classified as retryable or terminal.

Retryable examples: transient provider/model errors, timeouts, rate limits.
Terminal examples: unsupported content, repeated schema failure, permanently unavailable content.

A failed inference must not block synchronization of the underlying mail. Processing state and retry metadata are persisted separately from the canonical message.

14. Acceptance Criteria

The AI subsystem is implementation-ready when: