agentscope.message
The message module of AgentScope.
- class AudioBlock[source]
Bases:
TypedDict
The audio block
- type: Required[Literal['audio']]
The type of the block
- url: str
The url of the audio
- class FileBlock[source]
Bases:
TypedDict
The file block
- type: Required[Literal['file']]
The type of the block
- url: str
The url of the file
- class ImageBlock[source]
Bases:
TypedDict
The image block
- type: Required[Literal['image']]
The type of the block
- url: str
The url of the image
- 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)[source]
Bases:
BaseModel
The message class in AgentScope.
- 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
- Returns:
A Msg object.
- Return type:
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] [source]
Get the content in block format. If the content is a string, it will be converted to a text block.
- Parameters:
(`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.
- Returns:
The content blocks.
- Return type:
list[ContentBlock]
- 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
- 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.
- class TextBlock[source]
Bases:
TypedDict
The text block.
- text: str
The text content
- type: Required[Literal['text']]
The type of the block
- class ToolResultBlock[source]
Bases:
TypedDict
The tool result block.
- id: Required[str]
The identity of the tool call result
- name: str | None
The name of the tool function
- output: Required[object]
The output of the tool function
- type: Required[Literal['tool_result']]
The type of the block