Skip to content

Accessing chat history as input to TransformChain #26380

Closed Answered by dosubot bot
snassimr asked this question in Q&A
Discussion options

You must be logged in to vote

To make 'history' accessible over the whole chain while also passing the output from subchain1 to subchain2, you can use the RunnableBranch to handle the conditional logic and ensure that the history is passed along with the input. Here is an example based on your requirements:

from langchain_core.messages import HumanMessage
from langchain.chains import TransformChain
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.chat_history import (
    BaseChatMessageHistory,
    InMemoryChatMessageHistory,
)
from langchain_core.runnables import RunnableBranch, RunnableLambda
from langchain_core.runnables.history import RunnableWithMessageHistory

def f1(

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@snassimr
Comment options

@dosubot
Comment options

Comment options

You must be logged in to vote
1 reply
@dosubot
Comment options

Comment options

You must be logged in to vote
1 reply
@dosubot
Comment options

Comment options

You must be logged in to vote
1 reply
@dosubot
Comment options

Answer selected by snassimr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant