Agent - AG2

Agent

autogen.Agent

Bases: Protocol

(In preview) A protocol for Agent.

An agent can communicate with other agents and perform actions. Different agents can differ in what actions they perform in the receive method.

name property

name

The name of the agent.

description property

description

The description of the agent. Used for the agent's introduction in a group chat setting.

send

send(message, recipient, request_reply=None)

Send a message to another agent.

PARAMETER DESCRIPTION
message the message to send. If a dict, it should be a JSON-serializable and follows the OpenAI's ChatCompletion schema.
TYPE:dict or str
recipient the recipient of the message.
TYPE:Agent
request_reply whether to request a reply from the recipient.
TYPE:boolDEFAULT:None

Source code in autogen/agentchat/agent.py

    def send(
        self,
        message: Union[dict[str, Any], str],
        recipient: "Agent",
        request_reply: Optional[bool] = None,
    ) -> None:
        """Send a message to another agent.
        Args:
            message (dict or str): the message to send. If a dict, it should be
                a JSON-serializable and follows the OpenAI's ChatCompletion schema.
            recipient (Agent): the recipient of the message.
            request_reply (bool): whether to request a reply from the recipient.
        """
        ...

a_send async

a_send(message, recipient, request_reply=None)

(Async) Send a message to another agent.

Source code in autogen/agentchat/agent.py

async def a_send(
    self,
    message: Union[dict[str, Any], str],
    recipient: "Agent",
    request_reply: Optional[bool] = None,
) -> None:
    """(Async) Send a message to another agent.
    Args:
        message (dict or str): the message to send. If a dict, it should be
            a JSON-serializable and follows the OpenAI's ChatCompletion schema.
        recipient (Agent): the recipient of the message.
        request_reply (bool): whether to request a reply from the recipient.
    """
    ...

receive

receive(message, sender, request_reply=None)

Receive a message from another agent.

PARAMETER DESCRIPTION
message the message received. If a dict, it should be a JSON-serializable and follows the OpenAI's ChatCompletion schema.
TYPE:dict or str
sender the sender of the message.
TYPE:Agent
request_reply whether the sender requests a reply.
TYPE:boolDEFAULT:None

Source code in autogen/agentchat/agent.py

def receive(
    self,
    message: Union[dict[str, Any], str],
    sender: "Agent",
    request_reply: Optional[bool] = None,
) -> None:
    """Receive a message from another agent.
    Args:
        message (dict or str): the message received. If a dict, it should be
            a JSON-serializable and follows the OpenAI's ChatCompletion schema.
        sender (Agent): the sender of the message.
        request_reply (bool): whether the sender requests a reply.
    """

a_receive async

a_receive(message, sender, request_reply=None)

(Async) Receive a message from another agent.

Source code in autogen/agentchat/agent.py

async def a_receive(
    self,
    message: Union[dict[str, Any], str],
    sender: "Agent",
    request_reply: Optional[bool] = None,
) -> None:
    """(Async) Receive a message from another agent.
    Args:
        message (dict or str): the message received. If a dict, it should be
            a JSON-serializable and follows the OpenAI's ChatCompletion schema.
        sender (Agent): the sender of the message.
        request_reply (bool): whether the sender requests a reply.
    """
    ...

generate_reply

generate_reply(messages=None, sender=None, **kwargs)

Generate a reply based on the received messages.

PARAMETER DESCRIPTION
messages a list of messages received from other agents. The messages are dictionaries that are JSON-serializable and follows the OpenAI's ChatCompletion schema.
TYPE:list[dict[str, Any]]DEFAULT:None
sender sender of an Agent instance.
TYPE:Optional[Agent]DEFAULT:None
**kwargs Additional keyword arguments.
TYPE:AnyDEFAULT:{}
RETURNS DESCRIPTION
Union[str, dict[str, Any], None] str or dict or None: the generated reply. If None, no reply is generated.

Source code in autogen/agentchat/agent.py

def generate_reply(
    self,
    messages: Optional[list[dict[str, Any]]] = None,
    sender: Optional["Agent"] = None,
    **kwargs: Any,
) -> Union[str, dict[str, Any], None]:
    """Generate a reply based on the received messages.
    Args:
        messages (list[dict[str, Any]]): a list of messages received from other agents.
            The messages are dictionaries that are JSON-serializable and
            follows the OpenAI's ChatCompletion schema.
        sender: sender of an Agent instance.
        **kwargs: Additional keyword arguments.
    Returns:
        str or dict or None: the generated reply. If None, no reply is generated.
    """

a_generate_reply async

a_generate_reply(messages=None, sender=None, **kwargs)

(Async) Generate a reply based on the received messages.

RETURNS DESCRIPTION
Union[str, dict[str, Any], None] str or dict or None: the generated reply. If None, no reply is generated.

Source code in autogen/agentchat/agent.py

async def a_generate_reply(
    self,
    messages: Optional[list[dict[str, Any]]] = None,
    sender: Optional["Agent"] = None,
    **kwargs: Any,
) -> Union[str, dict[str, Any], None]:
    """(Async) Generate a reply based on the received messages.
    Args:
        messages (list[dict[str, Any]]): a list of messages received from other agents.
            The messages are dictionaries that are JSON-serializable and
            follows the OpenAI's ChatCompletion schema.
        sender: sender of an Agent instance.
        **kwargs: Additional keyword arguments.
    Returns:
        str or dict or None: the generated reply. If None, no reply is generated.
    """

set_ui_tools

set_ui_tools(tools)

Set the UI tools for the agent.

PARAMETER DESCRIPTION
tools a list of UI tools to set.
TYPE:list[Tool]

Source code in autogen/agentchat/agent.py

def set_ui_tools(self, tools: list[Tool]) -> None:
    """Set the UI tools for the agent.
    Args:
        tools: a list of UI tools to set.
    """
    ...

unset_ui_tools

unset_ui_tools(tools)

Unset the UI tools for the agent.

PARAMETER DESCRIPTION
tools a list of UI tools to set.
TYPE:list[Tool]

Source code in autogen/agentchat/agent.py

def unset_ui_tools(self, tools: list[Tool]) -> None:
    """Unset the UI tools for the agent.
    Args:
        tools: a list of UI tools to set.
    """
    ...