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-35klisted (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
.envfile with your Neo4j and OpenAI credentials:OPENAI_API_KEY=sk-... - Your OpenAI keyIf 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.ioYour instance id is
4469a679.Add the following to your
.envfile: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.pyStart the agent:
python kyc_agent.pyTest 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 schemato fetch the schema. -
Find suspicious rings:
Show me 3 watchlisted customers involved in ringsThis tests the
find_customer_ringstool. -
Check shared addresses:
For each of these customers, find their addresses and find out if they are shared with other customersThis tests both the
Text-to-Cypher Generationtool and theMCP Neo4j server exec read querytool. -
Recent transactions:
Find more details about the customer with the shared adddress. List accounts and recent transactionsThis tests the
get_customer_and_accountstool. -
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 conversationThis tests the
create_memorytool.