跳到主要内容

agentchat.user_proxy_agent

UserProxyAgent

class UserProxyAgent(ConversableAgent)

(预览中)一个为用户代理的代理人,可以执行代码并向其他代理人提供反馈。

UserProxyAgent 是 ConversableAgent 的一个子类,配置了 human_input_mode 为 ALWAYS 和 llm_config 为 False。默认情况下,代理每次接收到消息时都会提示用户输入。默认情况下启用代码执行功能。默认情况下禁用基于LLM的自动回复。要修改自动回复,请使用 register_reply 方法注册一个方法。要修改获取用户输入的方式,请重写 get_human_input 方法。要修改执行代码块、单个代码块或函数调用的方式,请分别重写 execute_code_blocksrun_codeexecute_function 方法。

__init__

def __init__(name: str,
is_termination_msg: Optional[Callable[[Dict], bool]] = None,
max_consecutive_auto_reply: Optional[int] = None,
human_input_mode: Literal["ALWAYS", "TERMINATE",
"NEVER"] = "ALWAYS",
function_map: Optional[Dict[str, Callable]] = None,
code_execution_config: Union[Dict, Literal[False]] = {},
default_auto_reply: Optional[Union[str, Dict, None]] = "",
llm_config: Optional[Union[Dict, Literal[False]]] = False,
system_message: Optional[Union[str, List]] = "",
description: Optional[str] = None,
**kwargs)

参数:

  • name str - 代理的名称。
  • is_termination_msg 函数 - 一个接收字典形式的消息并返回布尔值的函数,用于指示接收到的消息是否为终止消息。 该字典可以包含以下键:"content"(内容), "role"(角色), "name"(名称), "function_call"(函数调用)。
  • max_consecutive_auto_reply int - 最大连续自动回复次数。 默认为 None(未提供限制,此时将使用类属性 MAX_CONSECUTIVE_AUTO_REPLY 作为限制)。 此限制仅在 human_input_mode 不为 "ALWAYS" 时生效。
  • human_input_mode str - 是否在每次收到消息时请求人工输入。 可能的值为 "ALWAYS"、"TERMINATE"、"NEVER"。 (1) 当值为 "ALWAYS" 时,代理在每次收到消息时都会提示人工输入。 在此模式下,当人工输入为 "exit" 时,或当 is_termination_msg 为 True 且没有人工输入时,对话会停止。 (2) 当值为 "TERMINATE" 时,代理仅在收到终止消息或自动回复次数达到 max_consecutive_auto_reply 时提示人工输入。 (3) 当值为 "NEVER" 时,代理永远不会提示人工输入。在此模式下,当自动回复次数达到 max_consecutive_auto_reply 或 is_termination_msg 为 True 时,对话会停止。
  • function_map dict[str, callable] - 将函数名称(传递给openai)映射到可调用函数。
  • code_execution_config dict or False - config for the code execution. To disable code execution, set to False. Otherwise, set to a dictionary with the following keys:
    • work_dir(可选,str):代码执行的工作目录。 如果为None,将使用默认的工作目录。 默认工作目录是“path_to_autogen”下的“extensions”目录。
    • use_docker (可选, list, str 或 bool): 用于代码执行的docker镜像。 默认为True,意味着代码将在docker容器中执行。将使用默认的镜像列表。 如果提供了镜像名称的列表或字符串,代码将在成功拉取的首个镜像的docker容器中执行。 如果为False,代码将在当前环境中执行。 我们强烈推荐使用docker进行代码执行。
    • timeout(可选,int):最大执行时间(以秒为单位)。
    • last_n_messages(实验性,可选,int):用于代码执行的消息回溯数量。默认为1。
  • default_auto_reply str or dict or None - 当没有生成代码执行或基于llm的回复时的默认自动回复消息。
  • llm_config dict or False or None - llm推理配置。 请参考OpenAIWrapper.create 了解可用选项。 默认值为False,表示禁用基于llm的自动回复。 当设置为None时,将使用self.DEFAULT_CONFIG,其默认值为False。
  • system_message str 或 List - 用于 ChatCompletion 推理的系统消息。 仅在 llm_config 不为 False 时使用。用它来重新编程代理。
  • description str - 对该代理的简短描述。此描述由其他代理(例如GroupChatManager)使用,以决定何时调用该代理。(默认值:system_message)
  • **kwargs dict - 请参考ConversableAgent中的其他kwargs。