Share context across users using graphs
In this recipe, we will demonstrate how to share context across different users by utilizing graphs. We will set up a user thread, add graph-specific data, and integrate the OpenAI client to show how to use both user and graph context to enhance the context of a chatbot.
Set up the user and thread
First, we initialize the Zep client, create a user, and create a thread:
Create a graph and add business data
Next, we create a new graph and add structured business data to the graph, in the form of a JSON string. This step uses the Graphs API.
Generate a response using both contexts
The chatbot_response function retrieves user and graph context, then sends both values as untrusted user-level data. The developer message contains only stable application instructions.
Do not interpolate either context block into the developer message. OpenAI assigns developer messages higher instruction priority than user messages. Read Memory security best practices before you use retrieved context in a production agent.
Summary
This recipe demonstrated how to share context across users by utilizing graphs with Zep. We set up user threads, added structured graph data, and integrated the OpenAI client to generate contextual responses, sharing context across different users.