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]#
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) β The language model to use.
toolkit (OpenAPIToolkit) β The OpenAPI toolkit.
callback_manager (Optional[BaseCallbackManager]) β Optional. The callback manager. Default is None.
prefix (str) β Optional. The prefix for the prompt. Default is OPENAPI_PREFIX.
suffix (str) β Optional. The suffix for the prompt. Default is OPENAPI_SUFFIX.
format_instructions (Optional[str]) β Optional. The format instructions for the prompt. Default is None.
input_variables (Optional[List[str]]) β Optional. The input variables for the prompt. Default is None.
max_iterations (Optional[int]) β Optional. The maximum number of iterations. Default is 15.
max_execution_time (Optional[float]) β Optional. The maximum execution time. Default is None.
early_stopping_method (str) β Optional. The early stopping method. Default is βforceβ.
verbose (bool) β Optional. Whether to print verbose output. Default is False.
return_intermediate_steps (bool) β Optional. Whether to return intermediate steps. Default is False.
agent_executor_kwargs (Optional[Dict[str, Any]]) β Optional. Additional keyword arguments for the agent executor.
kwargs (Any) β Additional arguments.
- Returns:
The agent executor.
- Return type:
Examples using create_openapi_agent