📢 Announcing our research paper: Zentry achieves 26% higher accuracy than OpenAI Memory, 91% lower latency, and 90% token savings! Read the paper to learn how we're revolutionizing AI agent memory.
LlamaIndex supports Zentry as a memory store. In this guide, we’ll show you how to use it.
🎉 Exciting news! ZentryMemory now supports ReAct and FunctionCalling agents.
Import the necessary modules and create a ZentryMemory instance:
from llama_index.memory.Zentry import ZentryMemorycontext = {"user_id": "user_1"}memory_from_client = ZentryMemory.from_client( context=context, api_key="<your-Zentry-api-key>", search_msg_limit=4, # optional, default is 5)
Context is used to identify the user, agent or the conversation in the Zentry. It is required to be passed in the at least one of the fields in the ZentryMemory constructor. It can be any of the following:
search_msg_limit is optional, default is 5. It is the number of messages from the chat history to be used for memory retrieval from Zentry. More number of messages will result in more context being used for retrieval but will also increase the retrieval time and might result in some unwanted results.
search_msg_limit is different from limit. limit is the number of messages to be retrieved from Zentry and is used in search.
Use the SimpleChatEngine to start a chat with the agent with the memory.
from llama_index.core.chat_engine import SimpleChatEngineagent = SimpleChatEngine.from_defaults( llm=llm, memory=memory_from_client # or memory_from_config)# Start the chatresponse = agent.chat("Hi, My name is Mayank")print(response)
Now we will learn how to use Zentry with FunctionCalling and ReAct agents.Initialize the tools:
from llama_index.core.tools import FunctionTooldef call_fn(name: str): """Call the provided name. Args: name: str (Name of the person) """ print(f"Calling... {name}")def email_fn(name: str): """Email the provided name. Args: name: str (Name of the person) """ print(f"Emailing... {name}")call_tool = FunctionTool.from_defaults(fn=call_fn)email_tool = FunctionTool.from_defaults(fn=email_fn)
from llama_index.core.agent import FunctionCallingAgentagent = FunctionCallingAgent.from_tools( [call_tool, email_tool], llm=llm, memory=memory_from_client, # or memory_from_config verbose=True,)# Start the chatresponse = agent.chat("Hi, My name is Mayank")print(response)
from llama_index.core.agent import ReActAgentagent = ReActAgent.from_tools( [call_tool, email_tool], llm=llm, memory=memory_from_client, # or memory_from_config verbose=True,)# Start the chatresponse = agent.chat("Hi, My name is Mayank")print(response)
By integrating LlamaIndex with Zentry, you can build a personalized agent that can maintain context across interactions with the agent and provide tailored recommendations and assistance.