This is an automated email from the ASF dual-hosted git repository.

JiriOndrusek pushed a commit to branch 3.40.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 0481ad2ed4e1279b31214f9e380d87da33531ada
Author: Jiří Ondrušek <[email protected]>
AuthorDate: Wed Nov 25 09:11:49 2026 +0100

    Fixes #9552. ai-tool: warn when @CamelAiTools is not on a 
@RegisterAiService interface
    
    Since the interceptor was removed, @CamelAiTools only works on
    @RegisterAiService interfaces. On any other class it was silently ignored;
    the build now logs a warning.
    
    Co-authored-by: jiriOndrusek-agent <[email protected]>
    Co-authored-by: Claude Opus 5.5 <[email protected]>
    (cherry picked from commit 2e19ad3412377db98a0fb19a45faff4b3aecd2e7)
---
 .../ROOT/pages/reference/extensions/ai-tool.adoc   |  1 +
 .../ai/tool/deployment/AiToolProcessor.java        |  9 +++
 .../deployment/CamelAiToolsNotAiServiceTest.java   | 60 +++++++++++++++++
 .../deployment/CamelAiToolsOnAiServiceTest.java    | 75 ++++++++++++++++++++++
 extensions/ai-tool/runtime/src/main/doc/usage.adoc |  1 +
 5 files changed, 146 insertions(+)

diff --git a/docs/modules/ROOT/pages/reference/extensions/ai-tool.adoc 
b/docs/modules/ROOT/pages/reference/extensions/ai-tool.adoc
index 4c6394b5897..123754cc174 100644
--- a/docs/modules/ROOT/pages/reference/extensions/ai-tool.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/ai-tool.adoc
@@ -128,6 +128,7 @@ the 
`org.apache.camel.quarkus.component.ai.tool.CamelAiTools` annotation.
 
 * It takes a single tag. A comma-separated list is not split.
 * A blank tag fails the build (when Quarkus LangChain4j and 
`camel-langchain4j-agent` are present).
+* It only applies to `@RegisterAiService` interfaces. On any other class (such 
as a CDI bean calling the service) it has no effect and the build logs a 
warning.
 * It has no effect on Camel agents (`langchain4j-agent` endpoints), which 
receive no tools from this bridge.
 
 [source,java]
diff --git 
a/extensions/ai-tool/deployment/src/main/java/org/apache/camel/quarkus/component/ai/tool/deployment/AiToolProcessor.java
 
b/extensions/ai-tool/deployment/src/main/java/org/apache/camel/quarkus/component/ai/tool/deployment/AiToolProcessor.java
index 0a1be3231d9..085594ccda4 100644
--- 
a/extensions/ai-tool/deployment/src/main/java/org/apache/camel/quarkus/component/ai/tool/deployment/AiToolProcessor.java
+++ 
b/extensions/ai-tool/deployment/src/main/java/org/apache/camel/quarkus/component/ai/tool/deployment/AiToolProcessor.java
@@ -35,6 +35,7 @@ import 
org.apache.camel.quarkus.component.ai.tool.AiToolSpecConverterImpl;
 import org.apache.camel.quarkus.component.ai.tool.CamelAiToolProvider;
 import org.jboss.jandex.AnnotationInstance;
 import org.jboss.jandex.AnnotationTarget;
+import org.jboss.jandex.ClassInfo;
 import org.jboss.jandex.DotName;
 import org.jboss.jandex.IndexView;
 import org.jboss.logging.Logger;
@@ -44,6 +45,8 @@ 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 DotName REGISTER_AI_SERVICE_DOTNAME = DotName
+            .createSimple("io.quarkiverse.langchain4j.RegisterAiService");
 
     private static final Logger LOG = Logger.getLogger(AiToolProcessor.class);
 
@@ -96,6 +99,12 @@ class AiToolProcessor {
                                 + "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.")));
+                continue;
+            }
+            ClassInfo target = annotation.target().asClass();
+            if (!target.isInterface() || 
!target.hasDeclaredAnnotation(REGISTER_AI_SERVICE_DOTNAME)) {
+                LOG.warnf("@CamelAiTools on %s has no effect: it only applies 
to @RegisterAiService interfaces. "
+                        + "Move it to the AI service interface.", 
target.name());
             }
         }
     }
diff --git 
a/extensions/ai-tool/deployment/src/test/java/org/apache/camel/quarkus/component/ai/tool/deployment/CamelAiToolsNotAiServiceTest.java
 
b/extensions/ai-tool/deployment/src/test/java/org/apache/camel/quarkus/component/ai/tool/deployment/CamelAiToolsNotAiServiceTest.java
new file mode 100644
index 00000000000..dcdf8a0dc84
--- /dev/null
+++ 
b/extensions/ai-tool/deployment/src/test/java/org/apache/camel/quarkus/component/ai/tool/deployment/CamelAiToolsNotAiServiceTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.ai.tool.deployment;
+
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+import io.quarkus.test.QuarkusExtensionTest;
+import jakarta.enterprise.context.ApplicationScoped;
+import org.apache.camel.quarkus.component.ai.tool.CamelAiTools;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * {@code @CamelAiTools} on a class that is not a {@code @RegisterAiService} 
interface has no effect, so the build
+ * warns.
+ */
+class CamelAiToolsNotAiServiceTest {
+
+    @RegisterExtension
+    static final QuarkusExtensionTest TEST = new QuarkusExtensionTest()
+            .withApplicationRoot(jar -> jar.addClasses(SupportFacade.class, 
OptionalDependencies.class))
+            .setForcedDependencies(
+                    List.of(OptionalDependencies.QUARKUS_LANGCHAIN4J, 
OptionalDependencies.CAMEL_LANGCHAIN4J_AGENT))
+            .setLogRecordPredicate(r -> r.getLevel().equals(Level.WARNING)
+                    && r.getMessage().contains("only applies to 
@RegisterAiService interfaces"))
+            .assertLogRecords(records -> 
assertEquals(List.of(SupportFacade.class.getName()),
+                    
records.stream().map(CamelAiToolsNotAiServiceTest::annotatedClass).toList()));
+
+    @Test
+    void warnsForPlainBean() {
+        // Asserted by assertLogRecords above
+    }
+
+    private static String annotatedClass(LogRecord record) {
+        return String.valueOf(record.getParameters()[0]);
+    }
+
+    @ApplicationScoped
+    @CamelAiTools("support")
+    public static class SupportFacade {
+    }
+}
diff --git 
a/extensions/ai-tool/deployment/src/test/java/org/apache/camel/quarkus/component/ai/tool/deployment/CamelAiToolsOnAiServiceTest.java
 
b/extensions/ai-tool/deployment/src/test/java/org/apache/camel/quarkus/component/ai/tool/deployment/CamelAiToolsOnAiServiceTest.java
new file mode 100644
index 00000000000..a45ec738983
--- /dev/null
+++ 
b/extensions/ai-tool/deployment/src/test/java/org/apache/camel/quarkus/component/ai/tool/deployment/CamelAiToolsOnAiServiceTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.ai.tool.deployment;
+
+import java.util.List;
+import java.util.logging.Level;
+
+import io.quarkus.test.QuarkusExtensionTest;
+import org.apache.camel.quarkus.component.ai.tool.CamelAiTools;
+import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * {@code @CamelAiTools} on a {@code @RegisterAiService} interface must not 
warn; on a plain interface it must.
+ * The AI service interface is generated with ASM because {@code 
@RegisterAiService} is only added at test runtime
+ * (forced dependency), not at compile time.
+ */
+class CamelAiToolsOnAiServiceTest {
+
+    private static final String AI_SERVICE = 
CamelAiToolsOnAiServiceTest.class.getPackageName() + ".GeneratedAiService";
+
+    @RegisterExtension
+    static final QuarkusExtensionTest TEST = new QuarkusExtensionTest()
+            .withApplicationRoot(jar -> jar.addClasses(PlainService.class, 
OptionalDependencies.class)
+                    .add(new ByteArrayAsset(aiServiceInterface()), 
AI_SERVICE.replace('.', '/') + ".class"))
+            .setForcedDependencies(
+                    List.of(OptionalDependencies.QUARKUS_LANGCHAIN4J, 
OptionalDependencies.CAMEL_LANGCHAIN4J_AGENT))
+            .setLogRecordPredicate(r -> r.getLevel().equals(Level.WARNING)
+                    && r.getMessage().contains("only applies to 
@RegisterAiService interfaces"))
+            .assertLogRecords(records -> 
assertEquals(List.of(PlainService.class.getName()),
+                    records.stream().map(r -> 
String.valueOf(r.getParameters()[0])).toList()));
+
+    @Test
+    void warnsOnlyForPlainInterface() {
+        // Asserted by assertLogRecords above
+    }
+
+    /** {@code @RegisterAiService @CamelAiTools("x") public interface 
GeneratedAiService {}} */
+    private static byte[] aiServiceInterface() {
+        ClassWriter cw = new ClassWriter(0);
+        cw.visit(Opcodes.V17, Opcodes.ACC_PUBLIC | Opcodes.ACC_INTERFACE | 
Opcodes.ACC_ABSTRACT,
+                AI_SERVICE.replace('.', '/'), null, "java/lang/Object", null);
+        cw.visitAnnotation("Lio/quarkiverse/langchain4j/RegisterAiService;", 
true).visitEnd();
+        AnnotationVisitor tools = 
cw.visitAnnotation(Type.getDescriptor(CamelAiTools.class), true);
+        tools.visit("value", "x");
+        tools.visitEnd();
+        cw.visitEnd();
+        return cw.toByteArray();
+    }
+
+    @CamelAiTools("x")
+    public interface PlainService {
+    }
+}
diff --git a/extensions/ai-tool/runtime/src/main/doc/usage.adoc 
b/extensions/ai-tool/runtime/src/main/doc/usage.adoc
index da837c2346d..e2be779e2cc 100644
--- a/extensions/ai-tool/runtime/src/main/doc/usage.adoc
+++ b/extensions/ai-tool/runtime/src/main/doc/usage.adoc
@@ -75,6 +75,7 @@ the `org.apache.camel.quarkus.component.ai.tool.CamelAiTools` 
annotation.
 
 * It takes a single tag. A comma-separated list is not split.
 * A blank tag fails the build (when Quarkus LangChain4j and 
`camel-langchain4j-agent` are present).
+* It only applies to `@RegisterAiService` interfaces. On any other class (such 
as a CDI bean calling the service) it has no effect and the build logs a 
warning.
 * It has no effect on Camel agents (`langchain4j-agent` endpoints), which 
receive no tools from this bridge.
 
 [source,java]

Reply via email to