TextMessageContentName

TextMessageContentName(
    position: str = 'start',
    format_string: str = '{name}:\n',
    deduplicate: bool = True,
    filter_dict: dict[str, Any] | None = None,
    exclude_filter: bool = True
)

A transform for including the agent’s name in the content of a message.
How to create and apply the transform:
# Imports from autogen.agentchat.contrib.capabilities import transform_messages, transforms

Create Transform

name_transform = transforms.TextMessageContentName(position=“start”, format_string=”‘{name}’ said:
“)

Create the TransformMessages

context_handling = transform_messages.TransformMessages( transforms=[ name_transform ] )

Add it to an agent so when they run inference it will apply to the messages

context_handling.add_to_agent(my_agent)

Parameters:
NameDescription
positionType: str

Default: ‘start’
format_stringType: str

Default: ‘{name}
deduplicateType: bool

Default: True
filter_dictType: dict[str, typing.Any] | None

Default: None
exclude_filterType: bool

Default: True

Instance Methods

apply_transform

apply_transform(self, messages: list[dict[str, Any]]) -> list[dict[str, Any]]

Applies the name change to the message based on the position and format string.

Parameters:
NameDescription
messagesA list of message dictionaries.

Type: list[dict[str, typing.Any]]
Returns:
TypeDescription
list[dict[str, typing.Any]]List[Dict]: A list of dictionaries with the message content updated with names.

get_logs

get_logs(
    self,
    pre_transform_messages: list[dict[str, Any]],
    post_transform_messages: list[dict[str, Any]]
) -> tuple[str, bool]
Parameters:
NameDescription
pre_transform_messagesType: list[dict[str, typing.Any]]
post_transform_messagesType: list[dict[str, typing.Any]]