Back to Changelog

AI Email Intelligence, Search, and Auto-Labeling

apisdknew-feature

AgentPost now includes a suite of AI-powered features for email intelligence: automatic embedding generation, hybrid full-text search, rule-based auto-labeling with AI classification, and structured data extraction from email content. All AI features require an OPENAI_API_KEY environment variable and are gracefully disabled when it is not set.

AI Email Intelligence

AgentPost generates email embeddings automatically using OpenAI's text-embedding-3-small model. Embeddings are created in the background via pg-boss workers whenever a new message arrives.

Per-org AI settings let each organization configure their own setup:

  • Bring your own key -- Organizations can provide their own OpenAI API key for full control over costs
  • Platform key -- Use a platform-provided key with monthly token budgets and automatic circuit breaker

When the monthly token budget is exhausted, the circuit breaker pauses embedding generation until the next billing cycle. An admin endpoint allows budget overrides when needed.

A backfill service generates embeddings for messages that existed before AI was enabled:

// Trigger backfill for an organization
await client.ai.backfill("org_01JQ...");

Prometheus metrics provide visibility into embedding throughput, latency, token consumption, and budget utilization.

The search API combines vector similarity (from AI embeddings) with traditional keyword matching using Reciprocal Rank Fusion (RRF) scoring for high-quality results:

// TypeScript
const results = await client.search.query({
  query: "quarterly revenue report",
  inbox_id: "inbox_01JQ...",
  filters: {
    date_from: "2026-01-01",
    labels: ["finance"],
  },
});
# Python
results = client.search.query(
    query="quarterly revenue report",
    inbox_id="inbox_01JQ...",
    filters={
        "date_from": "2026-01-01",
        "labels": ["finance"],
    },
)

Available filters include inbox, date range, labels, and read status.

A 3-second timeout on embedding generation ensures search stays responsive. If the embedding times out or AI is not configured, AgentPost falls back to keyword-only search automatically -- so search always works, with or without AI.

Search analytics track query patterns and result quality:

GET /search/analytics

Auto-Labeling

Create classification rules that automatically label incoming emails:

await client.autoLabelRules.create({
  name: "Support Requests",
  match_type: "ai",  // or "keyword"
  label_id: "label_01JQ...",
  conditions: {
    description: "Emails requesting help or reporting issues",
  },
});

Preset rules are available for common patterns including spam detection, support requests, billing inquiries, and more. Classification uses GPT-4o-mini and runs automatically on message.received events via a background worker.

Data Extraction

Configure structured data extraction per inbox to pull specific fields from incoming emails:

await client.inboxes.updateExtractionConfig("inbox_01JQ...", {
  schema: {
    invoice_number: { type: "string", description: "Invoice or PO number" },
    amount: { type: "number", description: "Total amount in dollars" },
    due_date: { type: "string", description: "Payment due date" },
  },
});

Extracted data is attached to messages as structured metadata, ready for your agents to consume without parsing email bodies.

Console Integration

  • Search results page with filters, accessible via Ctrl+K command palette from anywhere in the console
  • Auto-label rule management under the Intelligence navigation group -- create, edit, test, and delete rules
  • Extraction config editor inline on the inbox detail page -- define schemas and preview extraction results