What You’ll Build
Your Granola meeting notes, your Gmail inbox and your sent mail go into one cognee memory. When a new email arrives, an agent drafts your reply: the facts come from what was said in your meetings, and the tone comes from how you write. The draft is printed, never sent. Building the memory takes threecognee.remember calls, one per source, and drafting the reply takes two cognee.recall calls.
The complete cookbook is
examples/cookbooks/personalized_email/.
Try It on Sample Data
The sample is Mira Lang’s week. Twelve days ago, on a call, she promised Priya Shah pilot pricing by Friday and said SSO supports SAML today, with OIDC coming next month. Yesterday Priya emailed asking when the pilot can start, whether SSO supports OIDC, and where the pricing is. You need only an LLM key, no Gmail or Granola account.LLM_API_KEY alone is enough for OpenAI, cognee’s default for both the LLM and the embeddings. Other providers, such as Anthropic, Gemini, Azure OpenAI, AWS Bedrock or a local model through Ollama, need a few more lines in the same .env: LLM Providers and Embedding Providers list them for each provider. Set both, because embeddings you leave at the default still need an OpenAI key.
- Terminal
- Coding agent
[clear] Forgot the dataset personalized_email instead. Your wording will differ from run to run.
Run It on Your Data
Gmail is required. Granola is optional: without it, pass--no-granola to skip meetings. Set up each source you use:
- Gmail
- Granola
The cookbook reads your mail read-only through a Google OAuth client you create once:
- In the Google Cloud Console, create or pick a project and enable the Gmail API.
- Configure the OAuth consent screen. While the app is in Testing, add your own Google account as a test user.
- Go to Credentials → Create credentials → OAuth client ID, choose Desktop app, and download the JSON file.
- Save it as
credentials.jsonin the cookbook folder, next topersonalized_email.py. - Install the Google client libraries with
uv sync --extra gmail.
token.json next to credentials.json, with the gmail.readonly scope. Gmail Ingestion covers the connector in more detail.MY_NAME(optional): your name as it appears in your email, in.env, so the draft speaks as you. A sample run always answers as Mira, whose mailbox the sample is.credentials.jsonandtoken.jsonare git-ignored. Never commit them.
--check reports what is missing without doing any work. The first run opens a browser so you can let it read your Gmail. Running it again skips content cognee already holds; add --clear to forget the dataset first and start over from your sources as they are now. Each script also runs alone, for example uv run python examples/cookbooks/personalized_email/scripts/draft.py.
How It Works
Step 1: Start From an Empty Memory
Source:scripts/clear.py
This step forgets what an earlier run remembered, so old copies never mix with new ones. It runs only with --clear, which a sample run turns on by default; --no-clear keeps the dataset.
cognee.forget(dataset="personalized_email"), which deletes the dataset and everything extracted from it. On your own data, use --clear only to start over.
Step 2: Remember Your Meeting Notes
Source:scripts/ingest_granola.py
This step saves your meeting notes so the agent can use them later. It runs unless you pass --no-granola.
--days N to change that. With args.sample, it reads the sample meetings instead; every ingest step works this way. cognee’s part is one call: cognee.remember, into the dataset personalized_email with node_set=["meetings"]. remember turns text into a knowledge graph of people, decisions and dates. A dataset is the named memory everything goes into. A node set is a tag on what you remember, so you can later recall from that part alone.
Step 3: Remember Your Inbox and Sent Mail
Source:scripts/ingest_email.py
This step saves your newest emails: the inbox for facts, your sent mail as a sample of how you write. It takes the newest 50 inbox emails and the newest 50 sent emails, not your whole mailbox. Pass --emails N to change how many.
cognee.remember once per label, with cognee’s Gmail connector, gmail_source, as the input. Inbox mail gets the node set inbox and sent mail gets sent_mail. That split matters in the next step: the agent can ask for your own writing without mixing in other people’s. write_disposition="merge" with primary_key="id" merges emails by message id, so a rerun does not store the same email twice.
Step 4: Draft the Reply
Source:scripts/draft.py
This step reads the newest email in your inbox and prints the reply you would write. On the sample, it writes as Mira.
cognee.recall calls. The first uses query_type=SearchType.CHUNKS with node_name=["sent_mail"]. It returns three of your own emails as raw text, so the draft can copy your exact greeting and sign-off. The second uses HYBRID_COMPLETION, which gives the LLM the matching source passages and the graph around them in one call, so dates and prices are copied from the text. It gets the new email, your three emails, and DRAFT_PROMPT: answer every question from memory, never invent a date or price, and if you owe the sender something, say plainly whether it was sent.
Make It Yours
- Write in a different voice. Edit
DRAFT_PROMPTinscripts/draft.py: keep replies to three sentences, always propose a call, or answer in the sender’s language. - Add your pricing sheet. Write one more ingest script that calls
cognee.rememberon a folder of documents with its own node set, and add it torun(). The draft then answers from your real price list. See Remember for the inputs it accepts. - Build a meeting-prep agent. Keep steps 2 and 3 as they are and replace the draft with one
HYBRID_COMPLETIONrecall: “What did I promise Priya Shah, and what is still open?” Same memory, a different application. - Look at your memory before trusting it. Recall with
node_name=["meetings"]to see only what came from calls. NodeSet Grouping shows how scoping works.
Clean Up
sample/ and token.json in the cookbook folder.
NodeSet Grouping
Tag memories by source and recall from one part at a time.
Gmail Ingestion
How the Gmail connector syncs your mail incrementally.
Follow-Up Agent
Build another one: next steps from your latest call, posted to Slack.
Self-Hosted AI Companion
Build another one: a chat companion that remembers your notes.