transform_messages
autogen.agentchat.contrib.capabilities.transform_messages.TransformMessages
TransformMessages
Agent capability for transforming messages before reply generation.
This capability allows you to apply a series of message transformations to a ConversableAgent’s incoming messages before they are processed for response generation. This is useful for tasks such as:
- Limiting the number of messages considered for context.
- Truncating messages to meet token limits.
- Filtering sensitive information.
- Customizing message formatting.
To use TransformMessages
:
- Create message transformations (e.g.,
MessageHistoryLimiter
,MessageTokenLimiter
). - Instantiate
TransformMessages
with a list of these transformations. - Add the
TransformMessages
instance to yourConversableAgent
usingadd_to_agent
.
NOTE: Order of message transformations is important. You could get different results based on the order of transformations.
Example:
Name | Description |
---|---|
transforms | A list of message transformations to apply. Type: list[autogen.agentchat.contrib.capabilities.transforms.MessageTransform] Default: [] |
verbose | Whether to print logs of each transformation or not. Type: bool Default: True |
Instance Methods
add_to_agent
Adds the message transformations capability to the specified ConversableAgent.
This function performs the following modifications to the agent:
- Registers a hook that automatically transforms all messages before they are processed for response generation.
Name | Description |
---|---|
agent | Type: autogen.agentchat.conversable_agent.ConversableAgent |