Use this file to discover all available pages before exploring further.
Enable Agno agents to use natural language queries to perform “Multi-hop Reasoning” by interacting with Neo4j database. Agents can find connections that are three or four levels deep, such as finding the supplier of a component used in a product bought by a customer who also complained about a specific shipping delay.
Run this script to create an agent that can interact with your Neo4j database
Test with queries like “What are the node labels in my graph?” or “Show me the database schema”
import osfrom agno.agent import Agentfrom agno.models.openai import OpenAIChatfrom agno.tools.neo4j import Neo4jToolsfrom dotenv import load_dotenv# ---------------------------------------------------------------------------# Create Agent# ---------------------------------------------------------------------------# ---------------------------------------------------------------------------# Run Agent# ---------------------------------------------------------------------------if __name__ == "__main__": load_dotenv() # Optionally load from environment or hardcode here uri = os.getenv("NEO4J_URI", "bolt://localhost:7687") user = os.getenv("NEO4J_USERNAME", "neo4j") password = os.getenv("NEO4J_PASSWORD", "password") # Example 1: All functions enabled (default) neo4j_toolkit_all = Neo4jTools( uri=uri, user=user, password=password, all=True, ) # Example 2: Specific functions only neo4j_toolkit_specific = Neo4jTools( uri=uri, user=user, password=password, enable_list_labels=True, enable_get_schema=True, enable_list_relationships=False, enable_run_cypher=False, ) # Example 3: Default behavior neo4j_toolkit = Neo4jTools( uri=uri, user=user, password=password, ) description = """You are a Neo4j expert assistant who can help with all operations in a Neo4j database by understanding natural language context and translating it into Cypher queries.""" instructions = [ "Analyze the user's context and convert it into Cypher queries that respect the database's current schema.", "Before performing any operation, query the current schema (e.g., check for existing nodes or relationships).", "If the necessary schema elements are missing, dynamically create or extend the schema using best practices, ensuring data integrity and consistency.", "If properties are required or provided for nodes or relationships, ensure that they are added correctly do not overwrite existing ones and do not create duplicates and do not create extra nodes.", "Optionally, use or implement a dedicated function to retrieve the current schema (e.g., via a 'get_schema' function).", "Ensure that all operations maintain data integrity and follow best practices.", "Intelligently create relationships if bi-directional relationships are required, and understand the users intent and create relationships accordingly.", "Intelligently handle queries that involve multiple nodes and relationships, understand has to be nodes, properties, and relationships and maintain best practices.", "Handle errors gracefully and provide clear feedback to the user.", ] # Example: Use with AGNO Agent agent = Agent( model=OpenAIChat(id="o3-mini"), tools=[neo4j_toolkit], markdown=True, description=description, instructions=instructions, ) # Agent handles tool usage automatically via LLM reasoning agent.print_response( "Add some nodes in my graph to represent a person with the name John Doe and a person with the name Jane Doe, and they belong to company 'X' and they are friends." ) agent.print_response("What is the schema of my graph?")~~~## Run the Example```bash# Clone and setup repogit clone https://github.com/agno-agi/agno.gitcd agno/cookbook/91_tools# Create and activate virtual environment./scripts/demo_setup.shsource .venvs/demo/bin/activate# Export relevant API keysexport NEO4J_PASSWORD="***"export NEO4J_URI="***"export NEO4J_USERNAME="***"python neo4j_tools.py