What You’ll Build
Your primary Google Calendar, your newest Gmail inbox emails and one Google Drive folder go into one cognee memory. An agent then answers one question across them. By default it prepares your client meetings of the next seven days: which orders are late or at risk, why, and what to tell each client. Google is read-only: nothing is created, changed or sent. Building the memory takes threecognee.remember calls, one per app, and answering takes one cognee.recall call.
The complete cookbook is
examples/cookbooks/google_workspace_memory/.
Try It on Sample Data
The sample is Ana Novak’s week. She runs Birchwood Ceramics, which makes tableware for restaurants. She meets Harbor Café in two days and Olive & Fig in four. A courier delayed Harbor Café’s dinner plates past their menu launch, and a back-ordered sage glaze puts Olive & Fig’s pasta bowls at risk. You need only an LLM key, no Google 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] forgets the sample’s dataset from an earlier run, or says there is nothing to forget yet, then [ingest_calendar], [ingest_gmail] and [ingest_drive] report 4 sample calendar events, 4 sample emails and 1 sample Drive file. [ask] prints the question, then the answer after [ask] Answer:.
A correct answer lists both meetings. For Harbor Café, it names order BC-1042, the dinner plates, delayed by the courier past the menu launch. For Olive & Fig, it names BC-1043, the pasta bowls held up by the back-ordered glaze. The meetings come from the calendar, the promised dates and statuses from the orders sheet in Drive, and the reasons from the courier’s and the supplier’s emails. Your wording will differ from run to run.
Run It on Your Data
Calendar, Gmail and Drive all read through one Google OAuth client. Each app is optional: pass--no-calendar, --no-gmail or --no-drive to skip one, and the answer draws on the others.
- Google Calendar
- Gmail
- Google Drive
The cookbook reads every event of your primary calendar, past and future, through cognee’s Google Calendar connector. Create the OAuth client here once; Gmail and Drive use the same one.
- In the Google Cloud Console, create or pick a project and enable the Google Calendar API, the Gmail API and the Google Drive API.
- In Google Auth Platform → Audience, add your own Google account as a test user.
- In Data Access, add the three read-only scopes:
calendar.readonly,gmail.readonlyanddrive.readonly. - In Clients, create a client of type Desktop app and download its JSON file.
- Save it as
credentials.jsonin the cookbook folder, next togoogle_workspace_memory.py.
calendar_token.json next to credentials.json.- Install the Google client libraries with
uv sync --extra gmail --extra google-drive --extra google-calendar. credentials.jsonand the*_token.jsonfiles are git-ignored. Never commit them.
--check reports what is missing without doing any work. The first run opens the browser three times, once per app. It reads your whole primary calendar and cognifies each event with your LLM, so a calendar with a few hundred events can take ten minutes or more. Later runs fetch only what changed in Calendar and Drive and skip the emails cognee already holds; add --clear to forget the dataset first and start over. Each script also runs alone, for example uv run python examples/cookbooks/google_workspace_memory/scripts/ask.py --ask "...".
How It Works
Step 1: Start From an Empty Memory
Source:scripts/clear.py
This step forgets what an earlier run remembered. It runs only with --clear, which a sample run turns on by default; --no-clear keeps the dataset.
cognee.forget(dataset=...), which deletes the dataset and everything extracted from it. args.sample switches every step to the sample’s own dataset, google_workspace_memory_sample, so the sample never mixes with your data in google_workspace_memory.
Step 2: Remember Your Calendar
Source:scripts/ingest_calendar.py
This step saves every event of your primary calendar, past and future, so the agent knows who you meet and when. It runs unless you pass --no-calendar.
cognee.remember with google_calendar_source(["primary"]) as the input and node_set=["calendar"]. remember turns each event, with its organizer and attendees, into a knowledge graph, so the same client links across meetings. A node set is a tag on what you remember, so you can later recall from that part alone. write_disposition="merge" with primary_key="id" merges events by id, so a rerun updates them instead of storing them twice.
Step 3: Remember Your Inbox
Source:scripts/ingest_gmail.py
This step saves the newest 50 emails in your inbox, not your whole mailbox. Pass --emails N to change how many. It runs unless you pass --no-gmail.
cognee.remember with gmail_source(label_ids=["INBOX"], max_results=count) and node_set=["email"]. A capped read is a snapshot of your inbox, so it uses write_disposition="replace": emails that left the newest N are forgotten, and memory holds your inbox as it is now.
Step 4: Remember Your Drive Folder
Source:scripts/ingest_drive.py
This step saves the Docs, Sheets, PDFs and text files in the folder GOOGLE_DRIVE_FOLDER_ID and its subfolders, such as your orders sheet. It runs unless you pass --no-drive.
cognee.remember with google_drive_source(folder_id, auth_mode="oauth") and node_set=["drive"], merged by file id like the calendar. Every ingest step passes self_improvement=False, so no improve pass runs after each app; the question in the next step reads the graph directly.
Step 5: Ask Across All Three
Source:scripts/ask.py
This step answers one question across your calendar, inbox and Drive. Without --ask, it prepares your client meetings of the next seven days.
cognee.recall call with query_type=SearchType.HYBRID_COMPLETION over the cookbook’s dataset, the named memory everything went into. HYBRID_COMPLETION gives the LLM the matching source passages and the graph around them in one call, so a meeting, an email and a sheet row about the same client meet in one answer. The script puts today’s date in front of the question, so “next seven days” and “late” are measured from today.
Make It Yours
- Ask your own question. Pass
--ask "Which clients have I not met in a month?", or changeDEFAULT_QUESTIONinscripts/ask.pyto the question you ask every Monday. - Read a different label or more mail. Change
label_ids=["INBOX"]inscripts/ingest_gmail.pyto a support or sales label, or raise--emails. See Gmail Ingestion for the connector’s options. - Ask one app at a time. Recall with
node_name=["email"]to answer only from your inbox, or["drive"]only from your files. NodeSet Grouping shows how scoping works. - Draft the follow-up email. Keep steps 1–4 and add a step after
askthat recalls the meeting answer and drafts one email per client. Same memory, a different application.
Clean Up
sample/ and the *_token.json files in the cookbook folder.
Through a Cognee Server
The steps above read Google from your machine with your own OAuth client. When cognee runs as a server for several people, the server can hold the Google OAuth clients instead. Each user connects their account once in the browser, and the server syncs each app into that account’s own dataset.--api drives that flow:
--api, run() replaces steps 1–5 with one line:
scripts/sync_api.py selects your primary calendar, the INBOX label and the folder GOOGLE_DRIVE_FOLDER_ID through PUT /api/v1/integrations/<provider>/resources, replacing any calendars, labels or folders you selected before, and the next sync forgets what they held. It starts each sync with POST .../sync and polls GET .../connection until lastSyncedAt changes. ask_api in scripts/ask.py then sends the same question to POST /api/v1/recall across the synced datasets. --sample and --clear stop the run with a [setup] MISSING line, and --emails is ignored: the server’s datasets are its own, and Gmail syncs the whole label.
COGNEE_API_TOKEN(your bearer token) andCOGNEE_API_URL(defaulthttp://localhost:8000) go in.envat the repo root, along withGOOGLE_DRIVE_FOLDER_IDunless you pass--no-drive.- The server needs, per app (
GOOGLE_CALENDAR_*,GOOGLE_GMAIL_*,GOOGLE_DRIVE_*), aCLIENT_IDandCLIENT_SECRETfrom a Google OAuth client of type Web application, aREDIRECT_URI(<server>/api/v1/integrations/<provider>/callback), aSTATE_SECRETand aFRONTEND_BASE_URL. It also needsINTEGRATION_CREDENTIALS_KEYS(andINTEGRATION_CREDENTIALS_ACTIVE_KEY_IDwhen the active key’s id isn’t1) to encrypt the stored Google tokens. The Google Calendar, Gmail and Google Drive integration pages cover each one. - Connect each app in the browser, never in the script: the server accepts only a consent that finishes in the browser that started it. Connect Drive and Gmail on the cognee UI’s Integrations page. Calendar has no card there yet: in the same browser, open the server’s
/docs, callPOST /api/v1/integrations/google_calendar/authorize, and open theauthorizeUrlit returns.--api --checkreports each app that is not connected yet.