MCP Agent
May 19, 2025 · View on GitHub
Diagram

Overview
This project implements a LangGraph agent based on the ReWOO (Reasoning WithOut Observation) pattern. Similar to the ReAct (Reasoning and Acting) pattern, it reasons and acts, but aims to reduce the amount and complexity of prompts, especially when using Small LLMs (SLMs), by pre-defining the necessary evidence during the planning phase instead of explicitly separating an Observation step.
It also includes several optimization logics, such as tool filtering, plan validation and correction, and evidence management, for efficient interaction with the MCP (Model Context Protocol) server.
Architecture: LangGraph Nodes
This agent executes the ReWOO workflow using the following LangGraph nodes:
tool_filter: At the start of agent execution, filters the most relevant tools for the current task based on the user query and descriptions of all available tools.planner: Based on the filtered tool information, generates a step-by-step execution plan (in YAML format) to resolve the user query. Also handles plan correction logic upon errors.plan_parser: Parses the raw YAML plan generated by theplannerand validates its structural integrity. May include logic for automatic correction using LLM upon parsing/validation errors.plan_validator: Finally validates whether the tool names included in the parsed plan exist in the valid tool list selected during thetool_filterstep.tool_selector: Selects the tool for the current step to be executed from the validated plan.tool_input_preparer: Prepares the input for the selected tool. In this process, it replaces placeholders (#E1, etc.) with actual values by referencing the evidence collected in previous steps.tool_executor: Executes the actual tool (via the MCP server) with the prepared input and retrieves the result.evidence_processor: Processes the tool execution result and stores it in theevidencedictionary. (Currently a placeholder, further logic can be implemented).generate_final_answer: When all plan steps are completed or the plan finishes without tool calls, synthesizes the final answer by compiling all collected evidence.
Project Structure
.
├── agent/ # ReWOO agent core logic
│ ├── graph.py # LangGraph graph definition
│ ├── state.py # Agent state definition (ReWOOState)
│ ├── nodes/ # Graph node implementations (planner, parser, executor, etc.)
│ ├── prompts/ # LLM prompt definitions
│ └── utils.py # Utility functions
├── core/ # Core utilities
│ └── llm_loader.py # LLM instance loading and management
├── tests/ # Test code (unit/integration)
├── images/ # Images for README
├── mcp.json # MCP server configuration file
├── main.py # Agent execution script
├── .env.example # Environment variable setup example
└── README.md # Project documentation
Usage
python main.py