Add metadata field to basemessage (#5372)

Add metadata field to BaseMessage.

Why?
- additional metadata field can track 1) timestamp if needed, 2) flags
about the message. For instance, a use case is a metadata field
{"internal":"yes"} that would hide messages from being displayed in an
application or studio.

As long as an extra field is added to basemessage that is not consumed
by existing agents, I am happy.



Notes:
- We can also only add it to BaseChatMessage, that would be fine
- I don't care what the extra field is called as long as there is an
extra field somewhere
- I don't have preference for the type, a str could work, but a dict
would be more useful.

---------

Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
This commit is contained in:
Hussein Mozannar 2025-02-24 22:54:49 -08:00 committed by GitHub
parent c302b5408a
commit 4dac9c819e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,7 +5,7 @@ class and includes specific fields relevant to the type of message being sent.
"""
from abc import ABC
from typing import List, Literal
from typing import Dict, List, Literal
from autogen_core import FunctionCall, Image
from autogen_core.memory import MemoryContent
@ -23,6 +23,9 @@ class BaseMessage(BaseModel, ABC):
models_usage: RequestUsage | None = None
"""The model client usage incurred when producing this message."""
metadata: Dict[str, str] = {}
"""Additional metadata about the message."""
model_config = ConfigDict(arbitrary_types_allowed=True)