跳到主要内容

agentchat.agent

代理

@runtime_checkable
class Agent(Protocol)

(预览中)一个用于Agent的协议。

一个代理可以与其他代理通信并执行操作。 不同的代理在receive方法中执行的操作可能有所不同。

名称

@property
def name() -> str

代理的名称。

描述

@property
def description() -> str

代理的描述。用于群聊设置中的代理介绍。

发送

def send(message: Union[Dict[str, Any], str],
recipient: "Agent",
request_reply: Optional[bool] = None) -> None

向另一个代理发送消息。

参数:

  • message dict or str - 要发送的消息。如果是 dict,则它应该是可 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 - 是否请求接收者回复。

接收

def receive(message: Union[Dict[str, Any], str],
sender: "Agent",
request_reply: Optional[bool] = None) -> None

从另一个代理接收消息。

参数:

  • message dict or 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 or str - 接收到的消息。如果是字典,它应该是可JSON序列化的,并遵循OpenAI的ChatCompletion模式。
  • sender Agent - 消息的发送者。
  • request_reply bool - 发送方是否请求回复。

generate_reply

def generate_reply(messages: Optional[List[Dict[str, Any]]] = None,
sender: Optional["Agent"] = None,
**kwargs: Any) -> Union[str, Dict[str, Any], None]

根据收到的消息生成回复。

参数:

  • messages list[dict] - 从其他代理接收到的消息列表。 这些消息是符合 JSON 可序列化的字典,并且遵循 OpenAI 的 ChatCompletion 模式。
  • sender - Agent实例的发送者。

返回:

str 或 dict 或 None: 生成的回复。如果为 None,则不生成回复。

a_generate_reply

async def a_generate_reply(messages: Optional[List[Dict[str, Any]]] = None,
sender: Optional["Agent"] = None,
**kwargs: Any) -> Union[str, Dict[str, Any], None]

(异步)根据接收到的消息生成回复。

参数:

  • messages list[dict] - 从其他代理接收到的消息列表。 这些消息是可以进行JSON序列化的字典, 并遵循OpenAI的ChatCompletion模式。
  • sender - Agent 实例的发送者。

返回:

str 或 dict 或 None:生成的回复。如果为 None,则不会生成任何回复。

LLMAgent

@runtime_checkable
class LLMAgent(Agent, Protocol)

(预览中)一个用于LLM代理的协议。

系统消息

@property
def system_message() -> str

此代理的系统消息。

update_system_message

def update_system_message(system_message: str) -> None

更新此代理的系统消息。

参数:

  • system_message str - 用于推理的系统消息。