Agent

Agent(*args, **kwargs)

(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.

Parameters:
NameDescription
*args
**kwargs

Instance Attributes

description


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

name


The name of the agent.

Instance Methods

a_generate_reply

a_generate_reply(
    self,
    messages: list[dict[str, typing.Any]] | None = None,
    sender: ForwardRef('Agent') | None = None,
    **kwargs: Any
) -> str | dict[str, typing.Any] | None

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

Parameters:
NameDescription
messagesa 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, typing.Any]] | None

Default: None
sendersender of an Agent instance.

Type: ForwardRef('Agent') | None

Default: None
**kwargsType: Any
Returns:
TypeDescription
str | dict[str, typing.Any] | Nonestr or dict or None: the generated reply. If None, no reply is generated.

a_receive

a_receive(
    self,
    message: dict[str, typing.Any] | str,
    sender: Agent,
    request_reply: bool | None = None
) -> None

(Async) Receive a message from another agent.

Parameters:
NameDescription
messagethe message received.

If a dict, it should be a JSON-serializable and follows the OpenAI’s ChatCompletion schema.

Type: dict[str, typing.Any] | str
senderthe sender of the message.

Type: Agent
request_replywhether the sender requests a reply.

Type: bool | None

Default: None

a_send

a_send(
    self,
    message: dict[str, typing.Any] | str,
    recipient: Agent,
    request_reply: bool | None = None
) -> None

(Async) Send a message to another agent.

Parameters:
NameDescription
messagethe message to send.

If a dict, it should be a JSON-serializable and follows the OpenAI’s ChatCompletion schema.

Type: dict[str, typing.Any] | str
recipientthe recipient of the message.

Type: Agent
request_replywhether to request a reply from the recipient.

Type: bool | None

Default: None

generate_reply

generate_reply(
    self,
    messages: list[dict[str, typing.Any]] | None = None,
    sender: ForwardRef('Agent') | None = None,
    **kwargs: Any
) -> str | dict[str, typing.Any] | None

Generate a reply based on the received messages.

Parameters:
NameDescription
messagesa 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, typing.Any]] | None

Default: None
sendersender of an Agent instance.

Type: ForwardRef('Agent') | None

Default: None
**kwargsType: Any
Returns:
TypeDescription
str | dict[str, typing.Any] | Nonestr or dict or None: the generated reply. If None, no reply is generated.

receive

receive(
    self,
    message: dict[str, typing.Any] | str,
    sender: Agent,
    request_reply: bool | None = None
) -> None

Receive a message from another agent.

Parameters:
NameDescription
messagethe message received.

If a dict, it should be a JSON-serializable and follows the OpenAI’s ChatCompletion schema.

Type: dict[str, typing.Any] | str
senderthe sender of the message.

Type: Agent
request_replywhether the sender requests a reply.

Type: bool | None

Default: None

send

send(
    self,
    message: dict[str, typing.Any] | str,
    recipient: Agent,
    request_reply: bool | None = None
) -> None

Send a message to another agent.

Parameters:
NameDescription
messagethe message to send.

If a dict, it should be a JSON-serializable and follows the OpenAI’s ChatCompletion schema.

Type: dict[str, typing.Any] | str
recipientthe recipient of the message.

Type: Agent
request_replywhether to request a reply from the recipient.

Type: bool | None

Default: None