This repo provides a simple example of how to build a ReAct agent with MCP and local tools.
Specifically this repo builds a Text2Cypher ReAct agent with the Neo4j Cypher MCP Server. The agent also has extended capabilities by exposing local tools for it to use.
A conversational AI agent that connects to a Neo4j Movies database and can answer movie-related questions using natural language. Built with LangGraph's implementation of a ReAct agent, the Neo4j Cypher MCP server, and a custom movie recommendations tool.
- Natural Language to Cypher: Ask questions in plain English and get answers from your Neo4j database
- ReAct Agent Pattern: Uses reasoning and acting loops for complex reasoning
- Schema-Aware: Automatically retrieves and uses database schema for accurate query generation
- Interactive CLI: Chat-based interface for easy interaction
- Python 3.10 or higher
- Neo4j Aura account or local Neo4j instance with Movies database
- OpenAI API key
uvpackage manager (recommended) orpip
-
Install uv (if not already installed):
pip install uv
-
Clone and setup the project:
git clone neo4j-field/text2cypher-react-agent-example cd text2cypher-react-agent-example -
Install dependencies:
uv sync
-
Clone and setup the project:
git clone neo4j-field/text2cypher-react-agent-example cd text2cypher-react-agent-example -
Create and activate virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Copy the example environment file:
cp .env.example .env
-
Edit
.envwith your credentials:OPENAI_API_KEY=your_openai_api_key_here NEO4J_USERNAME=neo4j NEO4J_PASSWORD=your_neo4j_password NEO4J_URI=neo4j+s://your-instance.databases.neo4j.io NEO4J_DATABASE=neo4j
- LangGraph ReAct Agent: Implements reasoning and acting loops for complex queries
- Neo4j Cypher MCP Server: Provides schema introspection and query execution
- Custom Recommendations Tool: Custom tool for movie recs
- Interactive CLI: Command-line chat interface
get_neo4j_schema: Retrieves database schema for informed query writingread_neo4j_cypher: Executes read-only Cypher queries against the databasefind_movie_recommendations: Custom recommendation engine that finds movies liked by users who also enjoyed a target movie
make run-agent-uv
# or
uv run python3 single_file_agent.pymake run-agent
# or
python3 single_file_agent.pyOnce running, you can ask questions like:
- "What movies are in the database?"
- "Tell me about The Matrix"
- "Recommend me some films like The Dark Knight."
To exit the agent, type any of:
exitquitq
This repo also contains a simple local evaluation suite. This may be used and extended to evaluate your own agents.
To run
- Configure the
eval.pyfile with the LLM name, tools and prompt you would like to use - Ensure you have populated the
questions.yamlfile with your eval question set - Run
make run-eval-uvormake run-evaldepending on your package manager - The eval results CSV will be saved to
evals/output/<file-name>.csv - View the contents with
review.ipynb - Generate a
.txtreport withmake generate-report-uv csv-name=<file-name>ormake generate-report csv-name=<file-name>depending on your package manager
The resulting evaluation CSV will contain the following columns:
- question_id: str
- question: str
- expected_answer: str
- agent_final_answer: Optional[str]
- generated_cypher: list[ReadNeo4jCypherToolInput]
- model: str
- available_tools: list[str]
- called_tools: list[str]
- num_messages: Optional[int]
- num_llm_calls: Optional[int]
- num_tool_calls: Optional[int]
- response_time: Optional[float]
- error: Optional[str]
make formatCore Libraries:
langchain- LangChain frameworklangchain-mcp-adapters- MCP (Model Context Protocol) adapterslangchain-openai- OpenAI integrationlanggraph- Graph-based agent frameworkneo4j- Neo4j Python driveropenai- OpenAI API clientpydantic- Data validation
Development:
ruff- Code formatting and linting
Connection Issues:
- Verify your Neo4j credentials in
.env - Ensure your Neo4j instance is running and accessible
OpenAI Issues:
- Verify your OpenAI API key is valid
- Check your API usage limits
MCP Server Issues:
- Ensure
uvxis available in your PATH - The agent automatically installs
[email protected]via uvx
Python Issues:
- Ensure Python 3.10+ is installed
- Try recreating your virtual environment if using pip
This project is provided as an example for educational and demonstration purposes.