create_openapi_agent#

langchain_community.agent_toolkits.openapi.base.create_openapi_agent(llm: BaseLanguageModel, toolkit: OpenAPIToolkit, callback_manager: BaseCallbackManager | None = 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: str | None = None, input_variables: List[str] | None = None, max_iterations: int | None = 15, max_execution_time: float | None = None, early_stopping_method: str = 'force', verbose: bool = False, return_intermediate_steps: bool = False, agent_executor_kwargs: Dict[str, Any] | None = None, **kwargs: Any) AgentExecutor[source]#

从LLM和工具构建一个OpenAPI代理。

Security Note: When creating an OpenAPI agent, check the permissions

以及底层工具包的功能。

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

控制谁可以使用此工具包提交问题请求以及它拥有哪些网络访问权限。

查看 https://python.langchain.com/docs/security 获取更多信息。

Parameters:
  • llm (BaseLanguageModel) – 使用的语言模型。

  • toolkit (OpenAPIToolkit) – OpenAPI工具包。

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

  • prefix (str) – 可选。提示的前缀。默认是 OPENAPI_PREFIX。

  • suffix (str) – 可选。提示的后缀。默认是 OPENAPI_SUFFIX。

  • format_instructions (Optional[str]) – 可选。提示的格式说明。 默认值为 None。

  • input_variables (Optional[List[str]]) – 可选。提示的输入变量。默认为 None。

  • max_iterations (Optional[int]) – 可选。最大迭代次数。默认值为15。

  • max_execution_time (可选[float]) – 可选。最大执行时间。默认为 None。

  • early_stopping_method (str) – 可选。早停方法。默认为“force”。

  • verbose (bool) – 可选。是否打印详细输出。默认为 False。

  • return_intermediate_steps (bool) – 可选。是否返回中间步骤。默认值为 False。

  • agent_executor_kwargs (Optional[Dict[str, Any]]) – 可选的。用于代理执行器的额外关键字参数。

  • kwargs (Any) – 额外的参数。

Returns:

代理执行器。

Return type:

AgentExecutor

使用 create_openapi_agent 的示例