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.com/docs/security。

Parameters
  • llm (BaseLanguageModel) –

  • toolkit (OpenAPIToolkit) –

  • callback_manager (Optional[BaseCallbackManager]) –

  • prefix (str) –

  • suffix (str) –

  • format_instructions (Optional[str]) –

  • input_variables (Optional[List[str]]) –

  • max_iterations (Optional[int]) –

  • max_execution_time (Optional[float]) –

  • early_stopping_method (str) –

  • verbose (bool) –

  • return_intermediate_steps (bool) –

  • agent_executor_kwargs (Optional[Dict[str, Any]]) –

  • kwargs (Any) –

Return type

AgentExecutor

Examples using create_openapi_agent