Turn starred Gmail emails into a Mem knowledge base
Every 30 minutes during your workday, starred Gmail messages become clean, searchable Mem notes filed into the right collection.
Build me an agent workflow that turns my starred Gmail emails into a clean, searchable Mem knowledge base.
Trigger: cron, every 30 minutes during my working hours (default Mon–Fri, 8am to 7pm in my local timezone). I want this expressed as a schedule the platform can actually run, since Gmail is not a first-class poll trigger.
Two integrations, both first-class: Gmail (List Messages, Get a Message, Modify Message Labels, and Create a Label if the label does not exist yet) and Mem (Search Notes, Create Note, List Collections, and Create Collection when needed).
On each run the agent should do the following, in order:
1. Make sure a Gmail user label called "Saved-to-Mem" exists. If Get a Label / List Labels does not find it, call Create a Label to make it. Cache the label id for the rest of the run.
2. Call Gmail List Messages with the query is:starred -label:Saved-to-Mem to get the candidate message ids. Page through results only if there are more than can be handled in one run; a reasonable per-run cap (say 25 messages) is fine so we do not blow the Mem complexity quota.
3. For each candidate message, call Gmail Get a Message with format=full to pull the subject, sender, date, RFC-822 Message-ID header, and the message body. Prefer text/plain; fall back to text/html and strip tags to clean markdown.
4. Dedupe defensively. Call Mem Search Notes for the Gmail message id (the RFC-822 Message-ID header value, not the Gmail thread id). If a note already exists that references that id, skip creating a new note and jump straight to the labeling step below. This protects against a Saved-to-Mem label that failed to write on a previous run.
5. Pick a Mem collection. Call Mem List Collections once per run and cache it. For each email, match the best collection by comparing sender domain, subject keywords, and a short AI-generated topic guess to existing collection titles and descriptions. If nothing scores a reasonable match, call Mem Create Collection with a clean, human name (project name, client name, or topic) and use that.
6. Call Mem Create Note. The note content is markdown. Mem uses the first line as the title, so start with '# {subject}'. Then a small metadata block: 'From: {sender name} <{email}>', 'Date: {ISO date}', 'Gmail Message-ID: {rfc822 id}', and a link back to the Gmail thread. Follow that with a two-to-four-sentence AI summary under a '## Summary' heading, then the cleaned message body under a '## Body' heading. Attach the note to the chosen collection via the create-note collections field. Preserve any inline links from the email.
7. Call Gmail Modify Message Labels to add the Saved-to-Mem label to that message id. This is what keeps the next run's List Messages query from re-processing the same email.
Error handling: if Create Note fails, do not label the Gmail message; let the next run retry. If Modify Message Labels fails after a successful Create Note, log it but do not create a second note next run because step 4's Search Notes dedupe will catch it. Respect Mem's rate limits (100 requests/min, 200 complexity tokens/min): if you hit a 429, back off for the Retry-After duration and continue.
Output: at the end of the run, produce a short internal summary (how many messages were swept, how many notes created, which collections they landed in, any skips or errors). No email or Slack recap needed. No em dashes anywhere in the copy the agent writes.
Additional information
What does this prompt do?
- Sweeps your Gmail every 30 minutes and grabs anything you have starred since the last run.
- Saves each starred email into Mem as a tidy markdown note with the subject as the title, sender and date up top, and a short AI summary above the cleaned message body.
- Files the note into the Mem collection that best matches the topic, and spins up a new collection when nothing fits.
- Skips anything already saved, so re-runs never create duplicates and your starred inbox turns into a real knowledge base.
What do I need to use this?
- A Gmail account you can connect (personal or Google Workspace).
- A Mem account with an API key from Settings, API in the Mem web app.
- A working habit of starring the emails you want to remember.
How can I customize it?
- Change the schedule. Every 30 minutes during working hours is the default, but you can go hourly, twice a day, or only on weekdays.
- Pick a different Gmail signal. Swap starring for a specific label, an importance marker, or a saved search like emails from your VCs.
- Tune the note format. Add a tag list, drop the AI summary, or route certain senders into a dedicated collection like Clients or Research.
Frequently asked questions
Will the same email get saved twice if I star it, unstar it, and star it again?
Can I use a different Gmail signal instead of starring?
How does the workflow decide which Mem collection an email belongs in?
Does this work with a Google Workspace inbox?
What ends up in the note itself?
Related templates
Stop losing the emails you swore you would come back to.
Connect Gmail and Mem once, then just keep starring. Geni turns your starred inbox into a real searchable knowledge base in the background.