You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "atiaomar1978-hub (via GitHub)" <gi...@apache.org> on 2026/08/14 00:00:25 UTC

[PR] CAMEL-23397: Support route tool annotations (returnDirect) in camel-openai agentic loop [camel]

atiaomar1978-hub opened a new pull request, #25497:
URL: https://github.com/apache/camel/pull/25497

   # Description
   
   _AI-generated on behalf of atiaomar1978-hub using Cursor._
   
   Implements [CAMEL-23397](https://issues.apache.org/jira/browse/CAMEL-23397): parity between MCP tools and route-based `ai-tool` tools in the `camel-openai` agentic loop.
   
   ### Changes
   
   - **`camel-ai-tool`**: add `returnDirect` to `AiToolAnnotations` / `AiToolConfiguration` and document it.
   - **`camel-mcp-server`**: publish `returnDirect` in MCP tool annotations via `VertxMcpServerEngine`.
   - **`camel-openai`**:
     - new `tags` endpoint option to discover route tools from the shared `AiToolRegistry`
     - convert route tools to OpenAI function tools (`AiToolSpecToOpenAI`, `OpenAIRouteToolSupport`)
     - execute route tools in `McpToolCallExecutor` via `AiToolExecutor`
     - honour `returnDirect` annotations when short-circuiting the agentic loop
     - refresh route tools dynamically when the registry changes
     - support manual `tool-execution` loops with tags-only route tools
   
   ### Testing
   
   ```bash
   ./mvnw -pl components/camel-ai/camel-ai-tool,components/camel-ai/camel-openai -am test \
     -Dtest=AiToolAnnotationsTest,OpenAIRouteToolSupportTest,OpenAIRouteToolReturnDirectTest,McpToolCallExecutorTest,OpenAIProducerMcpMockTest,OpenAIEndpointMcpToolRefreshTest
   ```
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful subject line and body.
   - [x] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes.
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used.


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23397: Support route tool annotations (returnDirect) in camel-openai agentic loop [camel]

Posted by "atiaomar1978-hub (via GitHub)" <gi...@apache.org>.
atiaomar1978-hub commented on PR #25497:
URL: https://github.com/apache/camel/pull/25497#issuecomment-5302936370

   ## Review follow-up (@davsclaus)
   
   _AI-generated on behalf of atiaomar1978-hub using Cursor._
   
   Addressed all items from the [changes-requested review](https://github.com/apache/camel/pull/25497#pullrequestreview-4890126512) in commit `f07d3b2b`:
   
   | # | Finding | Fix |
   |---|---------|-----|
   | 1 | `AiToolAnnotations` 6th field API change | Confirmed target is **4.23.0-SNAPSHOT** (pre-release). Added **5-arg convenience constructor** defaulting `returnDirect` to `null` + test for source compatibility. |
   | 2 | FQCNs in `McpToolState.knownToolNames()` | Replaced `java.util.Set` / `java.util.HashSet` with imported `Set` / `HashSet`. |
   | 3 | Dead `release` variable in `executeRouteTool()` | Removed flag; `releaseExchange` now called unconditionally in `finally`. |
   | 4 | `camel-ai-tool` compile dependency justification | Added explanation to PR description (shared registry/executor, no meaningful SPI win). |
   | 5 | Co-authorship attribution | New commit includes `Co-authored-by: Omar Atie`. |
   
   ### Tests (local)
   
   ```bash
   mvn -pl components/camel-ai/camel-ai-tool,components/camel-ai/camel-openai test \
     -Dtest=AiToolAnnotationsTest,OpenAIRouteToolSupportTest,OpenAIRouteToolReturnDirectTest,McpToolCallExecutorTest,OpenAIEndpointMcpToolRefreshTest
   ```
   
   **27 tests, 0 failures.**
   
   Ready for re-review.


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23397: Support route tool annotations (returnDirect) in camel-openai agentic loop [camel]

Posted by "atiaomar1978-hub (via GitHub)" <gi...@apache.org>.
atiaomar1978-hub commented on PR #25497:
URL: https://github.com/apache/camel/pull/25497#issuecomment-5399114978

   Addressed the follow-up review from @davsclaus in commit $(git rev-parse --short HEAD).
   
   **Fix:** Route tool execution now creates exchanges via `spec.getConsumer().createExchange(false)` instead of `Endpoint.createExchange()`, matching the symmetric `releaseExchange()` path and avoiding `ClassCastException` when `camel.main.exchangeFactory=pooled` is configured.
   
   **Tests run locally (all passing):**
   ```
   ./mvnw -pl components/camel-ai/camel-ai-tool,components/camel-ai/camel-openai -am test \
     -Dtest=AiToolAnnotationsTest,OpenAIRouteToolSupportTest,OpenAIRouteToolReturnDirectTest,McpToolCallExecutorTest,OpenAIProducerMcpMockTest,OpenAIEndpointMcpToolRefreshTest
   ```
   
   _AI-generated on behalf of atiaomar1978-hub_


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23397: Support route tool annotations (returnDirect) in camel-openai agentic loop [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on PR #25497:
URL: https://github.com/apache/camel/pull/25497#issuecomment-5291270100

   There are uncommitted changes
   HEAD detached at pull/25497/merge
   Changes not staged for commit:
     (use "git add <file>..." to update what will be committed)
     (use "git restore <file>..." to discard changes in working directory)
   	modified:   catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/ai-tool.json
   	modified:   catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/openai.json
   	modified:   catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/ai-tool-component.adoc
   	modified:   catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/openai-mcp.adoc
   	modified:   dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AiToolComponentBuilderFactory.java
   	modified:   dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/AiToolEndpointBuilderFactory.java
   	modified:   dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/OpenAIEndpointBuilderFactory.java


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23397: Support route tool annotations (returnDirect) in camel-openai agentic loop [camel]

Posted by "atiaomar1978-hub (via GitHub)" <gi...@apache.org>.
atiaomar1978-hub commented on PR #25497:
URL: https://github.com/apache/camel/pull/25497#issuecomment-5412654639

   Merged latest upstream \`main\` and regenerated the openai component catalog, URI factory, and endpoint DSL artifacts.
   
   **Merge resolution**
   - Source files auto-merged cleanly (including \`OpenAIConfiguration\` with both upstream image-generation options and the new \`tags\` parameter).
   - Generated file conflicts were resolved by rebuilding affected modules so artifacts include both change sets.
   
   **Verification**
   - \`./mvnw -pl components/camel-ai/camel-ai-tool,components/camel-ai/camel-openai -am test\` with \`AiToolAnnotationsTest\`, \`OpenAIRouteToolSupportTest\`, \`OpenAIRouteToolReturnDirectTest\`, \`McpToolCallExecutorTest\`, \`OpenAIProducerMcpMockTest\`, and \`OpenAIEndpointMcpToolRefreshTest\` — all green.
   
   _AI-generated update on behalf of atiaomar1978-hub_


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23397: Support route tool annotations (returnDirect) in camel-openai agentic loop [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #25497:
URL: https://github.com/apache/camel/pull/25497#issuecomment-5290603682

   :star2: Thank you for your contribution to the Apache Camel project! :star2:
     :robot: CI automation will test this PR automatically.
   
     :camel: Apache Camel Committers, please review the following items:
   
     * First-time contributors **require MANUAL approval** for the GitHub Actions to run
     * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
     * You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
     * Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
     
     :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23397: Support route tool annotations (returnDirect) in camel-openai agentic loop [camel]

Posted by "atiaomar1978-hub (via GitHub)" <gi...@apache.org>.
atiaomar1978-hub commented on PR #25497:
URL: https://github.com/apache/camel/pull/25497#issuecomment-5287759341

   ## Bugbot re-review follow-up
   
   _AI-generated on behalf of atiaomar1978-hub using Cursor._
   
   After the initial bugbot review, the following issues were addressed in commits `39500554a24b` and `799b8ae0dbd8`:
   
   ### Fixed
   
   1. **Route deregistration dropped MCP tools** — `republishCombinedState` now keeps MCP-backed tools via `toolClientMap` instead of filtering by previous route-tool names.
   2. **Duplicate tools on name clash** — route tools shadow MCP tools with the same name in the advertised tool list (route execution already took precedence).
   3. **`tool-execution` rejected route-only tools** — `OpenAIToolExecutionProducer` now accepts endpoints configured with `tags` only (no `mcpServer.*`).
   4. **MCP `returnDirect` lost after shadowing** — MCP and route `returnDirect` flags are merged separately; MCP flags are preserved when a route tool is removed.
   5. **MCP refresh bypassed route merge** — `republishServerTools` now calls `republishCombinedState()` after MCP reconnect / `tools/list_changed` refresh so route-tool shadowing and `returnDirect` merging stay consistent.
   
   ### Tests re-run
   
   ```bash
   ./mvnw -pl components/camel-ai/camel-openai -am test \
     -Dtest=OpenAIRouteToolSupportTest,OpenAIRouteToolReturnDirectTest,McpToolCallExecutorTest,OpenAIEndpointMcpToolRefreshTest
   ```
   
   All passed locally.


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23397: Support route tool annotations (returnDirect) in camel-openai agentic loop [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus merged PR #25497:
URL: https://github.com/apache/camel/pull/25497


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23397: Support route tool annotations (returnDirect) in camel-openai agentic loop [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #25497:
URL: https://github.com/apache/camel/pull/25497#discussion_r3788724843


##########
components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/McpToolState.java:
##########
@@ -22,24 +22,33 @@
 
 import com.openai.models.chat.completions.ChatCompletionFunctionTool;
 import io.modelcontextprotocol.client.McpSyncClient;
+import org.apache.camel.component.ai.tool.AiToolSpec;
 
 /**
- * Immutable snapshot of the MCP tool state shared by all concurrent exchanges.
+ * Immutable snapshot of the MCP and route-based tool state shared by all concurrent exchanges.
  */
 record McpToolState(
         List<ChatCompletionFunctionTool> tools,
         Map<String, McpSyncClient> toolClientMap,
         Map<String, String> toolToServerName,
-        Set<String> returnDirectTools) {
+        Set<String> returnDirectTools,
+        Map<String, AiToolSpec> routeTools) {
 
     McpToolState {
         tools = List.copyOf(tools);
         toolClientMap = Map.copyOf(toolClientMap);
         toolToServerName = Map.copyOf(toolToServerName);
         returnDirectTools = Set.copyOf(returnDirectTools);
+        routeTools = Map.copyOf(routeTools);
     }
 
     static McpToolState empty() {
-        return new McpToolState(List.of(), Map.of(), Map.of(), Set.of());
+        return new McpToolState(List.of(), Map.of(), Map.of(), Set.of(), Map.of());

Review Comment:
   These use fully-qualified class names (`java.util.Set`, `java.util.HashSet`) but both are already imported at the top of this file. Per project conventions, use the simple class names:
   ```suggestion
       Set<String> knownToolNames() {
           Set<String> names = new HashSet<>(toolClientMap.keySet());
   ```



##########
components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/McpToolCallExecutor.java:
##########
@@ -254,6 +263,56 @@ private ToolResult executeOne(ChatCompletionMessageToolCall toolCall, McpToolSta
         }
     }
 
+    private ToolResult executeRouteTool(
+            ChatCompletionMessageToolCall toolCall,
+            AiToolSpec spec,
+            McpToolState toolState,
+            OpenAIConfiguration config)
+            throws Exception {
+        String toolName = toolCall.asFunction().function().name();
+        String argsJson = toolCall.asFunction().function().arguments();
+
+        LOG.debug("Executing route tool '{}' with args: {}", toolName, argsJson);
+
+        try {
+            Map<String, Object> argsMap = OBJECT_MAPPER.readValue(argsJson, Map.class);
+            Exchange toolExchange = spec.getConsumer().getEndpoint().createExchange();

Review Comment:
   `release` is set to `true` and never changed — the conditional is always entered. Remove the variable and call `releaseExchange` unconditionally in the finally block.
   ```suggestion
               boolean release = true;
   ```
   
   Should become just removing the variable and changing `if (release) {` to unconditional.



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23397: Support route tool annotations (returnDirect) in camel-openai agentic loop [camel]

Posted by "atiaomar1978-hub (via GitHub)" <gi...@apache.org>.
atiaomar1978-hub commented on PR #25497:
URL: https://github.com/apache/camel/pull/25497#issuecomment-5295278562

   Fixed CI **uncommitted changes** failure in run [31782070449](https://github.com/apache/camel/actions/runs/31782070449/job/94711275211).
   
   Regenerated and committed missing catalog/DSL artifacts for `returnDirect` (ai-tool) and `tags` (openai):
   
   - `catalog/.../ai-tool.json`, `openai.json`, docs
   - `AiToolComponentBuilderFactory`, `AiToolEndpointBuilderFactory`, `OpenAIEndpointBuilderFactory`
   
   Commit: `42553cbd`
   
   _AI-generated on behalf of atiaomar1978-hub_


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23397: Support route tool annotations (returnDirect) in camel-openai agentic loop [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #25497:
URL: https://github.com/apache/camel/pull/25497#issuecomment-5301014856

   <!-- ci-tested-modules -->
   :test_tube: **CI tested the following changed modules:**
   
   - `catalog/camel-catalog`
   - `components/camel-ai/camel-ai-tool`
   - `components/camel-ai/camel-mcp-server`
   - `components/camel-ai/camel-openai`
   - `dsl/camel-componentdsl`
   - `dsl/camel-endpointdsl`
   
   ---
   
   <details><summary>:microscope: Scalpel shadow comparison — Scalpel: 17 tested, 26 compile-only — current: 14 all tested</summary>
   
   [Maveniverse Scalpel](https://github.com/maveniverse/scalpel) detected **43 affected modules** (current approach: 14).
   
   <details><summary>:warning: Modules only in Scalpel (29)</summary>
   
   - `apache-camel`
   - `camel-allcomponents`
   - `camel-catalog`
   - `camel-catalog-console`
   - `camel-catalog-lucene`
   - `camel-catalog-maven`
   - `camel-catalog-suggest`
   - `camel-componentdsl`
   - `camel-csimple-maven-plugin`
   - `camel-endpointdsl`
   - `camel-endpointdsl-support`
   - `camel-itest`
   - `camel-jbang-core`
   - `camel-jbang-it`
   - `camel-jbang-main`
   - `camel-jbang-plugin-edit`
   - `camel-jbang-plugin-generate`
   - `camel-jbang-plugin-kubernetes`
   - `camel-jbang-plugin-test`
   - `camel-kamelet-main`
   - `camel-launcher`
   - `camel-report-maven-plugin`
   - `camel-route-parser`
   - `camel-yaml-dsl`
   - `camel-yaml-dsl-deserializers`
   - `camel-yaml-dsl-maven-plugin`
   - `coverage`
   - `docs`
   - `dummy-component`
   
   </details>
   
   **Skip-tests mode would test 17 modules** (6 direct + 11 downstream), **skip tests for 26** (generated code, meta-modules)
   
   <details><summary>Modules Scalpel would test (17)</summary>
   
   - `camel-ai-tool`
   - `camel-catalog`
   - `camel-componentdsl`
   - `camel-endpointdsl`
   - `camel-jbang-mcp`
   - `camel-jbang-plugin-mcp`
   - `camel-jbang-plugin-route-parser`
   - `camel-jbang-plugin-tui`
   - `camel-jbang-plugin-validate`
   - `camel-langchain4j-agent`
   - `camel-launcher-container`
   - `camel-mcp-server`
   - `camel-mcp-server-api`
   - `camel-openai`
   - `camel-spring-ai-chat`
   - `camel-yaml-dsl-validator`
   - `camel-yaml-dsl-validator-maven-plugin`
   
   </details>
   
   <details><summary>Modules with tests skipped (26)</summary>
   
   - `apache-camel`
   - `camel-allcomponents`
   - `camel-catalog-console`
   - `camel-catalog-lucene`
   - `camel-catalog-maven`
   - `camel-catalog-suggest`
   - `camel-csimple-maven-plugin`
   - `camel-endpointdsl-support`
   - `camel-itest`
   - `camel-jbang-core`
   - `camel-jbang-it`
   - `camel-jbang-main`
   - `camel-jbang-plugin-edit`
   - `camel-jbang-plugin-generate`
   - `camel-jbang-plugin-kubernetes`
   - `camel-jbang-plugin-test`
   - `camel-kamelet-main`
   - `camel-launcher`
   - `camel-report-maven-plugin`
   - `camel-route-parser`
   - `camel-yaml-dsl`
   - `camel-yaml-dsl-deserializers`
   - `camel-yaml-dsl-maven-plugin`
   - `coverage`
   - `docs`
   - `dummy-component`
   
   </details>
   
   > :information_source: Shadow mode — Scalpel observes but does not affect test execution. [Learn more](https://github.com/maveniverse/scalpel)
   
   </details>
   
   :warning: **Some tests are disabled on GitHub Actions** (`@DisabledIfSystemProperty(named = "ci.env.name")`) and require manual verification:
   
   - `components/camel-ai/camel-mcp-server`: 1 test(s) disabled on GitHub Actions
   - `components/camel-ai/camel-openai`: 7 test(s) disabled on GitHub Actions
   
   <details><summary>All tested modules (43 modules)</summary>
   
   - Camel :: AI :: LangChain4j :: Agent
   - Camel :: AI :: MCP Server
   - Camel :: AI :: MCP Server API
   - Camel :: AI :: OpenAI
   - Camel :: AI :: Tool
   - Camel :: All Components Sync point
   - Camel :: Assembly
   - Camel :: Catalog :: CSimple Maven Plugin (deprecated)
   - Camel :: Catalog :: Camel Catalog
   - Camel :: Catalog :: Camel Report Maven Plugin
   - Camel :: Catalog :: Camel Route Parser
   - Camel :: Catalog :: Console
   - Camel :: Catalog :: Dummy Component
   - Camel :: Catalog :: Lucene (deprecated)
   - Camel :: Catalog :: Maven
   - Camel :: Catalog :: Suggest
   - Camel :: Component DSL
   - Camel :: Coverage
   - Camel :: Docs
   - Camel :: Endpoint DSL
   - Camel :: Endpoint DSL :: Support
   - Camel :: Integration Tests
   - Camel :: JBang :: Core
   - Camel :: JBang :: Integration tests
   - Camel :: JBang :: MCP
   - Camel :: JBang :: Main
   - Camel :: JBang :: Plugin :: Edit
   - Camel :: JBang :: Plugin :: Generate
   - Camel :: JBang :: Plugin :: Kubernetes
   - Camel :: JBang :: Plugin :: MCP
   - Camel :: JBang :: Plugin :: Route Parser
   - Camel :: JBang :: Plugin :: TUI
   - Camel :: JBang :: Plugin :: Testing
   - Camel :: JBang :: Plugin :: Validate
   - Camel :: Kamelet Main
   - Camel :: Launcher
   - Camel :: Launcher :: Container
   - Camel :: Spring AI :: Chat
   - Camel :: YAML DSL
   - Camel :: YAML DSL :: Deserializers
   - Camel :: YAML DSL :: Maven Plugins
   - Camel :: YAML DSL :: Validator
   - Camel :: YAML DSL :: Validator Maven Plugin
   
   </details>
   
   ---
   :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/31815994912)


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23397: Support route tool annotations (returnDirect) in camel-openai agentic loop [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on PR #25497:
URL: https://github.com/apache/camel/pull/25497#issuecomment-5410097131

   @atiaomar1978-hub can you update this PR as another was merged that changes this module


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23397: Support route tool annotations (returnDirect) in camel-openai agentic loop [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #25497:
URL: https://github.com/apache/camel/pull/25497#discussion_r3845951707


##########
components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/McpToolCallExecutor.java:
##########
@@ -254,6 +263,53 @@ private ToolResult executeOne(ChatCompletionMessageToolCall toolCall, McpToolSta
         }
     }
 
+    private ToolResult executeRouteTool(
+            ChatCompletionMessageToolCall toolCall,
+            AiToolSpec spec,
+            McpToolState toolState,
+            OpenAIConfiguration config)
+            throws Exception {
+        String toolName = toolCall.asFunction().function().name();
+        String argsJson = toolCall.asFunction().function().arguments();
+
+        LOG.debug("Executing route tool '{}' with args: {}", toolName, argsJson);
+
+        try {
+            Map<String, Object> argsMap = OBJECT_MAPPER.readValue(argsJson, Map.class);
+            Exchange toolExchange = spec.getConsumer().getEndpoint().createExchange();

Review Comment:
   This creates the exchange via `Endpoint.createExchange()`, which always returns a plain `DefaultExchange` (confirmed: `DefaultExchange` is `final` and does not implement `PooledExchange` — only the separate `DefaultPooledExchange` does). But it's released a few lines down via `spec.getConsumer().releaseExchange(toolExchange, false)`, which delegates to the consumer's configured `ExchangeFactory.release(...)`. When that factory is `PooledExchangeFactory` (activated via the documented `camel.main.exchangeFactory=pooled` option), `release()` does an unchecked `(PooledExchange) exchange` cast — guaranteed to throw `ClassCastException` on the plain `DefaultExchange` this code hands it.
   
   `design/aiTool.adoc` documents the correct symmetric pattern for this exact adapter code: create via `consumer.createExchange()`, release via `consumer.releaseExchange()` — both going through the same (possibly pooled) factory. Existing tests don't catch this because they run under the default non-pooled factory.
   
   ```suggestion
               Exchange toolExchange = spec.getConsumer().createExchange(false);
   ```



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org