langchain-ai/agents-from-scratch

Build an email assistant with human-in-the-loop and memory

What is it?

Agents From Scratch is a tutorial-style repository that walks you through building an AI agent from the ground up. The end goal is an "ambient" agent that can manage your email by connecting to Gmail's API. The project is divided into four progressive stages, each with a notebook (interactive lesson) and accompanying code. You also get setup instructions, test suites, and deployment notes.

How is it structured?

  1. Preface – LangGraph 101: A quick primer on LangGraph (a framework for building agents) covering chat models, tool calling, agents vs. workflows, and basic concepts like nodes and edges.
  2. Building an agent: You start with an email assistant that combines an email triage step (sorting messages) with an agent that drafts responses. This is the core implementation.
  3. Evaluation: You learn how to test the agent's behavior using a sample email dataset. The tests check response quality, tool calls, and triage decisions using an LLM-as-a-judge approach and LangSmith for tracking.
  4. Human-in-the-loop: You add a feature that lets a human review and approve certain actions (like sending an email or scheduling a meeting) before the agent executes them. An interface called Agent Inbox is provided for this.
  5. Memory: You give the assistant memory so it can learn from user feedback and remember preferences over time, using LangGraph's Store for long-term persistence.

The final, fully-featured version (email_assistant_hitl_memory_gmail.py) integrates with real Gmail and can be deployed to LangGraph Platform.

What do you need to run it?

  • Python 3.11+ (required for LangGraph compatibility)
  • API keys from OpenAI (for the model) and LangSmith (for tracing and evaluation)
  • Package installation – the repo must be installed in editable mode (pip install -e . or uv sync --extra dev) so the notebooks work correctly.
  • For Gmail integration: follow the specific instructions in the src/email_assistant/tools/gmail/README.md to set up Google API credentials.

Key takeaway

The repo is a practical, incremental guide: it starts with the absolute basics and builds up to a deployable, memory‑enabled agent that can handle real email. Along the way, it shows you how to evaluate and refine your agent, add human oversight, and give it long‑term memory – principles you can apply to any agent you build.

Related

  • Project
  • Project
  • Project
  • Project