agentscope.message.msg

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)[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]

get_text_content() str | None[source]

Get the pure text blocks from the message content.

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.