From 07c5c60f63a3dc5f53f84404a631dd228450a2fd Mon Sep 17 00:00:00 2001 From: Eun Hye Kim Date: Thu, 18 Jul 2024 22:37:46 +0900 Subject: [PATCH] community: fix tool appending logic and update planner prompt in OpenAPI agent toolkit (#24384) **Description:** - Updated the format for the 'Action' section in the planner prompt to ensure it must be one of the tools without additional words. Adjusted the phrasing from "should be" to "must be" for clarity and enforceability. - Corrected the tool appending logic in the `_create_api_controller_agent` function to ensure that `RequestsDeleteToolWithParsing` and `RequestsPatchToolWithParsing` are properly added to the tools list for "DELETE" and "PATCH" operations. **Issue:** #24382 **Dependencies:** None **Twitter handle:** @lunara_x --------- Co-authored-by: Chester Curme --- .../agent_toolkits/openapi/planner.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/libs/community/langchain_community/agent_toolkits/openapi/planner.py b/libs/community/langchain_community/agent_toolkits/openapi/planner.py index 9f801b0ca2d..d793182e365 100644 --- a/libs/community/langchain_community/agent_toolkits/openapi/planner.py +++ b/libs/community/langchain_community/agent_toolkits/openapi/planner.py @@ -292,17 +292,21 @@ def _create_api_controller_agent( ) if "DELETE" in allowed_operations: delete_llm_chain = LLMChain(llm=llm, prompt=PARSING_DELETE_PROMPT) - RequestsDeleteToolWithParsing( # type: ignore[call-arg] - requests_wrapper=requests_wrapper, - llm_chain=delete_llm_chain, - allow_dangerous_requests=allow_dangerous_requests, + tools.append( + RequestsDeleteToolWithParsing( # type: ignore[call-arg] + requests_wrapper=requests_wrapper, + llm_chain=delete_llm_chain, + allow_dangerous_requests=allow_dangerous_requests, + ) ) if "PATCH" in allowed_operations: patch_llm_chain = LLMChain(llm=llm, prompt=PARSING_PATCH_PROMPT) - RequestsPatchToolWithParsing( # type: ignore[call-arg] - requests_wrapper=requests_wrapper, - llm_chain=patch_llm_chain, - allow_dangerous_requests=allow_dangerous_requests, + tools.append( + RequestsPatchToolWithParsing( # type: ignore[call-arg] + requests_wrapper=requests_wrapper, + llm_chain=patch_llm_chain, + allow_dangerous_requests=allow_dangerous_requests, + ) ) if not tools: raise ValueError("Tools not found")