langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
91.27k stars 14.52k forks source link

Can't pass session id in #20255

Closed 1100111GTH closed 1 month ago

1100111GTH commented 4 months ago

Checked other resources

Example Code

server:

@chain
def base_answer(source: Dict):

    prompt_b = ChatPromptTemplate.from_messages(
        [
            ("system", system_prompt if source["from"] == "customer" else read_persist_var('system_prompt')), 
            MessagesPlaceholder(variable_name="history"),
            ("human", "{input}")
        ]
    )

    b_a = RunnableWithMessageHistory(
        prompt_b | llm(source["llm"]), 
        get_message_history, 
        input_messages_key="input", 
        history_messages_key="history"
    ) | StrOutputParser()

    return b_a

client:

base_answer = RemoteRunnable("http://localhost:2031/base_answer/")

base_answer.stream({"input": "hi"}, config={"configurable": {"session_id": "d"}})

Error Message and Stack Trace (if applicable)

ValueError: Missing keys ['session_id'] in config['configurable'] Expected keys are I'session_id'].When using via .invoke() or stream(), pass in a config; e.g., chain. invoke(f'input': "too'}, {'configurable': {'session_id': "[your-value-here]"}})

Description

CleanShot 2024-04-07 at 11 20 26 CleanShot 2024-04-07 at 11 21 14

System Info

python 3.9.18 langchian newest version ubuntu 20.04

liugddx commented 4 months ago

You can refer to this https://github.com/langchain-ai/langchain/pull/20155

1100111GTH commented 4 months ago

You can refer to this #20155

First thanks, but I'm not using agent, and I tried your code tip, the ConversationBufferMemory and hard code id + other chain, but not working. i need to output streaming to the client, and can't find helpful info on web, so it's difficult problem for me now.