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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]