diff --git a/catalog/pom.xml b/catalog/pom.xml index 7b654d212c3..4da6127a695 100644 --- a/catalog/pom.xml +++ b/catalog/pom.xml @@ -123,6 +123,19 @@ + + org.apache.camel.quarkus + camel-quarkus-ai-tool + ${project.version} + pom + test + + + * + * + + + org.apache.camel.quarkus camel-quarkus-amqp diff --git a/docs/modules/ROOT/examples/components/ai-tool.yml b/docs/modules/ROOT/examples/components/ai-tool.yml new file mode 100644 index 00000000000..a9bf4c3f9bd --- /dev/null +++ b/docs/modules/ROOT/examples/components/ai-tool.yml @@ -0,0 +1,13 @@ +# Do not edit directly! +# This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +cqArtifactId: camel-quarkus-ai-tool +cqArtifactIdBase: ai-tool +cqNativeSupported: true +cqStatus: Stable +cqDeprecated: false +cqJvmSince: 3.39.0 +cqNativeSince: 3.39.0 +cqCamelPartName: ai-tool +cqCamelPartTitle: AI Tool +cqCamelPartDescription: Framework-agnostic consumer endpoint that registers a Camel route as an LLM tool in the shared AiToolRegistry. +cqExtensionPageTitle: AI Tool diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index db466c825dd..d0cd2289b1a 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -31,6 +31,7 @@ ** xref:reference/index.adoc[Extensions] // extensions: START *** xref:reference/extensions/a2a.adoc[A2A] +*** xref:reference/extensions/ai-tool.adoc[AI Tool] *** xref:reference/extensions/amqp.adoc[AMQP] *** xref:reference/extensions/as2.adoc[AS2] *** xref:reference/extensions/asn1.adoc[ASN.1 File] diff --git a/docs/modules/ROOT/pages/reference/extensions/ai-tool.adoc b/docs/modules/ROOT/pages/reference/extensions/ai-tool.adoc new file mode 100644 index 00000000000..16920abb9a4 --- /dev/null +++ b/docs/modules/ROOT/pages/reference/extensions/ai-tool.adoc @@ -0,0 +1,94 @@ +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +[id="extensions-ai-tool"] += AI Tool +:linkattrs: +:cq-artifact-id: camel-quarkus-ai-tool +:cq-native-supported: true +:cq-status: Stable +:cq-status-deprecation: Stable +:cq-description: Framework-agnostic consumer endpoint that registers a Camel route as an LLM tool in the shared AiToolRegistry. +:cq-deprecated: false +:cq-jvm-since: 3.39.0 +:cq-native-since: 3.39.0 + +ifeval::[{doc-show-badges} == true] +[.badges] +[.badge-key]##JVM since##[.badge-supported]##3.39.0## [.badge-key]##Native since##[.badge-supported]##3.39.0## +endif::[] + +Framework-agnostic consumer endpoint that registers a Camel route as an LLM tool in the shared AiToolRegistry. + +[id="extensions-ai-tool-whats-inside"] +== What's inside + +* xref:{cq-camel-components}::ai-tool-component.adoc[AI Tool component], URI syntax: `ai-tool:toolName` + +Please refer to the above link for usage and configuration details. + +[id="extensions-ai-tool-maven-coordinates"] +== Maven coordinates + +https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-ai-tool[Create a new project with this extension on {link-quarkus-code-generator}, window="_blank"] + +Or add the coordinates to your existing project: + +[source,xml] +---- + + org.apache.camel.quarkus + camel-quarkus-ai-tool + +---- +ifeval::[{doc-show-user-guide-link} == true] +Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. +endif::[] + +[id="extensions-ai-tool-usage"] +== Usage +The `ai-tool` component is a framework-agnostic consumer endpoint that registers Camel routes as LLM-callable tools in a shared `AiToolRegistry`. Framework-specific extensions (such as `camel-quarkus-langchain4j-tools`, `camel-quarkus-openai`) discover and invoke these tools at runtime. + +[id="extensions-ai-tool-usage-defining-a-tool"] +=== Defining a tool + +Use the `ai-tool` consumer endpoint to register a route as an AI tool. Tool parameters are declared via URI options. + +[source,java] +---- +public class MyRoutes extends RouteBuilder { + @Override + public void configure() { + from("ai-tool:getWeather?tags=weather" + + "&description=Get the current weather for a city" + + "¶meter.city=string" + + "¶meter.city.description=The city name" + + "¶meter.city.required=true" + + "¶meter.unit=string" + + "¶meter.unit.enum=celsius,fahrenheit") + .setBody(simple("Sunny in ${header.city}, temperature in ${header.unit}")); + } +} +---- + +Arguments passed by the LLM are set as exchange headers (e.g. `${header.city}`). + +[id="extensions-ai-tool-usage-tag-based-grouping"] +=== Tag-based grouping + +Tools can be grouped by tags. AI producer endpoints use tags to discover a subset of available tools. + +A tool with no tags is placed in a default pool and is available to all tag queries. + +[source,java] +---- +// Tagged tool — only visible to producers querying the "support" tag +from("ai-tool:lookupOrder?tags=support&description=Look up order status" + + "¶meter.orderId=string¶meter.orderId.required=true") + .to("sql:SELECT status FROM orders WHERE id = :#${header.orderId}"); + +// Untagged tool — available to all producers +from("ai-tool:greet?description=Greet a user" + + "¶meter.name=string¶meter.name.required=true") + .setBody(simple("Hello, ${header.name}!")); +---- + diff --git a/extensions/ai-tool/deployment/pom.xml b/extensions/ai-tool/deployment/pom.xml new file mode 100644 index 00000000000..23a1f28a7b5 --- /dev/null +++ b/extensions/ai-tool/deployment/pom.xml @@ -0,0 +1,63 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-ai-tool-parent + 3.39.0-SNAPSHOT + ../pom.xml + + + camel-quarkus-ai-tool-deployment + Camel Quarkus :: AI Tool :: Deployment + + + + org.apache.camel.quarkus + camel-quarkus-core-deployment + + + org.apache.camel.quarkus + camel-quarkus-ai-tool + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${quarkus.version} + + + + + + + + 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 new file mode 100644 index 00000000000..e132611dd12 --- /dev/null +++ b/extensions/ai-tool/deployment/src/main/java/org/apache/camel/quarkus/component/ai/tool/deployment/AiToolProcessor.java @@ -0,0 +1,30 @@ +/* + * 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 io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.FeatureBuildItem; + +class AiToolProcessor { + + private static final String FEATURE = "camel-ai-tool"; + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); + } +} diff --git a/extensions/ai-tool/pom.xml b/extensions/ai-tool/pom.xml new file mode 100644 index 00000000000..57200130597 --- /dev/null +++ b/extensions/ai-tool/pom.xml @@ -0,0 +1,39 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-extensions + 3.39.0-SNAPSHOT + ../pom.xml + + + camel-quarkus-ai-tool-parent + Camel Quarkus :: AI Tool + pom + + + deployment + runtime + + diff --git a/extensions/ai-tool/runtime/pom.xml b/extensions/ai-tool/runtime/pom.xml new file mode 100644 index 00000000000..2a706452fd8 --- /dev/null +++ b/extensions/ai-tool/runtime/pom.xml @@ -0,0 +1,101 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-ai-tool-parent + 3.39.0-SNAPSHOT + ../pom.xml + + + camel-quarkus-ai-tool + Camel Quarkus :: AI Tool :: Runtime + Framework-agnostic consumer endpoint that registers a Camel route as an LLM tool in the shared AiToolRegistry. + + + 3.39.0 + 3.39.0 + + + + + org.apache.camel.quarkus + camel-quarkus-core + + + org.apache.camel + camel-ai-tool + + + + + + + io.quarkus + quarkus-extension-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${quarkus.version} + + + + + + + + + + + full + + + !quickly + + + + + + org.apache.camel.quarkus + camel-quarkus-maven-plugin + + + update-extension-doc-page + + update-extension-doc-page + + process-classes + + + + + + + + diff --git a/extensions/ai-tool/runtime/src/main/doc/usage.adoc b/extensions/ai-tool/runtime/src/main/doc/usage.adoc new file mode 100644 index 00000000000..677f114f7cb --- /dev/null +++ b/extensions/ai-tool/runtime/src/main/doc/usage.adoc @@ -0,0 +1,43 @@ +The `ai-tool` component is a framework-agnostic consumer endpoint that registers Camel routes as LLM-callable tools in a shared `AiToolRegistry`. Framework-specific extensions (such as `camel-quarkus-langchain4j-tools`, `camel-quarkus-openai`) discover and invoke these tools at runtime. + +=== Defining a tool + +Use the `ai-tool` consumer endpoint to register a route as an AI tool. Tool parameters are declared via URI options. + +[source,java] +---- +public class MyRoutes extends RouteBuilder { + @Override + public void configure() { + from("ai-tool:getWeather?tags=weather" + + "&description=Get the current weather for a city" + + "¶meter.city=string" + + "¶meter.city.description=The city name" + + "¶meter.city.required=true" + + "¶meter.unit=string" + + "¶meter.unit.enum=celsius,fahrenheit") + .setBody(simple("Sunny in ${header.city}, temperature in ${header.unit}")); + } +} +---- + +Arguments passed by the LLM are set as exchange headers (e.g. `${header.city}`). + +=== Tag-based grouping + +Tools can be grouped by tags. AI producer endpoints use tags to discover a subset of available tools. + +A tool with no tags is placed in a default pool and is available to all tag queries. + +[source,java] +---- +// Tagged tool — only visible to producers querying the "support" tag +from("ai-tool:lookupOrder?tags=support&description=Look up order status" + + "¶meter.orderId=string¶meter.orderId.required=true") + .to("sql:SELECT status FROM orders WHERE id = :#${header.orderId}"); + +// Untagged tool — available to all producers +from("ai-tool:greet?description=Greet a user" + + "¶meter.name=string¶meter.name.required=true") + .setBody(simple("Hello, ${header.name}!")); +---- diff --git a/extensions/ai-tool/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/ai-tool/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 00000000000..34ffbf6adda --- /dev/null +++ b/extensions/ai-tool/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,36 @@ +# +# 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. +# + +# This is a generated file. Do not edit directly! +# To re-generate, run the following command from the top level directory: +# +# mvn -N cq:update-quarkus-metadata +# +--- +name: "Camel AI Tool" +description: "Framework-agnostic consumer endpoint that registers a Camel route as an LLM tool in the shared AiToolRegistry" +metadata: + icon-url: "https://raw.githubusercontent.com/apache/camel-website/main/antora-ui-camel/src/img/logo-d.svg" + sponsor: "Apache Software Foundation" + guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/ai-tool.html" + categories: + - "integration" + status: "stable" + integrates: + - name: "Camel" + artifact: "org.apache.camel:camel-base" + version: "${camel.version}" \ No newline at end of file diff --git a/extensions/pom.xml b/extensions/pom.xml index 0445b0e37d1..bfb301db5eb 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -37,6 +37,7 @@ a2a activemq activemq6 + ai-tool amqp arangodb as2 diff --git a/integration-tests/ai-tool/pom.xml b/integration-tests/ai-tool/pom.xml new file mode 100644 index 00000000000..532b7596380 --- /dev/null +++ b/integration-tests/ai-tool/pom.xml @@ -0,0 +1,112 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-build-parent-it + 3.39.0-SNAPSHOT + ../../poms/build-parent-it/pom.xml + + + camel-quarkus-integration-test-ai-tool + Camel Quarkus :: Integration Tests :: AI Tool + Integration tests for Camel Quarkus AI Tool extension + + + + org.apache.camel.quarkus + camel-quarkus-ai-tool + + + io.quarkus + quarkus-resteasy + + + + + io.quarkus + quarkus-junit + test + + + io.rest-assured + rest-assured + test + + + + + + native + + + native + + + + true + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + + + + virtualDependencies + + + !noVirtualDependencies + + + + + + org.apache.camel.quarkus + camel-quarkus-ai-tool-deployment + ${project.version} + pom + test + + + * + * + + + + + + + + diff --git a/integration-tests/ai-tool/src/main/java/org/apache/camel/quarkus/component/ai/tool/it/AiToolResource.java b/integration-tests/ai-tool/src/main/java/org/apache/camel/quarkus/component/ai/tool/it/AiToolResource.java new file mode 100644 index 00000000000..d1a8c895f42 --- /dev/null +++ b/integration-tests/ai-tool/src/main/java/org/apache/camel/quarkus/component/ai/tool/it/AiToolResource.java @@ -0,0 +1,137 @@ +/* + * 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.it; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; +import org.apache.camel.CamelContext; +import org.apache.camel.Exchange; +import org.apache.camel.component.ai.tool.AiToolExecutor; +import org.apache.camel.component.ai.tool.AiToolRegistry; +import org.apache.camel.component.ai.tool.AiToolResult; +import org.apache.camel.component.ai.tool.AiToolSpec; +import org.apache.camel.support.DefaultExchange; + +@Path("/ai-tool") +@ApplicationScoped +public class AiToolResource { + + @Inject + CamelContext camelContext; + + @Path("/tools/tag/{tag}") + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getToolsByTag(@PathParam("tag") String tag) { + AiToolRegistry registry = AiToolRegistry.getOrCreate(camelContext); + Set tools = registry.getToolsByTag(tag); + return tools.stream() + .map(AiToolSpec::getName) + .sorted() + .collect(Collectors.joining(",")); + } + + @Path("/tools/all") + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getAllTools() { + AiToolRegistry registry = AiToolRegistry.getOrCreate(camelContext); + Set tools = registry.getAllTools(); + return tools.stream() + .map(AiToolSpec::getName) + .sorted() + .collect(Collectors.joining(",")); + } + + @Path("/tools/{toolName}/description") + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getToolDescription(@PathParam("toolName") String toolName) { + AiToolSpec spec = findTool(toolName); + if (spec == null) { + return "NOT_FOUND"; + } + return spec.getDescription(); + } + + @Path("/tools/{toolName}/schema") + @GET + @Produces(MediaType.APPLICATION_JSON) + public String getToolSchema(@PathParam("toolName") String toolName) { + AiToolSpec spec = findTool(toolName); + if (spec == null) { + return "{}"; + } + return spec.getParametersJsonSchema(); + } + + @Path("/execute/{toolName}") + @POST + @Produces(MediaType.TEXT_PLAIN) + public Response executeTool( + @PathParam("toolName") String toolName, + @QueryParam("param") java.util.List params) { + + AiToolSpec spec = findTool(toolName); + if (spec == null) { + return Response.status(404).entity("Tool not found: " + toolName).build(); + } + + Map arguments = new HashMap<>(); + if (params != null) { + for (String param : params) { + String[] parts = param.split("=", 2); + if (parts.length == 2) { + arguments.put(parts[0], parts[1]); + } + } + } + + Exchange exchange = new DefaultExchange(camelContext); + AiToolResult result = AiToolExecutor.execute(spec, arguments, exchange); + + if (result instanceof AiToolResult.Success s) { + return Response.ok(s.value()).build(); + } else if (result instanceof AiToolResult.ArgumentError e) { + return Response.status(400).entity(e.message()).build(); + } else if (result instanceof AiToolResult.ExecutionError e) { + return Response.status(500).entity(e.message()).build(); + } + return Response.status(500).entity("Unknown result type").build(); + } + + private AiToolSpec findTool(String toolName) { + AiToolRegistry registry = AiToolRegistry.getOrCreate(camelContext); + return registry.getAllTools().stream() + .filter(s -> s.getName().equals(toolName)) + .findFirst() + .orElse(null); + } +} diff --git a/integration-tests/ai-tool/src/main/java/org/apache/camel/quarkus/component/ai/tool/it/AiToolRoutes.java b/integration-tests/ai-tool/src/main/java/org/apache/camel/quarkus/component/ai/tool/it/AiToolRoutes.java new file mode 100644 index 00000000000..8ea55e49784 --- /dev/null +++ b/integration-tests/ai-tool/src/main/java/org/apache/camel/quarkus/component/ai/tool/it/AiToolRoutes.java @@ -0,0 +1,74 @@ +/* + * 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.it; + +import org.apache.camel.builder.RouteBuilder; + +public class AiToolRoutes extends RouteBuilder { + @Override + public void configure() { + from("ai-tool:getWeather?tags=weather" + + "&description=Get the current weather for a city" + + "¶meter.city=string" + + "¶meter.city.description=The city name" + + "¶meter.city.required=true" + + "¶meter.unit=string" + + "¶meter.unit.enum=celsius,fahrenheit") + .setBody(simple("Weather in ${header.city}: sunny, 25 ${header.unit}")); + + from("ai-tool:calculate?tags=math" + + "&description=Perform a calculation" + + "¶meter.a=integer" + + "¶meter.a.required=true" + + "¶meter.b=integer" + + "¶meter.b.required=true" + + "¶meter.operation=string" + + "¶meter.operation.required=true" + + "¶meter.operation.enum=add,subtract,multiply") + .choice() + .when(simple("${header.operation} == 'add'")) + .process(e -> { + int a = e.getMessage().getHeader("a", Integer.class); + int b = e.getMessage().getHeader("b", Integer.class); + e.getMessage().setBody(String.valueOf(a + b)); + }) + .when(simple("${header.operation} == 'subtract'")) + .process(e -> { + int a = e.getMessage().getHeader("a", Integer.class); + int b = e.getMessage().getHeader("b", Integer.class); + e.getMessage().setBody(String.valueOf(a - b)); + }) + .when(simple("${header.operation} == 'multiply'")) + .process(e -> { + int a = e.getMessage().getHeader("a", Integer.class); + int b = e.getMessage().getHeader("b", Integer.class); + e.getMessage().setBody(String.valueOf(a * b)); + }) + .otherwise() + .setBody(constant("Unknown operation")); + + from("ai-tool:greet?" + + "description=Greet a user by name" + + "¶meter.name=string" + + "¶meter.name.required=true") + .setBody(simple("Hello, ${header.name}!")); + + from("ai-tool:failingTool?tags=test" + + "&description=A tool that always fails") + .throwException(new IllegalStateException("Intentional failure")); + } +} diff --git a/integration-tests/ai-tool/src/test/java/org/apache/camel/quarkus/component/ai/tool/it/AiToolIT.java b/integration-tests/ai-tool/src/test/java/org/apache/camel/quarkus/component/ai/tool/it/AiToolIT.java new file mode 100644 index 00000000000..4cd2d387395 --- /dev/null +++ b/integration-tests/ai-tool/src/test/java/org/apache/camel/quarkus/component/ai/tool/it/AiToolIT.java @@ -0,0 +1,24 @@ +/* + * 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.it; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class AiToolIT extends AiToolTest { + +} diff --git a/integration-tests/ai-tool/src/test/java/org/apache/camel/quarkus/component/ai/tool/it/AiToolTest.java b/integration-tests/ai-tool/src/test/java/org/apache/camel/quarkus/component/ai/tool/it/AiToolTest.java new file mode 100644 index 00000000000..f1e5e411df1 --- /dev/null +++ b/integration-tests/ai-tool/src/test/java/org/apache/camel/quarkus/component/ai/tool/it/AiToolTest.java @@ -0,0 +1,159 @@ +/* + * 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.it; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@QuarkusTest +class AiToolTest { + + @Test + void toolRegistrationByTag() { + RestAssured.get("/ai-tool/tools/tag/weather") + .then() + .statusCode(200) + .body(containsString("getWeather")); + + RestAssured.get("/ai-tool/tools/tag/math") + .then() + .statusCode(200) + .body(containsString("calculate")); + } + + @Test + void taglessToolInDefaultPool() { + RestAssured.get("/ai-tool/tools/all") + .then() + .statusCode(200) + .body(containsString("greet")); + } + + @Test + void defaultPoolMergedWithTaggedTools() { + RestAssured.get("/ai-tool/tools/tag/weather") + .then() + .statusCode(200) + .body(containsString("greet")); + } + + @Test + void allToolsReturnsEveryRegisteredTool() { + String tools = RestAssured.get("/ai-tool/tools/all") + .then() + .statusCode(200) + .extract().asString(); + + assertTrue(tools.contains("getWeather"), "Expected getWeather in: " + tools); + assertTrue(tools.contains("calculate"), "Expected calculate in: " + tools); + assertTrue(tools.contains("greet"), "Expected greet in: " + tools); + assertTrue(tools.contains("failingTool"), "Expected failingTool in: " + tools); + } + + @Test + void toolDescription() { + RestAssured.get("/ai-tool/tools/getWeather/description") + .then() + .statusCode(200) + .body(is("Get the current weather for a city")); + } + + @Test + void toolSchema() { + String schema = RestAssured.get("/ai-tool/tools/getWeather/schema") + .then() + .statusCode(200) + .extract().asString(); + + assertTrue(schema.contains("\"city\""), "Expected city in schema: " + schema); + assertTrue(schema.contains("\"unit\""), "Expected unit in schema: " + schema); + assertTrue(schema.contains("\"string\""), "Expected string type in schema: " + schema); + } + + @Test + void executeWeatherTool() { + RestAssured.given() + .queryParam("param", "city=Prague") + .queryParam("param", "unit=celsius") + .post("/ai-tool/execute/getWeather") + .then() + .statusCode(200) + .body(containsString("Prague")) + .body(containsString("celsius")); + } + + @Test + void executeCalculateTool() { + RestAssured.given() + .queryParam("param", "a=10") + .queryParam("param", "b=3") + .queryParam("param", "operation=add") + .post("/ai-tool/execute/calculate") + .then() + .statusCode(200) + .body(is("13")); + + RestAssured.given() + .queryParam("param", "a=10") + .queryParam("param", "b=3") + .queryParam("param", "operation=multiply") + .post("/ai-tool/execute/calculate") + .then() + .statusCode(200) + .body(is("30")); + } + + @Test + void executeGreetTool() { + RestAssured.given() + .queryParam("param", "name=Alice") + .post("/ai-tool/execute/greet") + .then() + .statusCode(200) + .body(is("Hello, Alice!")); + } + + @Test + void executeMissingRequiredParam() { + RestAssured.given() + .post("/ai-tool/execute/getWeather") + .then() + .statusCode(400) + .body(containsString("city")); + } + + @Test + void executeFailingTool() { + RestAssured.given() + .post("/ai-tool/execute/failingTool") + .then() + .statusCode(500); + } + + @Test + void executeNonExistentTool() { + RestAssured.given() + .post("/ai-tool/execute/nonExistent") + .then() + .statusCode(404); + } +} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index b29781f585d..8ffee5a4dd6 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -51,6 +51,7 @@ a2a activemq activemq6 + ai-tool amqp arangodb as2 diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index bfd0533954b..ef15e3593ed 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -3545,6 +3545,16 @@ camel-quarkus-activemq6-deployment ${camel-quarkus.version} + + org.apache.camel.quarkus + camel-quarkus-ai-tool + ${camel-quarkus.version} + + + org.apache.camel.quarkus + camel-quarkus-ai-tool-deployment + ${camel-quarkus.version} + org.apache.camel.quarkus camel-quarkus-amqp diff --git a/poms/bom/src/main/generated/flattened-full-pom.xml b/poms/bom/src/main/generated/flattened-full-pom.xml index d89530db534..7c84dc4712b 100644 --- a/poms/bom/src/main/generated/flattened-full-pom.xml +++ b/poms/bom/src/main/generated/flattened-full-pom.xml @@ -3440,6 +3440,16 @@ camel-quarkus-activemq6-deployment 3.39.0-SNAPSHOT + + org.apache.camel.quarkus + camel-quarkus-ai-tool + 3.39.0-SNAPSHOT + + + org.apache.camel.quarkus + camel-quarkus-ai-tool-deployment + 3.39.0-SNAPSHOT + org.apache.camel.quarkus camel-quarkus-amqp diff --git a/poms/bom/src/main/generated/flattened-reduced-pom.xml b/poms/bom/src/main/generated/flattened-reduced-pom.xml index 86fb8899365..4ff8f176f5c 100644 --- a/poms/bom/src/main/generated/flattened-reduced-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-pom.xml @@ -4773,6 +4773,16 @@ camel-quarkus-activemq6-deployment 3.39.0-SNAPSHOT + + org.apache.camel.quarkus + camel-quarkus-ai-tool + 3.39.0-SNAPSHOT + + + org.apache.camel.quarkus + camel-quarkus-ai-tool-deployment + 3.39.0-SNAPSHOT + org.apache.camel.quarkus camel-quarkus-amqp diff --git a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml index b8075caa75d..41e05316634 100644 --- a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml @@ -4773,6 +4773,16 @@ camel-quarkus-activemq6-deployment 3.39.0-SNAPSHOT + + org.apache.camel.quarkus + camel-quarkus-ai-tool + 3.39.0-SNAPSHOT + + + org.apache.camel.quarkus + camel-quarkus-ai-tool-deployment + 3.39.0-SNAPSHOT + org.apache.camel.quarkus camel-quarkus-amqp diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml index 6eecf4224ad..a4df3902653 100644 --- a/tooling/scripts/test-categories.yaml +++ b/tooling/scripts/test-categories.yaml @@ -231,6 +231,7 @@ group-11: - xml-grouped - xslt-saxon group-12: + - ai-tool - aws2-grouped - csimple - github2