跳到主要内容

agentchat.contrib.gpt_assistant_agent

GPT助手代理

class GPTAssistantAgent(ConversableAgent)

一个实验性的AutoGen代理类,利用OpenAI助手API实现对话功能。 该代理的独特之处在于其依赖OpenAI助手进行状态管理,这与ConversableAgent等其他代理不同。

__init__

def __init__(name="GPT Assistant",
instructions: Optional[str] = None,
llm_config: Optional[Union[Dict, bool]] = None,
assistant_config: Optional[Dict] = None,
overwrite_instructions: bool = False,
overwrite_tools: bool = False,
**kwargs)

参数:

  • name str - 代理的名称。它将用于通过名称查找现有的助手。如果您打算创建一个同名的新助手,请记得删除同名的旧助手。
  • instructions str - OpenAI 助手配置的指令。 当 instructions 不为 None 时,代理的系统消息将被设置为提供的指令,并在助手运行时使用,无论 overwrite_instructions 标志如何。但当 instructions 为 None,且助手不存在时,系统消息将被设置为 AssistantAgent.DEFAULT_SYSTEM_MESSAGE。如果助手存在,系统消息将被设置为现有助手的指令。
  • llm_config dict or False - llm inference configuration.
    • model: 用于助手的模型(gpt-4-1106-preview, gpt-3.5-turbo-1106)。 assistant_config
    • assistant_id: 要使用的助手的ID。如果为None,将创建一个新的助手。
    • check_every_ms: 检查线程运行状态的时间间隔
    • 工具: 让助手访问OpenAI托管的工具,如代码解释器和知识检索,或使用函数调用构建自己的工具。参考 https://platform.openai.com/docs/assistants/tools
    • file_ids: (已弃用)在运行中用于检索的文件。它已弃用,请使用 tool_resources 代替。 https://platform.openai.com/docs/assistants/migration/what-has-changed.
    • tool_resources: 助手工具使用的一组资源。这些资源特定于工具的类型。
  • overwrite_instructions bool - 是否覆盖现有助手的指令。此参数仅在llm_config中指定了assistant_id时生效。
  • overwrite_tools bool - 是否覆盖现有助手的工具。此参数仅在 llm_config 中指定 assistant_id 时生效。
  • kwargs dict - Additional configuration options for the agent.
    • verbose (bool): 如果设置为True,将启用从assistant线程输出的更详细信息。
    • 其他 kwargs: 除了 verbose,其他的都直接传递给 ConversableAgent。

can_execute_function

def can_execute_function(name: str) -> bool

代理是否可以执行该函数。

重置

def reset()

重置代理,清除所有现有的对话线程和未读消息索引。

clear_history

def clear_history(agent: Optional[Agent] = None)

清除代理的聊天历史记录。

参数:

  • agent - 要清除聊天历史的代理。如果为 None,则清除与所有代理的聊天历史。

pretty_print_thread

def pretty_print_thread(thread)

格式化输出线程。

oai_threads

@property
def oai_threads() -> Dict[Agent, Any]

返回代理的线程。

assistant_id

@property
def assistant_id()

返回助手ID

get_assistant_instructions

def get_assistant_instructions()

从OAI助手API返回助手指令

删除助手

def delete_assistant()

从OAI助手API中删除助手

find_matching_assistant

def find_matching_assistant(candidate_assistants, instructions, tools)

从候选助手列表中查找匹配的助手。 过滤掉具有相同名称但不同指令和函数名称的候选助手。