From 3103f07e03182b43e8beb6aeed2c595dc5b31446 Mon Sep 17 00:00:00 2001 From: William FH <13333726+hinthornw@users.noreply.github.com> Date: Mon, 28 Aug 2023 14:40:22 -0700 Subject: [PATCH] Use existing required args obj if specified (#9883) We always overwrote the required args but we infer them by default. Doing it only the old way makes it so the llm guesses even if an arg is optional (e.g., for uuids) --- libs/langchain/langchain/tools/convert_to_openai.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/langchain/langchain/tools/convert_to_openai.py b/libs/langchain/langchain/tools/convert_to_openai.py index 82c0a47fbbd..e575b024d4b 100644 --- a/libs/langchain/langchain/tools/convert_to_openai.py +++ b/libs/langchain/langchain/tools/convert_to_openai.py @@ -19,7 +19,9 @@ def format_tool_to_openai_function(tool: BaseTool) -> FunctionDescription: if isinstance(tool, StructuredTool): schema_ = tool.args_schema.schema() # Bug with required missing for structured tools. - required = sorted(schema_["properties"]) # BUG WORKAROUND + required = schema_.get( + "required", sorted(schema_["properties"]) # Backup is a BUG WORKAROUND + ) return { "name": tool.name, "description": tool.description,