agentscope.message.msg module
The base class for message unit
- class Msg(name: str, content: str | Sequence[ToolUseBlock | ToolResultBlock | TextBlock | ImageBlock | AudioBlock | VideoBlock | FileBlock] | None, role: Literal['system', 'user', 'assistant'], metadata: str | int | float | bool | None | List[Any] | Dict[str, Any] = None, echo: bool = False, url: str | List[str] | None = None)[源代码]
基类:
BaseModel
The message class in AgentScope.
- classmethod from_dict(serialized_dict: dict) Msg [源代码]
Deserialize the dictionary to a Msg object.
- 参数:
serialized_dict (dict) -- A dictionary that must contain the keys
- 返回:
A Msg object.
- 返回类型:
Msg
- get_content_blocks(block_type: Literal['text', 'tool_use', 'tool_result', 'image', 'audio', 'video', 'file'] | None = None) list[ToolUseBlock | ToolResultBlock | TextBlock | ImageBlock | AudioBlock | VideoBlock | FileBlock] [源代码]
Get the content in block format. If the content is a string, it will be converted to a text block.
- 参数:
(`Optional[Literal["text" (block_type) --
"image", "audio", "video", "file"]]`, defaults to None): The type of the block to be extracted. If None, all blocks will be returned.
"tool_use" -- "image", "audio", "video", "file"]]`, defaults to None): The type of the block to be extracted. If None, all blocks will be returned.
"tool_result" -- "image", "audio", "video", "file"]]`, defaults to None): The type of the block to be extracted. If None, all blocks will be returned.
- :param"image", "audio", "video", "file"]]`, defaults to None):
The type of the block to be extracted. If None, all blocks will be returned.
- 返回:
The content blocks.
- 返回类型:
list[ContentBlock]
- to_dict() dict [源代码]
Serialize the message into a dictionary, which can be deserialized by calling the from_dict function.
- 返回:
The serialized dictionary.
- 返回类型:
dict
- content: str | list[ToolUseBlock | ToolResultBlock | TextBlock | ImageBlock | AudioBlock | VideoBlock | FileBlock]
The content of the message.
- id: str
The unique identity of the message.
- metadata: str | int | float | bool | None | List[Any] | Dict[str, Any]
The additional metadata stored in the message.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str
The name of the message sender.
- role: Literal['system', 'user', 'assistant']
The role of the message sender.
- timestamp: str
The timestamp of the message.