Skip to main content

gpt_assistant_agent

GPTAssistantAgent

class GPTAssistantAgent(ConversableAgent)

GPTAssistantAgent 是一个实验性的 AutoGen agent 类,利用 OpenAI Assistant API 实现对话功能。 该 agent 在状态管理上与 ConversableAgent 等其他 agent 不同,它依赖于 OpenAI Assistant。

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

can_execute_function

def can_execute_function(name: str) -> bool

代理是否能够执行该函数。

reset

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返回助手的指令。

delete_assistant

def delete_assistant()

从OAI助手API中删除助手。

find_matching_assistant

def find_matching_assistant(candidate_assistants, instructions, tools)

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