# 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`

```python
name
```

The name of the agent.

### `description property`

```python
description
```

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

### `send`

```python
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.<br>**TYPE:**`dict or str` |
| `recipient` | the recipient of the message.<br>**TYPE:**`Agent` |
| `request_reply` | whether to request a reply from the recipient.<br>**TYPE:**`bool`**DEFAULT:**`None` |

Source code in `autogen/agentchat/agent.py`

```python
    def send(
        self,
        message: dict[str, Any] | str,
        recipient: "Agent",
        request_reply: bool | None = 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`

```python
a_send(message, recipient, request_reply=None)
```

(Async) Send a message to another agent.

Source code in `autogen/agentchat/agent.py`

```python
async def a_send(
    self,
    message: dict[str, Any] | str,
    recipient: "Agent",
    request_reply: bool | None = 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`

```python
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.<br>**TYPE:**`dict or str` |
| `sender` | the sender of the message.<br>**TYPE:**`Agent` |
| `request_reply` | whether the sender requests a reply.<br>**TYPE:**`bool`**DEFAULT:**`None` |

Source code in `autogen/agentchat/agent.py`

```python
    def receive(
        self,
        message: dict[str, Any] | str,
        sender: "Agent",
        request_reply: bool | None = 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`

```python
a_receive(message, sender, request_reply=None)
```

(Async) Receive a message from another agent.

Source code in `autogen/agentchat/agent.py`

```python
async def a_receive(
    self,
    message: dict[str, Any] | str,
    sender: "Agent",
    request_reply: bool | None = 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`

```python
generate_reply(messages=None, sender=None)
```

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.<br>**TYPE:**`list[dict[str, Any]]`**DEFAULT:**`None` |
| `sender` | sender of an Agent instance.<br>**TYPE:**`Optional[Agent]`**DEFAULT:**`None` |
| `**kwargs` | Additional keyword arguments. |

| RETURNS | DESCRIPTION |
| --- | --- |
| `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`

```python
    def generate_reply(
        self,
        messages: list[dict[str, Any]] | None = None,
        sender: Optional["Agent"] = None,
    ) -> 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`

```python
a_generate_reply(messages=None, sender=None)
```

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

| RETURNS | DESCRIPTION |
| --- | --- |
| `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`

```python
async def a_generate_reply(
    self,
    messages: list[dict[str, Any]] | None = None,
    sender: Optional["Agent"] = None,
) -> 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`

```python
set_ui_tools(tools)
```

Set the UI tools for the agent.

| PARAMETER | DESCRIPTION |
| --- | --- |
| `tools` | a list of UI tools to set.<br>**TYPE:**`list[Tool]` |

Source code in `autogen/agentchat/agent.py`

```python
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`

```python
unset_ui_tools(tools)
```

Unset the UI tools for the agent.

| PARAMETER | DESCRIPTION |
| --- | --- |
| `tools` | a list of UI tools to set.<br>**TYPE:**`list[Tool]` |

Source code in `autogen/agentchat/agent.py`

```python
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.
    """
    ...
```
