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 any email inbox into agent memory.

Written by Hazik Director of Product Management

Reviewed by Hazik

VerifiedCLI 3.1.1 · Gmail, Outlook · last tested April 11, 2026

Three types of memory in your inbox

Email inboxes contain three distinct types of long-term memory that cognitive science has studied for decades: semantic (facts), episodic (events), and procedural (how-to patterns). A typical business user accumulates over 50,000 emails per year according to Radicati Group research, creating a structured memory store that no vector database can replicate without significant ingestion work.

  • 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

Semantic memory stores factual knowledge — names, agreements, prices, technical specifications — that an AI agent can retrieve on demand. The Nylas CLI's email search command runs full-text search across message subjects and bodies, returning results in under 2 seconds on Gmail and Outlook. Combined with sender and date filters, the agent narrows millions of stored messages to the exact facts it needs.

The following examples show three common fact-retrieval patterns: identifying contacts by domain, extracting pricing from proposals, and pulling technical details from support threads. Each command pipes JSON output through jq for structured extraction.

# 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}]'

Email providers like Gmail index messages within 1-3 seconds of delivery, making new facts immediately searchable. The --from filter scopes results by sender domain, while --limit controls result volume. This approach avoids the 20-40 minute embedding pipeline that vector databases typically require before new documents become queryable.

Episodic memory: replay conversation history

Episodic memory reconstructs what happened and in what order. Email threads serve as natural episode containers where each thread groups 5-30 related messages into a self-contained narrative with timestamps, participants, and sequential context. According to RFC 5322, the References and In-Reply-To headers create a reliable chain of custody that AI agents can traverse to reconstruct an event timeline.

The Nylas CLI's email threads show command retrieves an entire conversation thread by ID, while email search with sender filters builds a chronological timeline of all interactions with a specific person. The email list command fetches the most recent messages for a broader "what happened this week" view.

# 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}]'

Episodic retrieval from email provides richer context than summary documents because it preserves the exact sequence of statements, who made them, and when. An agent preparing for a meeting can reconstruct the full negotiation arc from a single thread instead of relying on someone's after-the-fact notes.

Procedural memory: learn from past actions

Procedural memory answers "how did we do this before?" by retrieving the actual emails sent in similar past situations. According to McKinsey research, knowledge workers spend 28% of their work week searching for and gathering information. An AI agent with access to sent email history can skip that search entirely by finding the exact template, tone, and structure used in a previous communication — often within 1-2 seconds.

The --in SENT flag filters results to only outbound messages, which is where procedural patterns live. Sent emails capture what was actually delivered and (presumably) worked, making them more reliable than any style guide or internal wiki.

# 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'

Extracting the .body field from past sent messages gives the agent a ready-made template. For customer apology emails, vendor onboarding checklists, or compliance reports, the format is already proven — the agent just adapts the details to the current situation.

Pipe email memory to LLMs for reasoning

The highest-value pattern combines email retrieval with LLM reasoning. An agent searches for relevant messages, extracts structured JSON, and passes it to a language model for summarization, decision extraction, or sentiment analysis. With GPT-4o supporting 128,000 tokens of context (roughly 400-500 emails worth of snippets), an agent can synthesize months of communication history in a single prompt.

The Nylas CLI's --json flag outputs structured data that pipes directly into jq for field extraction. Writing results to a temp file lets the agent pass them as context to any LLM. Through MCP, this search-and-reason loop runs automatically without intermediate files.

# 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 without shell commands. Ask it to "find what we agreed with Acme about pricing" and the assistant searches your email, reads the relevant threads, and synthesizes an answer — typically completing the full cycle in under 10 seconds.

Build contextual recall into agent workflows

Contextual recall means the agent automatically retrieves relevant email history before taking any action — replying, scheduling, or escalating. This pattern mirrors Retrieval-Augmented Generation (RAG) but skips the infrastructure overhead. A standard RAG pipeline requires an embedding model, a vector store like Pinecone or Weaviate, and a chunking strategy. Email-based recall needs only 3 CLI commands: search for recent interactions, check for unresolved issues, and load the latest thread.

The script below demonstrates a pre-reply workflow that builds a relationship context profile for any vendor. It runs 3 searches sequentially — recent messages, flagged issues, and the most recent thread — giving the agent full context in under 5 seconds before composing a response.

# 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}]'

The third command chains jq output into xargs to load the full thread for the most recent conversation. This gives the agent both the broad relationship timeline and the specific current context, eliminating the need for a separate memory store.

Use MCP for conversational memory access

The Model Context Protocol (MCP) turns email memory retrieval into natural language queries. Instead of writing shell commands, the user asks questions like "what did Sarah say about the timeline?" and the MCP-connected assistant translates that into the appropriate email search call. Setup takes under 60 seconds: install the CLI, authenticate, and run nylas mcp install to configure your assistant.

The nylas mcp install command writes the MCP server configuration for Claude Code, Cursor, VS Code Copilot, or Windsurf. Once configured, the assistant has access to all email, calendar, and contact tools — including the search and thread-retrieval commands needed for memory recall.

# 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 natural language into email searches, reads the results, and synthesizes answers. It handles follow-up questions, cross-references multiple threads, and maintains context across the conversation — all without the user writing a single CLI command or jq expression.

Common memory retrieval patterns

Five memory retrieval patterns cover roughly 90% of what AI agents need from email: identifying responsible people, extracting decisions, pinpointing event dates, replicating past procedures, and checking current status. Each pattern maps to a specific Nylas CLI search strategy using keyword targeting, folder filtering, or date constraints. The table below shows the mapping from memory need to CLI command.

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

Email inboxes and vector databases both store retrievable information, but they differ in setup cost, latency, and metadata richness. A Pinecone or Weaviate deployment requires provisioning infrastructure, building an embedding pipeline, and maintaining index freshness — typically 4-8 hours of initial setup plus ongoing operational cost. Email memory requires zero setup because the inbox is already indexed by the provider, already searchable, and already contains years of accumulated context.

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

The tradeoff is that email search is keyword-based, not embedding-based. You can't ask "find emails where the tone was frustrated" directly — but you can retrieve the emails and ask an LLM to assess the tone. For most agent memory needs, keyword search with metadata filters is sufficient.

Frequently asked questions

These questions cover the most common concerns when using email as agent memory: search depth, latency, multi-account access, and access control. Gmail retains messages indefinitely by default, and Outlook retains them for the lifetime of the account, so email memory can span years or even decades of context.

How far back can agents search?

As far back as your email provider retains messages. Gmail retains all emails indefinitely by default, and Outlook retains them for the account's lifetime. Exchange, Yahoo, iCloud, and IMAP providers also retain messages indefinitely unless administrators set explicit retention policies. The Nylas API provides access to the full mailbox history regardless of provider.

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

Yes. Search results from the Nylas CLI typically return within 1-3 seconds for Gmail and Outlook. For latency-sensitive workflows, cache frequently accessed results or pre-fetch context before the agent needs it. Even searching across 100,000+ messages completes in under 3 seconds because the provider handles the indexing.

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 the nylas audit logs show command to monitor what the agent accesses. The audit log records every CLI command, the invoker (human or AI), and the timestamp.


Next steps