From ef7347763f381554866b397830a4783306f3fc5e Mon Sep 17 00:00:00 2001 From: Jan Pohlmeyer Date: Thu, 5 Sep 2024 14:53:06 +0200 Subject: [PATCH] Evaluate 'required' attribute of @P annotation in tool. --- .../langchain4j/deployment/ToolProcessor.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/ToolProcessor.java b/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/ToolProcessor.java index 478448e8f..eb67c7dd1 100644 --- a/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/ToolProcessor.java +++ b/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/ToolProcessor.java @@ -203,7 +203,14 @@ public void handleTools(CombinedIndexBuildItem indexBuildItem, memoryIdParameter = parameter; continue; } - builder.addParameter(parameter.name(), toJsonSchemaProperties(parameter, index)); + + AnnotationInstance pInstance = parameter.annotation(P); + if (pInstance != null && pInstance.value("required") != null + && !pInstance.value("required").asBoolean()) { + builder.addOptionalParameter(parameter.name(), toJsonSchemaProperties(parameter, index)); + } else { + builder.addParameter(parameter.name(), toJsonSchemaProperties(parameter, index)); + } } Map nameToParamPosition = toolMethod.parameters().stream().collect(