agentscope.message.msg module
The base class for message unit
- class Msg(name: str, content: Any, role: str | Literal['system', 'user', 'assistant'], url: str | List[str] | None = None, metadata: str | dict | None = None, echo: bool = False, **kwargs: Any)[source]
Bases:
object
The message class for AgentScope, which is responsible for storing the information of a message, including
id: the identity of the message
name: who sends the message
content: the message content
role: the sender role chosen from ‘system’, ‘user’, ‘assistant’
url: the url(s) refers to multimodal content
metadata: some additional information
timestamp: when the message is created
- formatted_str(colored: bool = False) str [source]
Return the formatted string of the message. If the message has an url, the url will be appended to the content.
- Parameters:
colored (bool, defaults to False) – Whether to color the name of the message
- Returns:
The formatted string of the message.
- Return type:
str
- classmethod from_dict(serialized_dict: dict) Msg [source]
Deserialize the dictionary to a Msg object.
- Parameters:
serialized_dict (dict) – A dictionary that must contain the keys in Msg.__serialized_attrs, and the keys __module__ and __name__.
- Returns:
A Msg object.
- Return type:
Msg
- to_dict() dict [source]
Serialize the message into a dictionary, which can be deserialized by calling the from_dict function.
- Returns:
The serialized dictionary.
- Return type:
dict
- property content: Any
The content of the message.
- property id: str
The identity of the message.
- property metadata: str | dict | None
The metadata of the message, which can store some additional information.
- property name: str
The name of the message sender.
- property role: Literal['system', 'user', 'assistant']
The role of the message sender, chosen from ‘system’, ‘user’, ‘assistant’.
- property timestamp: str
The timestamp when the message is created.
- property url: str | List[str] | None
A URL string or a list of URL strings.