Guide

Email as Memory for AI Agents

Every inbox is a database of human decisions, commitments, and context — timestamped, authenticated, and searchable. When AI agents need to remember what was discussed, who agreed to what, or how a similar situation was handled before, email is the richest source of truth available. This guide shows how to use Nylas CLI to turn email into agent memory.

Three types of memory in your inbox

Cognitive science distinguishes between three types of long-term memory. All three exist naturally in email:

  • Semantic memory — facts and knowledge. Who is the point of contact at Acme Corp? What is the agreed-upon pricing? Email stores these as searchable facts embedded in conversations.
  • Episodic memory — events and experiences. What happened during the Q3 negotiation? When did the outage start? Email threads provide timestamped, sequential narratives of events.
  • Procedural memory — how to do things. How did we handle the last compliance audit? What template did we use for vendor onboarding? Past emails contain patterns and templates that inform future actions.

Most agent memory systems (vector databases, RAG pipelines) require you to ingest and index data upfront. Email is already indexed, already searchable, and already contains years of accumulated context.

Semantic memory: retrieve facts and knowledge

When an agent needs to answer "what do we know about X?", it can search email for relevant facts:

# Who is the contact at Acme Corp?
nylas email search "*" --from "@acme.com" --limit 10 --json \
  | jq '[.[] | {from: .from[0].email, name: .from[0].name, date}] | unique_by(.from)'

# What was the agreed pricing?
nylas email search "pricing proposal" --from sales@acme.com --json \
  | jq '.[0].body'

# What are the API rate limits for this service?
nylas email search "rate limit API quota" --from support@service.com --json \
  | jq '[.[] | {subject, date, snippet: .snippet}]'

The search is semantic in the sense that email providers perform full-text search across subjects and bodies. Combined with filters (sender, date range, labels), the agent can narrow results to exactly the knowledge it needs.

Episodic memory: replay conversation history

Episodic memory answers "what happened?" and "in what order?". Email threads are natural episode containers — each thread is a self-contained narrative with a beginning, middle, and (sometimes) end:

# Get the full history of a negotiation thread
nylas email threads show thread_negotiation123 --json \
  | jq '[.[] | {from: .from[0].name, date, snippet: .snippet}]'

# Timeline of all interactions with a specific person
nylas email search "*" --from alice@partner.com --json \
  | jq '[.[] | {date, subject, direction: (if .from[0].email == "alice@partner.com" then "received" else "sent" end)}] | sort_by(.date)'

# What happened last week?
nylas email list --limit 50 --json \
  | jq '[.[] | {from: .from[0].name, subject, date}]'

When an agent needs to prepare for a meeting, catch up on a project, or understand a relationship history, episodic retrieval from email provides richer context than any summary document.

Procedural memory: learn from past actions

Procedural memory answers "how did we do this before?". Past emails contain templates, workflows, and patterns that an agent can replicate:

# How did we handle the last vendor onboarding?
nylas email search "onboarding" --in SENT --json \
  | jq '[.[] | {to: .to[0].email, subject, date, body: .body}]'

# What template did we use for customer apologies?
nylas email search "apology" --in SENT --limit 5 --json \
  | jq '.[0].body'

# How was the last compliance report formatted?
nylas email search "compliance report" --in SENT --limit 1 --json \
  | jq -r '.[0].body'

By searching sent emails, agents find the actual language, tone, and structure used in previous communications. This is more reliable than a style guide because it reflects what was actually sent and (presumably) worked.

Pipe email memory to LLMs for reasoning

The real power comes from combining email retrieval with LLM reasoning. Search for relevant emails, extract the content, and pass it to a language model for analysis:

# Summarize all communications with a client
nylas email search "*" --from "@client.com" --limit 20 --json \
  | jq '[.[] | {from: .from[0].name, subject, date, body: .body}]' \
  > /tmp/client_emails.json

# Then pass to your LLM of choice for summarization
# (This example uses the file as context for a prompt)

