A basic GraphRAG agent built with OpenAI Agent SDK, Neo4j and Neo4j MCP server
Before running the KYC Agent, ensure you have the following prerequisites installed and configured:
-
Python 3.13+
- Download and install Python 3.13
- Verify installation with:
python --version
-
uv Package Manager
- Install uv
- Verify installation with:
uv --version
-
Ollama
-
Ideally, you need a device with 6GB GPU Memory (the model weights take about 4.1GB)
-
Start the Ollama server:
ollama serve
-
Pull the Text-to-Cypher model:
ollama pull ed-neo4j/t2c-gemma3-4b-it-q8_0-35k
-
Verify the model is available and being served locally
ollama ls
You should see
pull ed-neo4j/t2c-gemma3-4b-it-q8_0-35k
listed (available locally) -
-
OpenAI Key You will be using the OpenAI Agent SDK with an OpenAI model, so you need an OPENAI_KEY
You have two options to create a Free Neo4j database
Start a Neo4j docker container using the provided docker-compose.yml:
docker compose up -d
-
Head over to Neo4j AuraDB Console
-
Create a new database instance, Choose
AuraDB Free
. Make sure to download your credentials.
-
Clone the repository:
git clone https://github.com/neo4j-product-examples/graphrag-kyc-agent.git cd graphrag-kyc-agent
-
Create a virtual environment and install dependencies:
uv venv source .venv/bin/activate uv sync
-
Set up environment variables:
Create a
.env
file with your Neo4j and OpenAI credentials:OPENAI_API_KEY=sk-... - Your OpenAI key
If you are using an AuraDB Free tier instance, find the downloaded credentials. Look at the NEO4J_URI and locate your instance id.
For example, If your instance id is
NEO4J_URI=neo4j+s://4469a679.databases.neo4j.io
Your instance id is
4469a679
.Add the following to your
.env
file:NEO4J_URI=neo4j+s://<YOUR_INSTANCE_ID>.databases.neo4j.io NEO4J_USERNAME=<YOUR_INSTANCE_ID> NEO4J_PASSWORD=<YOUR_PASSWORD> NEO4J_DATABASE=<YOUR_INSTANCE_ID>
python generate_kyc_dataset.py
Start the agent:
python kyc_agent.py
Test the agent tools with these example questions:
-
Get the database schema:
What is the schema of the database?
This test the
MCP Neo4j server get schema
to fetch the schema. -
Find suspicious rings:
Show me 3 watchlisted customers involved in rings
This tests the
find_customer_rings
tool. -
Check shared addresses:
For each of these customers, find their addresses and find out if they are shared with other customers
This tests both the
Text-to-Cypher Generation
tool and theMCP Neo4j server exec read query
tool. -
Recent transactions:
Find more details about the customer with the shared adddress. List accounts and recent transactions
This tests the
get_customer_and_accounts
tool. -
Store conversation summary:
Write a 300-word summary of this investigation into this customer. Store it as a memory, make sure to link it to accounts and transasction mentioned in the conversation
This tests the
create_memory
tool.