This project extends an existing MCP + LangGraph AI agent by adding:
- Structured Todo-style execution planning
- Human-in-the-Loop (HITL) approval before tool execution
- Deterministic, explainable control flow using LangGraph
The goal of this task is to ensure that every tool invocation is deliberate, transparent, and explicitly approved by a human, making the agent safer, more controllable, and suitable for production-style workflows.
This work builds directly on Task 2, which implemented a stable MCP-based AI agent with dynamic tool discovery and conversational memory.
The assignment required the following:
-
Add a Todo List tool Generate a structured list of steps describing how the agent plans to solve the userβs query before executing any tools.
-
Add Human-in-the-Loop control Pause execution and request explicit user approval before running tools. (Bonus: request approval after plan generation and before tool execution.)
-
Evaluate LangChain middleware Investigate
TodoListMiddlewareand Human-in-the-Loop middleware as referenced in the assignment.
This repository demonstrates all three, with clear justification for the architectural decisions made.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β User β
β (Natural Language Queries) β
βββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β LangGraph AI Agent β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Agent Node (LLM) β β
β β β’ Interprets user intent β β
β β β’ Decides whether tools are required β β
β βββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ β
β β β
β βββββββββββββββββΌββββββββββββββββββββββββββββββββββββββ β
β β Planner Node (Todo Generation) β β
β β β’ Generates a structured execution plan β β
β β β’ Explains what tools will be used and why β β
β βββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ β
β β (Human approval required) β
β βββββββββββββββββΌββββββββββββββββββββββββββββββββββββββ β
β β Tool Node (MCP Executors) β β
β β β’ Executes approved MCP tools β β
β β β’ Returns results to the agent β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MCP Client (STDIO) β
β β’ Discovers tools dynamically β
β β’ Sends tool calls via MCP protocol β
βββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MCP Server β
β β’ get_weather β
β β’ get_stock_price β
β β’ web_search β
β β’ No agent logic β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
task4-todo-hitl/
βββ agent/
β βββ ai-agent.py # Baseline agent (Task 2)
β βββ agent-custom.py # Final working Todo + HITL agent
β βββ agent-prebuilt.py # Middleware investigation (documented limitation)
β
βββ server/
β βββ backend/
β βββ tools/
β βββ main.py # MCP tool server
β
βββ README.md
βββ requirements.txt
βββ .gitignore
This is the original MCP + LangGraph agent developed in Task 2.
Features:
- Dynamic MCP tool discovery
- Explicit LangGraph state management
- Conversational memory
- Tool invocation without planning or approval
This file serves as a reference baseline for comparison.
This is the primary and final implementation for this task.
Key additions:
Todo-style execution planning
-
Generated only when tools are required
-
Explains:
- What data will be fetched
- Why each tool is needed
- How results will be presented
Human-in-the-Loop approval
- Execution pauses after plan generation
- User must explicitly approve before tools are called
- Tool execution can be cancelled safely
Deterministic LangGraph flow
Agent β Planner β (Approval) β Tools β Agent
- No ReAct loops
- No uncontrolled retries
This approach provides maximum transparency, control, and safety.
This file contains an attempted implementation using:
TodoListMiddleware- LangChain agent middleware APIs referenced in the assignment
Outcome:
ModuleNotFoundError: No module named 'langchain.agents.middleware'
Reason:
- Agent middleware is not available in the LangChain version used by this project
- This is a version-level limitation, not a coding error
This file is intentionally included to:
- Show that the middleware approach was investigated
- Justify why a custom LangGraph-based implementation was the correct choice
The assignment references LangChainβs TodoList and Human-in-the-Loop middleware APIs.
While upgrading LangChain was technically possible, doing so would have required re-validating an already stable integration involving MCP (STDIO-based tools), LangGraph state transitions, and Groq tool calling. Instead, the same behavior was implemented explicitly using LangGraph, providing deterministic execution, full visibility into agent state, and precise control over when planning and human approval occurβwithout introducing unnecessary dependency upgrade risk.
- Python 3.9+
- Groq API key
git clone https://github.com/sushma9903/todo-hitl.git
cd todo-hitl
pip install -r requirements.txtCreate a .env file in the project root:
GROQ_API_KEY=your_groq_api_key_herepython agent/agent-custom.pyYou: what is the weather in London?
Agent's Plan:
1. Fetch current weather data for London using the get_weather MCP tool
2. This tool provides real-time weather data required to answer the query
3. Present temperature, humidity, and wind conditions in a clear response
Planned Tool Calls:
- get_weather {'city': 'London'}
Approve execution? (yes/no): yes
- Middleware APIs were unavailable in the current LangChain version
- LangGraph enables explicit, inspectable state transitions
- Planning logic is deterministic and testable
- Prevents unintended side effects
- Enables user trust and operational safety
- Mirrors real-world approval workflows
- MCP server handles only execution
- Agent handles reasoning, planning, and decisions
- Clear separation of concerns
langchainlanggraphlangchain-groqmcppydanticpython-dotenv
By the end of this task, the agent:
- Plans before acting
- Explains its intent clearly
- Requires explicit human approval
- Executes tools safely and deterministically
- Knows when not to proceed
This results in a production-grade, explainable AI agent that is safer and more controllable than a standard tool-calling chatbot.
- LangGraph Documentation
- LangChain Human-in-the-Loop
- LangChain Todo List Middleware
- Model Context Protocol (MCP)