Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

THARUN-S-R
Copy link

Chat ID inclusion to the conversation history

Changes

We are passing the Chat Id variable into the conversation history to better identify the chats within the same session.

Implementation Details

The BaseMessage of langchain has capabilities to accept the ID which we can use to identify the exact chat incase we need to use it for training or feedback purposes

This change will not be affected if chat id is not sent.

@THARUN-S-R
Copy link
Author

hey @pietrozullo / @NandhuKishore24 , can you please review the changes for this request.

@renvins renvins requested a review from pietrozullo August 26, 2025 17:33
@pietrozullo
Copy link
Member

Hey @THARUN-S-R actually the chat id has no function on the local agent but only on the remote execution. I am not sure what are you trying to do here, could you explain ?

@THARUN-S-R
Copy link
Author

Hi @pietrozullo , I am using the Chat Id to pass a unique hash value to identify each agent run or Chat. This will be then added to the conversation history. I need to find each Chat to add a feedback to the response. This way i can identify the chat and improve prompting based on user feedback. For this langchain BaseMessage has optional id field which we can use to identify each chat.

@pietrozullo
Copy link
Member

Hey @THARUN-S-R I am still not sure I follow, have you see what the chat_id is used for inside the agent ? The chatID is a reference to the cloud hosted agent in the library context, it will not have anything to do with chat persistence locally, even after your changes. Also I see you are passing it in the langchain messages, which is fine, but that id is supposed to be unique for every message not a common one for a chat. If you want to persiste the messages in a chat you can create a Chat class where you persist them and you can have the Chat take an ID.

Maybe I am not seeing something here but this PR does not seem to solve the problem you want to address, imo

@THARUN-S-R
Copy link
Author

Hi @pietrozullo , yes the chat id initially is used only for remote agent, but in my use case I want to mark each chat with a unique id to reference it back later. Hence, this field was already there which i can use to pass the unique id into the Messages. This way i dont need a new parameter to achieve this and can be assigned in Chat_id. About the uniqueness of the id, before triggering the run(query) func, I will assign the agent a new chat id as :
agent.chat_id = chat_id
this assignment is not within the MCP-USE architecture and is at the users discretion. this way it doesnt affect the architecture if not passed but gives the user options to assign an id to the messages.:
image

This way I can easily identify the chats I want to refer back to. The user can have a feedback to the chat generated which we can use to adjust our prompt accordingly. This is just one of the use case of the Chat ID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants