jamesnetherton commented on code in PR #9132:
URL: https://github.com/apache/camel-quarkus/pull/9132#discussion_r3955657101
##########
extensions/ai-tool/deployment/src/main/java/org/apache/camel/quarkus/component/ai/tool/deployment/AiToolProcessor.java:
##########
@@ -16,15 +16,105 @@
*/
package org.apache.camel.quarkus.component.ai.tool.deployment;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
+import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.annotations.ExecutionTime;
+import io.quarkus.deployment.annotations.Record;
+import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
+import org.apache.camel.quarkus.component.ai.tool.AiToolRecorder;
+import org.apache.camel.quarkus.component.ai.tool.AiToolSpecConverterImpl;
+import org.apache.camel.quarkus.component.ai.tool.CamelAiToolProvider;
+import org.apache.camel.quarkus.component.ai.tool.CamelAiToolsInterceptor;
+import org.jboss.jandex.AnnotationInstance;
+import org.jboss.jandex.AnnotationTarget;
+import org.jboss.jandex.DotName;
+import org.jboss.jandex.IndexView;
+import org.jboss.logging.Logger;
class AiToolProcessor {
private static final String FEATURE = "camel-ai-tool";
+ private static final DotName CAMEL_AI_TOOLS_DOTNAME = DotName
+
.createSimple("org.apache.camel.quarkus.component.ai.tool.CamelAiTools");
+
+ private static final Logger LOG = Logger.getLogger(AiToolProcessor.class);
@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}
+
+ @BuildStep(onlyIf = QuarkusLangchain4jPresent.class)
+ void registerCamelAiToolProvider(
+ CombinedIndexBuildItem combinedIndex,
+ BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
+
+ if (!new AiToolPresent().getAsBoolean()) {
+ Collection<AnnotationInstance> aiToolsAnnotations =
combinedIndex.getIndex()
+ .getAnnotations(CAMEL_AI_TOOLS_DOTNAME);
+ if (!aiToolsAnnotations.isEmpty()) {
+ LOG.warnf("@CamelAiTools annotations found but
camel-langchain4j-agent is not on the classpath. "
+ + "Add camel-langchain4j-agent dependency to enable
the Camel AI tool bridge. "
+ + "Affected classes: %s",
+ aiToolsAnnotations.stream()
+ .filter(a -> a.target().kind() ==
AnnotationTarget.Kind.CLASS)
+ .map(a ->
a.target().asClass().name().toString())
+ .collect(Collectors.joining(", ")));
+ }
+ return;
+ }
+
+ LOG.info("Camel AI Tool detected - registering CamelAiToolProvider as
CDI bean for ToolProvider auto-discovery");
+
additionalBeans.produce(AdditionalBeanBuildItem.unremovableOf(CamelAiToolProvider.class));
+ }
+
+ @BuildStep(onlyIf = { QuarkusLangchain4jPresent.class, AiToolPresent.class
})
+ AdditionalBeanBuildItem registerAiToolSpecConverter() {
+ return
AdditionalBeanBuildItem.unremovableOf(AiToolSpecConverterImpl.class);
+ }
+
+ @BuildStep(onlyIf = { QuarkusLangchain4jPresent.class, AiToolPresent.class
})
+ @Record(ExecutionTime.STATIC_INIT)
+ void configureCamelAiToolTags(
+ CombinedIndexBuildItem combinedIndex,
+ BuildProducer<AdditionalBeanBuildItem> additionalBeans,
+ AiToolRecorder recorder) {
+
+ IndexView index = combinedIndex.getIndex();
+ Map<String, String> tagMap = new HashMap<>();
+ for (AnnotationInstance annotation :
index.getAnnotations(CAMEL_AI_TOOLS_DOTNAME)) {
+ if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) {
+ String className =
annotation.target().asClass().name().toString();
+ if (annotation.value() == null) {
+ LOG.warnf("@CamelAiTools on %s has no value — skipping",
className);
Review Comment:
Good catch — a blank tag left `CURRENT_TAG` unset, so `provideTools()` fell
through to `getAllTools()` and the service received every registered tool,
which is the opposite of what the annotation asks for.
Fixed in 50a5464: it is now a build failure rather than a warning, produced
as a `ValidationErrorBuildItem` with a `ConfigurationException` to match
`validateRagRetrievalFilterSupplier` in the support module:
```
@CamelAiTools on ...AdminAiService has no tag. An empty tag would expose
every registered
Camel AI tool to the service instead of the intended subset. Give it the tag
used by the
ai-tool: routes it should see, or remove the annotation to receive all tools
deliberately.
```
Verified by temporarily setting `@CamelAiTools("")` on a test service —
augmentation fails with that message. `value()` keeps its `""` default because
the interceptor binding declaration on `CamelAiToolsInterceptor` needs it, so
validation is where the check belongs.
*This review was generated by an AI agent and may contain inaccuracies.
Please verify all suggestions before applying.*
*Claude Code on behalf of James Netherton*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]