agentchat.agent
Agent(代理)
@runtime_checkable
class Agent(Protocol)
(预览版)Agent 的协议。
代理可以与其他代理进行通信并执行操作。
不同的代理在 receive
方法中执行的操作可能不同。
name(名称)
@property
def name() -> str
代理的名称。
description(描述)
@property
def description() -> str
代理的描述。用于在群聊设置中介绍代理。
send(发送)
def send(message: Union[Dict[str, Any], str],
recipient: "Agent",
request_reply: Optional[bool] = None) -> None
向另一个代理发送消息。
参数:
message
dict 或 str - 要发送的消息。如果是字典,则应为可序列化为 JSON 并遵循 OpenAI 的 ChatCompletion 模式。recipient
Agent - 消息的接收者。request_reply
bool - 是否请求接收者回复。
a_send(异步发送)
async def a_send(message: Union[Dict[str, Any], str],
recipient: "Agent",
request_reply: Optional[bool] = None) -> None
(异步)向另一个代理发送消息。
参数:
message
dict 或 str - 要发送的消息。如果是字典,则应为可序列化为 JSON 并遵循 OpenAI 的 ChatCompletion 模式。recipient
Agent - 消息的接收者。request_reply
bool - 是否请求接收者回复。
receive(接收)
def receive(message: Union[Dict[str, Any], str],
sender: "Agent",
request_reply: Optional[bool] = None) -> None
从另一个代理接收消息。
参数:
message
dict 或 str - 接收到的消息。如果是字典,则应为可序列化为 JSON 并遵循 OpenAI 的 ChatCompletion 模式。sender
Agent - 消息的发送者。request_reply
bool - 发送者是否请求回复。
a_receive(异步接收)
async def a_receive(message: Union[Dict[str, Any], str],
sender: "Agent",
request_reply: Optional[bool] = None) -> None
(异步)从另一个代理接收消息。
参数:
message
dict 或 str - 接收到的消息。如果是字典,则应为可序列化为 JSON 并遵循 OpenAI 的 ChatCompletion 模式。sender
Agent - 消息的发送者。request_reply
bool - 发送者是否请求回复。