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

|     |     |
| --- | --- |
| ```<br>41<br>42<br>43<br>44<br>45<br>46<br>47<br>48<br>49<br>50<br>51<br>52<br>53<br>54<br>55<br>``` | ```<br>def send(<br>    self,<br>    message: dict[str, Any] | str,<br>    recipient: "Agent",<br>    request_reply: bool | None = None,<br>) -> None:<br>    """Send a message to another agent.<br>    Args:<br>        message (dict or str): the message to send. If a dict, it should be<br>            a JSON-serializable and follows the OpenAI's ChatCompletion schema.<br>        recipient (Agent): the recipient of the message.<br>        request_reply (bool): whether to request a reply from the recipient.<br>    """<br>    ...<br>``` |

### `a_send async`

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

(Async) Send a message to another agent.

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

|     |     |
| --- | --- |
| ```<br>57<br>58<br>59<br>60<br>61<br>62<br>63<br>64<br>65<br>66<br>67<br>68<br>69<br>70<br>71<br>``` | ```<br>async def a_send(<br>    self,<br>    message: dict[str, Any] | str,<br>    recipient: "Agent",<br>    request_reply: bool | None = None,<br>) -> None:<br>    """(Async) Send a message to another agent.<br>    Args:<br>        message (dict or str): the message to send. If a dict, it should be<br>            a JSON-serializable and follows the OpenAI's ChatCompletion schema.<br>        recipient (Agent): the recipient of the message.<br>        request_reply (bool): whether to request a reply from the recipient.<br>    """<br>    ...<br>``` |

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

|     |     |
| --- | --- |
| ```<br>73<br>74<br>75<br>76<br>77<br>78<br>79<br>80<br>81<br>82<br>83<br>84<br>85<br>86<br>``` | ```<br>def receive(<br>    self,<br>    message: dict[str, Any] | str,<br>    sender: "Agent",<br>    request_reply: bool | None = None,<br>) -> None:<br>    """Receive a message from another agent.<br>    Args:<br>        message (dict or str): the message received. If a dict, it should be<br>            a JSON-serializable and follows the OpenAI's ChatCompletion schema.<br>        sender (Agent): the sender of the message.<br>        request_reply (bool): whether the sender requests a reply.<br>    """<br>``` |

### `a_receive async`

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

(Async) Receive a message from another agent.

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

|     |     |
| --- | --- |
| ```<br> 88<br> 89<br> 90<br> 91<br> 92<br> 93<br> 94<br> 95<br> 96<br> 97<br> 98<br> 99<br>100<br>101<br>102<br>``` | ```<br>async def a_receive(<br>    self,<br>    message: dict[str, Any] | str,<br>    sender: "Agent",<br>    request_reply: bool | None = None,<br>) -> None:<br>    """(Async) Receive a message from another agent.<br>    Args:<br>        message (dict or str): the message received. If a dict, it should be<br>            a JSON-serializable and follows the OpenAI's ChatCompletion schema.<br>        sender (Agent): the sender of the message.<br>        request_reply (bool): whether the sender requests a reply.<br>    """<br>    ...<br>``` |

### `generate_reply`

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

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

|     |     |
| --- | --- |
| ```<br>104<br>105<br>106<br>107<br>108<br>109<br>110<br>111<br>112<br>113<br>114<br>115<br>116<br>117<br>118<br>119<br>``` | ```<br>def generate_reply(<br>    self,<br>    messages: list[dict[str, Any]] | None = None,<br>    sender: Optional["Agent"] = None,<br>) -> str | dict[str, Any] | None:<br>    """Generate a reply based on the received messages.<br>    Args:<br>        messages (list[dict[str, Any]]): a list of messages received from other agents.<br>            The messages are dictionaries that are JSON-serializable and<br>            follows the OpenAI's ChatCompletion schema.<br>        sender: sender of an Agent instance.<br>    Returns:<br>        str or dict or None: the generated reply. If None, no reply is generated.<br>    """<br>``` |

### `a_generate_reply async`

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

|     |     |
| --- | --- |
| ```<br>121<br>122<br>123<br>124<br>125<br>126<br>127<br>128<br>129<br>130<br>131<br>132<br>133<br>134<br>135<br>136<br>137<br>``` | ```<br>async def a_generate_reply(<br>    self,<br>    messages: list[dict[str, Any]] | None = None,<br>    sender: Optional["Agent"] = None,<br>) -> str | dict[str, Any] | None:<br>    """(Async) Generate a reply based on the received messages.<br>    Args:<br>        messages (list[dict[str, Any]]): a list of messages received from other agents.<br>            The messages are dictionaries that are JSON-serializable and<br>            follows the OpenAI's ChatCompletion schema.<br>        sender: sender of an Agent instance.<br>    Returns:<br>        str or dict or None: the generated reply. If None, no reply is generated.<br>    """<br>    ...<br>``` |

### `set_ui_tools`

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

|     |     |
| --- | --- |
| ```<br>139<br>140<br>141<br>142<br>143<br>144<br>145<br>``` | ```<br>def set_ui_tools(self, tools: list[Tool]) -> None:<br>    """Set the UI tools for the agent.<br>    Args:<br>        tools: a list of UI tools to set.<br>    """<br>    ...<br>``` |

### `unset_ui_tools`

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

|     |     |
| --- | --- |
| ```<br>147<br>148<br>149<br>150<br>151<br>152<br>153<br>``` | ```<br>def unset_ui_tools(self, tools: list[Tool]) -> None:<br>    """Unset the UI tools for the agent.<br>    Args:<br>        tools: a list of UI tools to set.<br>    """<br>    ...<br>``` |
