A Jupyter notebook version of this example is available on GitHub.
Looking for a managed Graphiti service? Check out Zep Cloud.
The following example demonstrates building an agent using LangGraph. Graphiti is used to personalize agent responses based on information learned from prior conversations. Additionally, a database of products is loaded into the Graphiti graph, enabling the agent to speak to these products.
The agent implements:
MemorySaver to maintain agent state.Ensure that you’ve followed the Graphiti installation instructions. In particular, installation of neo4j.
Ensure that you have neo4j running and a database created. You’ll need the following environment variables configured:
The following is only required for the first run of this notebook or when you’d like to start your database over.
clear_data is destructive and will wipe your entire database.
Load several shoe and related products into the Graphiti. This may take a while.
This only needs to be done once. If you run clear_data you’ll need to rerun this step.
In your own app, this step could be done later once the user has identified themselves and made their sales intent known. We do this here so we can configure the agent with the user’s node_uuid.
get_shoe_data ToolThe agent will use this to search the Graphiti graph for information about shoes. We center the search on the manybirds_node_uuid to ensure we rank shoe-related data over user data.
The chatbot uses Graphiti to provide context-aware responses in a shoe sales scenario. Here’s how it works:
Context Retrieval: It searches the Graphiti graph for relevant information based on the latest message, using the user’s node as the center point. This ensures that user-related facts are ranked higher than other information in the graph.
System Message: It constructs a system message incorporating facts from Graphiti, setting the context for the AI’s response.
Knowledge Persistence: After generating a response, it asynchronously adds the interaction to the Graphiti graph, allowing future queries to reference this conversation.
This approach enables the chatbot to maintain context across interactions and provide personalized responses based on the user’s history and preferences stored in the Graphiti graph.
This section sets up the Agent’s LangGraph graph:
Graph Structure: It defines a graph with nodes for the agent (chatbot) and tools, connected in a loop.
Conditional Logic: The should_continue function determines whether to end the graph execution or continue to the tools node based on the presence of tool calls.
Memory Management: It uses a MemorySaver to maintain conversation state across turns. This is in addition to using Graphiti for facts.
Our LangGraph agent graph is illustrated below.

Let’s test the agent with a single call
At this stage, the graph would look something like this. The jess node is INTERESTED_IN the TinyBirds Wool Runner node. The image below was generated using Neo4j Desktop.

The following code will run the agent in a Jupyter notebook event loop. You can modify the code to suite your own needs.
Just enter a message into the box and click submit.