Skip to main content
In this tutorial, we’ll walk through how to ingest your Gmail emails into Honcho. By the end, each email thread will be a Honcho session and each participant will be a peer — giving your agents memory of who said what across your email history. This guide includes a ready-to-run Python script that handles everything: Gmail OAuth, thread fetching, participant extraction, and Honcho ingestion. You can run it as-is or use the full tutorial below to understand each piece as you go.
The full script is available on GitHub. This is a developer-focused tutorial — it requires creating a Google Cloud project and OAuth credentials.

TL;DR

If you just want to get your emails into Honcho, here’s everything you need.

1. Set Up Google Cloud Credentials

Follow Google’s official Gmail API Python Quickstart to:
  1. Create a Google Cloud project and enable the Gmail API
  2. Configure the OAuth consent screen
  3. Create OAuth credentials (select Desktop app as the application type)
  4. Download the credentials JSON into the same directory as the script
The script auto-detects Google’s default client_secret_*.json filename, so no renaming needed. The script only needs the gmail.readonly scope.

2. Install Dependencies

3. Preview with a Dry Run

On first run, a browser window opens for OAuth consent. After authorizing, a token.json file is created — future runs skip this step.

4. Load into Honcho

You can filter threads with Gmail search syntax:
That’s it — your emails are now queryable in Honcho. Read on if you want to understand how the script works and the design decisions behind it.

Full Tutorial

How Gmail Maps to Honcho

The core idea is straightforward: each Gmail thread becomes a Honcho session, and each email participant becomes a peer. Here’s the full mapping:

Email as Peer ID

The script normalizes email addresses into URL-safe peer IDs — alice@example.com becomes alice-example-com. This means the same person is automatically deduplicated across threads. If Alice emails you in 10 different threads, all of those conversations accumulate under a single peer.
This also means peers are consistent across data sources. If you import Granola meetings and Gmail threads for the same person, they merge under the same peer ID.

Extracting Participants

Every email has a sender, recipients, and optionally CC/BCC addresses. The script extracts all of these to build a complete picture of who’s involved in each thread:
Display names are extracted when available (e.g., Alice Smith <alice@example.com> → name: “Alice Smith”). When only an email is present, the script generates a name from the local part.

Message Attribution and Timestamps

Each email becomes a message attributed to its sender via peer.message(). The original email timestamp is preserved using created_at, so Honcho sees the conversation in chronological order — not the order you imported it.

Multi-Peer Sessions

Each thread’s session is linked to all participants using session.add_peers(). This means when you query Honcho about a peer, it has context not just from their messages but from the full conversations they participated in.

Stripping Quoted Replies

Email threads are full of quoted replies — each message repeats everything above it. The script strips these out so only the new content is stored per message, avoiding duplication in Honcho’s memory:

Querying After Import

Once your emails are in Honcho, you can query any peer:

CLI Reference

Troubleshooting

”No client_secret*.json file found”

Download OAuth credentials from Google Cloud Console and place the client_secret_*.json file in the same directory as the script.

”Access blocked: This app’s request is invalid”

Your OAuth consent screen may not be configured correctly. Ensure you’ve added the gmail.readonly scope.

”Token has been expired or revoked”

Delete token.json and run the script again to re-authenticate.

Rate Limits

The script includes a small delay when creating peers to avoid hitting Honcho’s rate limits. For large imports (100+ threads), consider running in batches.

Unique Messages

Use an AI assistant in your inbox? Want to parse out its messages differently? Feel free to modify and improve the structure of this script to fit your bespoke email setup. This script was written for agents and as such is easy to update with your coding assistant.

Full Script

Next Steps

Design Patterns

See how the Granola integration maps to common Honcho patterns.

GitHub Repository

Source code and example script.