langchain/libs/core/langchain_core/runnables
ccurme 0f7569ddbc
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.
```
2024-07-22 10:36:53 -04:00
..
__init__.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
base.py core[patch]: ensure iterator_ in scope for _atransform_stream_with_config except (#24454) 2024-07-20 03:24:04 +00:00
branch.py core[patch]: docstrings runnables update (#24161) 2024-07-12 11:27:06 -04:00
config.py core[patch]: Accept configurable keys top-level (#23806) 2024-07-20 03:49:00 +00:00
configurable.py core[patch]: docstrings runnables update (#24161) 2024-07-12 11:27:06 -04:00
fallbacks.py core[patch]: docstrings runnables update (#24161) 2024-07-12 11:27:06 -04:00
graph_ascii.py core[patch]: docstrings runnables update (#24161) 2024-07-12 11:27:06 -04:00
graph_mermaid.py core[patch]: docstrings runnables update (#24161) 2024-07-12 11:27:06 -04:00
graph_png.py core[patch]: docstrings runnables update (#24161) 2024-07-12 11:27:06 -04:00
graph.py core[patch]: docstrings runnables update (#24161) 2024-07-12 11:27:06 -04:00
history.py core[patch]: enable RunnableWithMessageHistory without config (#23775) 2024-07-22 10:36:53 -04:00
learnable.py [Enhancement] Add support for directly providing a run_id (#18990) 2024-03-18 15:03:04 -07:00
passthrough.py core[patch]: docstrings runnables update (#24161) 2024-07-12 11:27:06 -04:00
retry.py core[patch]: docstrings runnables update (#24161) 2024-07-12 11:27:06 -04:00
router.py core[patch]: docstrings runnables update (#24161) 2024-07-12 11:27:06 -04:00
schema.py Docs: Add how to dispatch custom callback events (#24278) 2024-07-16 17:38:32 -04:00
utils.py core[patch]: docstrings runnables update (#24161) 2024-07-12 11:27:06 -04:00