Code

cookbook/tools/gmail_tools.py
from agno.agent import Agent
from agno.tools.gmail import GmailTools

agent = Agent(
    name="Gmail Agent",
    tools=[GmailTools()],
    instructions=[
        "Based on user query, you can read, draft and send emails using Gmail.",
        "While showing email contents, you can summarize the email contents, extract key details and dates.",
        "Show the email contents in a structured markdown format.",
    ],
    markdown=True,
    show_tool_calls=True,
)

# Send a reply to an email
agent.print_response(
    "Send a reply to the last email saying 'Thank you for your message. I'll get back to you soon.'",
    stream=True,
)

Usage

1

Create a virtual environment

Open the Terminal and create a python virtual environment.
python3 -m venv .venv
source .venv/bin/activate
2

Set your API key

export OPENAI_API_KEY=xxx
3

Set up Gmail credentials

export GOOGLE_CLIENT_ID=xxx
export GOOGLE_CLIENT_SECRET=xxx
export GOOGLE_PROJECT_ID=xxx
4

Install libraries

pip install -U google-auth google-api-python-client openai agno
5

Run Agent

python cookbook/tools/gmail_tools.py