A simple AI agent built with Python, LangGraph, and Ollama that reads your recent Gmail inbox and answers questions about it in a chat. Everything runs locally, so your emails never go to a cloud model.
Built to learn how LLM tool-calling and agent loops work under the hood.
- Fetches your most recent emails (sender and subject) from Gmail over IMAP
- Lets you chat with a local LLM, for example "Summarize my latest emails"
- Remembers the conversation, so follow-ups like "Which one looks most important?" work
-
Tool:
fetch_recent_emailsconnects to Gmail withIMAPClientand returns the sender and subject of the latest emails as text. -
Model:
ChatOllamaruns a local model and is bound to the tool, so it can decide when to call it. -
Graph: LangGraph runs the loop automatically. The model is asked, and if it requests a tool, the tool runs and its result goes back to the model. This repeats until the model gives a final answer.
-
Memory: A
MemorySavercheckpointer stores the conversation per thread ID, so the agent keeps context between questions.
User -> agent (model) -> needs a tool? -> yes -> tools -> back to agent
-> no -> final answer
- Install dependencies:
uv sync
- Create a
.envfile (see.env.example):IMAP_USER=your_email@gmail.com IMAP_PASS=your_app_passwordUse a Gmail App Password, not your real password.
- Make sure Ollama is running with a model pulled:
ollama pull llama3.2
- Run the agent:
py main.py
Type your questions at the You: prompt, and type quit or exit to stop.