langchain
0f7569dd - core[patch]: enable RunnableWithMessageHistory without config (#23775)

Commit
1 year ago
core[patch]: enable RunnableWithMessageHistory without config (#23775) Feedback that `RunnableWithMessageHistory` is unwieldy compared to ConversationChain and similar legacy abstractions is common. Legacy chains using memory typically had no explicit notion of threads or separate sessions. To use `RunnableWithMessageHistory`, users are forced to introduce this concept into their code. This possibly felt like unnecessary boilerplate. Here we enable `RunnableWithMessageHistory` to run without a config if the `get_session_history` callable has no arguments. This enables minimal implementations like the following: ```python from langchain_core.chat_history import InMemoryChatMessageHistory from langchain_core.runnables.history import RunnableWithMessageHistory from langchain_openai import ChatOpenAI llm = ChatOpenAI(model="gpt-3.5-turbo-0125") memory = InMemoryChatMessageHistory() chain = RunnableWithMessageHistory(llm, lambda: memory) chain.invoke("Hi I'm Bob") # Hello Bob! chain.invoke("What is my name?") # Your name is Bob. ```
Author
Parents
Loading