Toggle Menu
Prev Up Next

# `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

  Construct an OpenAPI agent from an LLM and tools.

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

    and capabilities of the underlying toolkit.

    For example, if the default implementation of OpenAPIToolkit uses the RequestsToolkit which contains tools to make arbitrary network requests against any URL (e.g., GET, POST, PATCH, PUT, DELETE),

    Control access to who can submit issue requests using this toolkit and what network access it has.

    See https://python.langchain.com/docs/security for more information.

  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

- NOTE: In this example. We must set `allow_dangerous_request=True` to enable the OpenAPI Agent to automatically use the Request Tool.