> ## Content Index
> Fetch the complete content index at: https://blog.getzep.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Improved Langchain Support!
- URL: https://blog.getzep.com/improved-langchain-support/
- Published: 2023-07-10T16:48:36.000Z
- Updated: 2023-07-13T16:03:15.000Z
- Description: Langchain now includes improved support for Zep, with a new ZepMemory class, access to enriched messages, and more.
- Author: Daniel Chalef

### New `ZepMemory` Class Improves Developer Ergonomics

We've made it easier to use [Zep with Langchain](https://python.langchain.com/docs/modules/memory/integrations/zep%5Fmemory?ref=blog.getzep.com). Released in Langchain v0.0.229 is a `ZepMemory` class. This simplifies using Zep with your chains, as before today Zep's `ZepChatMessageHistory` class had to be wrapped in an existing Langchain Memory.

```python
# Set up Zep Memory
memory = ZepMemory(
    session_id=session_id,
    url=ZEP_API_URL,
    api_key=zep_api_key,
    memory_key="chat_history",
)

# Initialize the agent
llm = OpenAI(temperature=0, openai_api_key=openai_key)
agent_chain = initialize_agent(
    tools,
    llm,
    agent=AgentType.CONVERSATIONAL_REACT_DESCRIPTION,
    verbose=True,
    memory=memory,
)
```

### Improved Access to Enriched Memory

Langchain's `ZepMemory` class now provides access to Zep's enriched memory attributes, including extracted entities, intents, token counts, timestamps, and UUIDs.

```python
def print_messages(messages):
    for m in messages:
        print(m.type, ":\n", m.dict())

print(memory.chat_memory.zep_summary)
print("\n")
print_messages(memory.chat_memory.messages)

    The human inquires about Octavia Butler. The AI identifies her as an American science fiction author. The human then asks which books of hers were made into movies. The AI responds by mentioning the FX series Kindred, based on her novel of the same name. The human then asks about her contemporaries, and the AI lists Ursula K. Le Guin, Samuel R. Delany, and Joanna Russ.
    
    
    system :
     {'content': 'The human inquires about Octavia Butler. The AI identifies her as an American science fiction author. The human then asks which books of hers were made into movies. The AI responds by mentioning the FX series Kindred, based on her novel of the same name. The human then asks about her contemporaries, and the AI lists Ursula K. Le Guin, Samuel R. Delany, and Joanna Russ.', 'additional_kwargs': {}}
    human :
     {'content': 'What awards did she win?', 'additional_kwargs': {'uuid': '6b733f0b-6778-49ae-b3ec-4e077c039f31', 'created_at': '2023-07-09T19:23:16.611232Z', 'token_count': 8, 'metadata': {'system': {'entities': [], 'intent': 'The subject is inquiring about the awards that someone, whose identity is not specified, has won.'}}}, 'example': False}
    ai :
     {'content': 'Octavia Butler won the Hugo Award, the Nebula Award, and the MacArthur Fellowship.', 'additional_kwargs': {'uuid': '2f6d80c6-3c08-4fd4-8d4e-7bbee341ac90', 'created_at': '2023-07-09T19:23:16.618947Z', 'token_count': 21, 'metadata': {'system': {'entities': [{'Label': 'PERSON', 'Matches': [{'End': 14, 'Start': 0, 'Text': 'Octavia Butler'}], 'Name': 'Octavia Butler'}, {'Label': 'WORK_OF_ART', 'Matches': [{'End': 33, 'Start': 19, 'Text': 'the Hugo Award'}], 'Name': 'the Hugo Award'}, {'Label': 'EVENT', 'Matches': [{'End': 81, 'Start': 57, 'Text': 'the MacArthur Fellowship'}], 'Name': 'the MacArthur Fellowship'}], 'intent': 'The subject is stating that Octavia Butler received the Hugo Award, the Nebula Award, and the MacArthur Fellowship.'}}}, 'example': False}
<snip />
```

### Custom Chains Can Persist and Search Over Custom Metadata

Custom chain developers can now add their own metadata to chat messages when they're persisted to Zep. This [metadata is then searchable](https://blog.getzep.com/introducing-zep-hybrid-search-metadata/) via the [ZepRetriever or other Zep search functionality](https://docs.getzep.com/sdk/langchain/?ref=blog.getzep.com#search-zeps-message-history-from-your-langchain-app).

The `ZepMemory` class's `save_context` method now supports passing in a `metadata` argument. Your custom Chain class must override the [base Chain's \`prep\_outputs\` method](https://github.com/hwchase17/langchain/blob/5eec74d9a5435c671382e69412072a8725b2ec60/langchain/chains/base.py?ref=blog.getzep.com#L319) to include the metadata in the call to `self.memory.save_context`.

### Other Improvements

The chat history *summary* is now included in the `ZepMemory` chat history as a `SystemMessage`, whereas before, it was a `HumanMessage`. This change reduces ambiguity as to the origin of the summary.