Gmail
Gmail Action Item Extractor
Extracts action items from email threads and returns a structured checklist.
"""
Gmail Action Item Extractor
============================
Extracts action items from email threads and returns a structured checklist.
The agent reads a thread, identifies who needs to do what by when,
and returns structured action items. This is an LLM reasoning task --
no special tool needed, just get_thread + output_schema.
Key concepts:
- get_thread: Fetches full thread context for multi-message analysis
- output_schema: Forces structured action item extraction
- add_datetime_to_context: Agent knows today's date for deadline reasoning
Setup:
1. Create OAuth credentials at https://console.cloud.google.com (enable Gmail API)
2. Export GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, GOOGLE_PROJECT_ID env vars
3. pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib
4. First run opens browser for OAuth consent, saves token.json for reuse
"""
from typing import List, Literal, Optional
from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.tools.google.gmail import GmailTools
from pydantic import BaseModel, Field
class ActionItem(BaseModel):
owner: str = Field(..., description="Person responsible (name or email)")
task: str = Field(..., description="What needs to be done")
deadline: Optional[str] = Field(
None, description="Due date if mentioned, in YYYY-MM-DD format"
)
priority: Literal["high", "medium", "low"] = Field(
..., description="Priority based on urgency language and deadlines"
)
source_quote: str = Field(
..., description="Brief quote from the email that implies this action"
)
class ThreadActionItems(BaseModel):
thread_subject: str = Field(..., description="Thread subject line")
participants: List[str] = Field(..., description="All people in the thread")
action_items: List[ActionItem] = Field(
default_factory=list, description="Extracted action items"
)
summary: str = Field(..., description="One-sentence summary of the thread")
agent = Agent(
name="Action Item Extractor",
model=OpenAIResponses(id="gpt-5.5"),
tools=[GmailTools(max_results=10)],
instructions=[
"Search for the requested thread, then use get_thread to read all messages.",
"Extract action items from the FULL conversation -- check every message.",
"An action item is anything someone is asked to do, agrees to do, or volunteers to do.",
"Look for phrases like 'can you', 'please', 'I will', 'let's', 'by Friday', 'deadline'.",
"If no deadline is stated, leave deadline as null -- do not guess.",
"Set priority: high if deadline is soon or language is urgent, low for nice-to-haves.",
],
output_schema=ThreadActionItems,
add_datetime_to_context=True,
markdown=True,
)
if __name__ == "__main__":
agent.print_response(
"Find the most recent thread about a project or meeting and extract all action items",
stream=True,
)For this reading task, replace the toolkit with GmailTools(include_tools=["search_emails", "search_threads", "get_thread", "get_message"]) (retain max_results=10 for the action-item example if desired). GmailTools() otherwise also enables sending, drafting, and label changes. Search returns a page of results; follow nextPageToken for a complete digest or a broader thread search.
Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno google-api-python-client google-auth google-auth-httplib2 google-auth-oauthlib openaiConfigure Google OAuth
Enable the Google API used by this example, configure the consent screen, and create a Desktop OAuth client in your Cloud project. Export its GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, and GOOGLE_PROJECT_ID, or place the downloaded client JSON at credentials.json in the directory where you run Python. Google's Python quickstart shows the Desktop client setup.
The first tool call opens a browser for consent and caches credentials in token.json. Use a separate token_path when switching accounts. Passing an Agno user_id does not switch the authenticated Google account.
Export environment variables
export GOOGLE_CLIENT_ID="your_google_client_id_here"
export GOOGLE_CLIENT_SECRET="your_google_client_secret_here"
export GOOGLE_PROJECT_ID="your_google_project_id_here"
export OPENAI_API_KEY="your_openai_api_key_here"Run the example
Save the code above as action_items.py, then run:
python action_items.pyFull source: cookbook/91_tools/google/gmail/action_items.py