Files in Agent Chat

Hey,

I’m looking for an approach for storing file meta data (title, s3-url of file) to an agent chat and save it to the message and store it by memorysaver or something similar:

Langgraph chat and state is running and working. I’m just want to know how to store this information to the “HumanMessage" to show it later in the UI.

Any hints are welcome.

Thanks
Sven

Store file metadata in the HumanMessage’s additional_kwargs field, which is designed for this purpose:

from langchain_core.messages import HumanMessage

# When creating the message with file metadata
message = HumanMessage(
    content="Here's my document",
    additional_kwargs={
        "file_metadata": {
            "title": "document.pdf",
            "s3_url": "https://bucket.s3.amazonaws.com/file.pdf",
            "file_type": "pdf"
        }
    }
)

# In your UI, access the metadata
file_info = message.additional_kwargs.get("file_metadata")

Your MemorySaver will automatically persist this metadata along with the message. When you retrieve the conversation history, the file metadata will be available in each message’s additional_kwargs for display in your UI.

2 Likes

Cool. Thank you!

Thanks for the info. Would you mind telling me how you figured this out? I cant find any documentation stating that additional_kwargs is the way to go when it comes to “rendering attachments” in the ui