# Or use MCP directly — ask your assistant:
# "Search my email for all conversations with @client.com
#  and summarize the key decisions we have made together."

Through MCP, the assistant handles the search-and-reason loop automatically. Ask it to "find what we agreed with Acme about pricing" and it will search your email, read the relevant threads, and synthesize an answer.

Build contextual recall into agent workflows

The most useful pattern is contextual recall — the agent automatically retrieves relevant email history before taking an action:

# Before replying to a vendor, check the relationship history
VENDOR="vendor@supplier.com"

# Get recent interactions
nylas email search "*" --from "$VENDOR" --limit 10 --json \
  | jq '[.[] | {date, subject, direction: (if .from[0].email == env.VENDOR then "in" else "out" end)}]'

# Check if there are any unresolved issues
nylas email search "issue problem urgent" --from "$VENDOR" --json

# Look at the most recent thread for ongoing context
nylas email search "*" --from "$VENDOR" --limit 1 --json \
  | jq '.[0].thread_id' -r \
  | xargs -I{} nylas email threads show {} --json \
  | jq '[.[] | {from: .from[0].name, date, snippet: .snippet}]'

This is the email equivalent of a RAG (Retrieval-Augmented Generation) pipeline, but without the setup cost. No embeddings, no vector store, no chunking strategy — just search and read.

Use MCP for conversational memory access

When working through an MCP-compatible assistant, memory retrieval becomes natural language:

# Set up MCP
brew install nylas/nylas-cli/nylas
nylas auth login
nylas mcp install

# Then ask your assistant natural language questions:
#
# "What was the last thing Sarah from Acme said about the timeline?"
# "Find the email where we agreed on the project scope."
# "What template did I use the last time I sent a cold outreach email?"
# "Summarize my email thread with the legal team about the NDA."
# "When did the vendor first mention the price increase?"

The assistant translates these into email searches, reads the results, and synthesizes answers. It can handle follow-up questions, cross-reference multiple threads, and maintain context across the conversation.

Common memory retrieval patterns

Memory needSearch patternCLI command
Who is responsible for X?Search for topic + role keywordsnylas email search "project lead responsible"
What was decided?Search for decision language in threadsnylas email search "agreed decided confirmed"
When did something happen?Date-filtered search for the eventnylas email search "outage" --after 2026-03-01
How did we handle this before?Search sent emails for similar past actionsnylas email search "onboarding" --in SENT
What is the current status?Latest message in a threadnylas email threads show thread_id --json

Email memory vs. vector databases

Vector databases are powerful, but they require infrastructure and maintenance. Email memory has unique advantages:

  • Zero setup — your inbox is already populated with years of data. No ingestion pipeline needed.
  • Always current — new emails are searchable immediately. No re-indexing lag.
  • Rich metadata — every memory comes with sender, timestamp, thread context, and authentication headers. Vector stores typically lack this.
  • Natural boundaries — threads provide natural context windows. Each conversation is a self-contained unit of memory.
  • Authenticated source — email headers prove who said what and when. Vector stores have no provenance chain.

The tradeoff is that email search is keyword-based, not semantic. You cannot ask "find emails where the tone was frustrated" directly — but you can retrieve the emails and ask an LLM to assess the tone.

Frequently asked questions

How far back can agents search?

As far back as your email provider retains messages. Gmail, Outlook, and Exchange typically retain all emails indefinitely. The Nylas API provides access to the full mailbox history.

Is email search fast enough for real-time agent workflows?

Yes. Search results typically return within 1-3 seconds. For latency-sensitive workflows, cache frequently accessed results or pre-fetch context before the agent needs it.

Can agents search across multiple email accounts?

Yes. Authenticate multiple accounts with nylas auth login and specify which grant to use with --grant-id. An agent managing team communications can search across all team members' inboxes (with their consent and authentication).

How do I prevent agents from accessing sensitive emails?

Use a dedicated email account for agent workflows. For shared accounts, rely on the MCP confirmation flow (the assistant asks before taking actions) and audit logging to monitor what the agent accesses.


Next steps