Simple LangChain Agent

Introduction

In this lesson, you’ll build your first LangChain agent that can interact with your Neo4j knowledge graph.

Key insight: The agent chooses which tool to use based on your question.

When you ask: "Summarize the schema of the graph database"

  1. Agent receives your natural language question

  2. Agent decides to use the Get-graph-database-schema tool

  3. Tool executes and returns the Neo4j schema

  4. Agent processes the schema and creates a summary

  5. Agent responds in natural language

What You’ll Build

Open the notebook: 02_01_simple_agent.ipynb

This agent:

  • Uses LangChain and LangGraph for agent functionality

  • Connects to your Neo4j database

  • Has a single tool: Get-graph-database-schema

  • Can answer questions about your graph structure

The goal: Understand basic agent architecture before adding retriever capabilities.

== Agent Architecture

python
# 1. Initialize LLM
model = init_chat_model("gpt-4o", model_provider="openai")

# 2. Connect to Neo4j
graph = Neo4jGraph(url=NEO4J_URI, username=username, password=password)

# 3. Define tools
@tool("Get-graph-database-schema")
def get_schema():
    """Get the schema of the graph database."""
    return graph.schema

# 4. Create agent
agent = create_react_agent(model, tools)

Try These Questions

Schema exploration:

  • "Summarize the schema of the graph database"

  • "How are Products related to other entities?"

  • "What questions can I answer using this graph database?"

Perfect for understanding data structure before building queries!

Summary

In this lesson, you built your first agent with schema introspection capabilities:

Key Concepts:

  • Schema tool: Database structure exploration through conversation

  • Agent setup: LangChain ReAct agent with introspection tool

  • LangGraph: Modern agent framework for tool orchestration

  • Graph structure: Understanding nodes, relationships, and properties

Next lesson: Add Vector Retriever tool for semantic content search.

  • Conversation flow: Natural language → tool selection → retriever execution → formatted response

What You Built:

  • Agent that can answer questions using semantic search

  • Conversational interface to graph database schema

  • Foundation for adding more retriever tools

Limitations:

  • Only semantic search (no relationship traversal)

  • No precise queries or aggregations

  • Single tool agent

In the next lesson, you will enhance your agent by adding the Vector + Cypher Retriever tool for contextual relationships and richer answers.

Chatbot

How can I help you today?