langchain_community.agent_toolkits.openapi.base.create_openapi_agent

langchain_community.agent_toolkits.openapi.base.create_openapi_agent(llm: BaseLanguageModel, toolkit: OpenAPIToolkit, callback_manager: Optional[BaseCallbackManager] = None, prefix: str = "You are an agent designed to answer questions by making web requests to an API given the openapi spec.\n\nIf the question does not seem related to the API, return I don't know. Do not make up an answer.\nOnly use information provided by the tools to construct your response.\n\nFirst, find the base URL needed to make the request.\n\nSecond, find the relevant paths needed to answer the question. Take note that, sometimes, you might need to make more than one request to more than one path to answer the question.\n\nThird, find the required parameters needed to make the request. For GET requests, these are usually URL parameters and for POST requests, these are request body parameters.\n\nFourth, make the requests needed to answer the question. Ensure that you are sending the correct parameters to the request by checking which parameters are required. For parameters with a fixed set of values, please use the spec to look at which values are allowed.\n\nUse the exact parameter names as listed in the spec, do not make up any names or abbreviate the names of parameters.\nIf you get a not found error, ensure that you are using a path that actually exists in the spec.\n", suffix: str = 'Begin!\n\nQuestion: {input}\nThought: I should explore the spec to find the base server url for the API in the servers node.\n{agent_scratchpad}', format_instructions: Optional[str] = None, input_variables: Optional[List[str]] = None, max_iterations: Optional[int] = 15, max_execution_time: Optional[float] = None, early_stopping_method: str = 'force', verbose: bool = False, return_intermediate_steps: bool = False, agent_executor_kwargs: Optional[Dict[str, Any]] = None, **kwargs: Any) AgentExecutor[source]

从LLM和工具构建OpenAPI代理。

安全提示:在创建OpenAPI代理时,请检查底层工具包的权限

和功能。

例如,如果OpenAPIToolkit的默认实现使用RequestsToolkit,该工具包包含针对任何URL(例如,GET、POST、PATCH、PUT、DELETE)进行任意网络请求的工具,

控制可以提交问题请求的人以及该工具包具有的网络访问权限。

有关更多信息,请参阅 https://python.langchain.ac.cn/docs/security

参数
  • llm (BaseLanguageModel) – 要使用的语言模型。

  • 工具包 (OpenAPIToolkit) – OpenAPI 工具包。

  • 回调管理器 (可选[BaseCallbackManager]) – 可选。回调管理器。默认为 None。

  • 前缀 (字符串) – 可选。提示信息的前缀。默认为 OPENAPI_PREFIX。

  • 后缀 (字符串) – 可选。提示信息的后缀。默认为 OPENAPI_SUFFIX。

  • 格式说明 (可选[字符串]) – 可选。提示信息的格式说明。默认为 None。

  • 输入变量 (可选[字符串列表]) – 可选。提示信息的输入变量。默认为 None。

  • 最大迭代次数 (可选[整数]) – 可选。最大迭代次数。默认是 15。

  • 最大执行时间 (可选[浮点数]) – 可选。最大执行时间。默认为 None。

  • 早期停止方法 (字符串) – 可选。早期停止方法。默认是 “强制”。

  • 详细输出 (布尔值) – 可选。是否打印详细输出。默认是 False。

  • 返回中间步骤 (布尔值) – 可选。是否返回中间步骤。默认是 False。

  • 代理执行器关键字参数 (可选[字典[字符串,任何类型]]) – 可选。代理执行器的额外关键字参数。

  • 关键字参数 (任何类型) – 额外参数。

返回

代理执行器。

返回类型

AgentExecutor

使用 create_openapi_agent 的示例