memory metadata

I've got a setup where I'm doing conversation agents with different personalities. The user can switch personalities mid conversation. I'm wondering, is there a way to persist this information with the memory on messages so that I can display the personalilty name and maybe an avatar? I can't find any documentation (please point me there if there is some) on how to add metadata to messages and then use it with AI SDK useChat. Thanks!
5 Replies
_roamin_
_roamin_5d ago
Hi @rogueturnip ! You currently cannot attach metadata to a message, however, you can attache metadata to a thread, see this message https://discord.com/channels/1309558646228779139/1428396355180695572/1428510155221368924
rogueturnip
rogueturnipOP5d ago
Thanks @Romain I'm[ not sure if this will solve my needs. I'm actually using a single thread as a personal assitant type setup that the user can change their personality slight follow up. is it possible to know which agent placed something in memory?
_roamin_
_roamin_5d ago
Actually, I think the metadata at the message level is actually possible I just forgot... BUT, it's currently buggy, you can watch this GH issue for updates https://github.com/mastra-ai/mastra/issues/8938
GitHub
[BUG] Custom metadata no longer being returned on UIMessages · Iss...
Describe the Bug Custom metadata is not being returned for messages on latest version. Loading threads now returns [messages, uiMessages, legacyMessages]. The UI messages no longer contain the cust...
_roamin_
_roamin_5d ago
As for your other question, you cannot know at the moment which agent inserted the message into memory, but, it's something you should be able to do using the metadata (once they work again...)
rogueturnip
rogueturnipOP3d ago
Wonderful! I was curious cause I was debugging and I see in the client side the meta data there
(2) [{…}, {…}]
0
:
id
:
"0199eeb4-e5e6-74b2-8ac5-30cfc9abce1b"
metadata
:
{createdAt: '2025-10-17T03:27:39.957Z'}
parts
:
[{…}]
role
:
"user"
[[Prototype]]
:
Object
1
:
{id: 'f5a9df08-4be0-4724-96bf-25d1ded5bfe8', role: 'assistant', metadata: {…}, parts: Array(3)}
length
:
2
[[Prototype]]
:
Array(0)
(2) [{…}, {…}]
0
:
id
:
"0199eeb4-e5e6-74b2-8ac5-30cfc9abce1b"
metadata
:
{createdAt: '2025-10-17T03:27:39.957Z'}
parts
:
[{…}]
role
:
"user"
[[Prototype]]
:
Object
1
:
{id: 'f5a9df08-4be0-4724-96bf-25d1ded5bfe8', role: 'assistant', metadata: {…}, parts: Array(3)}
length
:
2
[[Prototype]]
:
Array(0)
Bug looks exactly like what I'm wondering.. but do you konw how to actually add the custom metadata? I don't see that in the bug directions.

Did you find this page helpful?