You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "Croway (via GitHub)" <gi...@apache.org> on 2026/09/10 11:08:40 UTC

[PR] CAMEL-24670: camel-openai - complete the Responses API support [camel]

Croway opened a new pull request, #26264:
URL: https://github.com/apache/camel/pull/26264

   _Claude Code on behalf of Federico Mariani (Croway)_
   
   JIRA: [CAMEL-24670](https://issues.apache.org/jira/browse/CAMEL-24670)
   
   ## Summary
   
   The `openai:responses` operation missed several Responses API features and silently ignored some endpoint options. Each change is a separate commit.
   
   **Fixes**
   - `CamelOpenAIResponseModel` and the GenAI span carried the SDK union type string (`ResponsesModel{string=...}`) instead of the model id.
   - `hostedMcpTools` sent only `server_label`, `server_url` and `server_description`, so `require_approval` (API default `always`), `allowed_tools`, `headers` and `authorization` were dropped. Every field is now sent, and the option is marked secret.
   - A response waiting for hosted MCP approval completed the exchange with an empty body. It now fails with a `CamelExchangeException` naming the pending calls.
   - `developerMessage` and `conversationMemory` were ignored by the `responses` operation.
   - A PDF `byte[]` body was silently dropped when `userMessage` was set.
   
   **Improvements**
   - `CamelOpenAIResponseAnnotations` header with the citations of `web_search` / `file_search`.
   - PDF bodies sent as `input_file`.
   - `conversationId` option / header for the Conversations API.
   - `conversationMemory` chains `previous_response_id` in the exchange.
   - MCP servers (`mcpServer.*`) and route tools (`tags`) run in a tool loop, as for `chat-completion` (`maxToolIterations`, error strategies, `returnDirect`; `autoToolExecution=false` returns the function calls).
   - `background` option, `CamelOpenAIResponseStatus` header, and new `responses-retrieve` / `responses-cancel` operations.
   
   **Test infrastructure (`camel-test-infra-openai-mock`)**
   - `getReceivedRequests()` / `getLastRequest()` to assert on requests from the test thread.
   - Responses API: custom output items, `thenRespondWith`, function call sequences, `GET` retrieve, `POST` cancel, background.
   - `replyWithError(status, type, message)` and `withRetryAfter(seconds)`.
   
   **Upgrade guide (4.23):** `hostedMcpTools` now sends every field, and pending MCP approvals fail the exchange.
   
   ## Testing
   
   - camel-openai unit tests: 275 passed (`OpenAIResponsesMockTest`: 23).
   - camel-test-infra-openai-mock tests: 29 passed. They live in `src/main/java` and are not run by surefire, so they were run with the JUnit console launcher.
   - Opt-in ITs against vLLM Metal 0.28 with `mlx-community/Qwen3-4B-Instruct-2507-4bit` (see `test_execution.md`): `OpenAIResponsesExternalServiceIT` 14 passed, `OpenAIResponsesMcpExternalServiceIT` 1 passed.
   
   Verified live on vLLM: text input and headers, instructions, developer message, `previousResponseId`, `jsonSchema`, `outputClass`, `storeFullResponse`, `maxTokens`, error metadata, `conversationMemory`, route tool loop, MCP tool loop, background, retrieve, cancel.
   
   Covered by mock tests only (OpenAI-only or unsupported by the local model): hosted MCP fields and approvals, citations, PDF input, `conversationId`, `returnDirect` and `autoToolExecution=false` in the tool loop.
   
   Not tested: against the OpenAI API itself; the tool error strategies and `parallelToolExecution` on the Responses loop (shared executor, tested for chat only); the tool loop combined with `conversationMemory` / `previousResponseId`; reasoning items sent back in the loop; image input on `responses` with a vision model.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_01AZd4Yzgp8hhbBW2779LuQY
   


-- 
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-24670: camel-openai - complete the Responses API support [camel]

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


-- 
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-24670: camel-openai - complete the Responses API support [camel]

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

   :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-24670: camel-openai - complete the Responses API support [camel]

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

   <!-- ci-tested-modules -->
   :test_tube: **CI tested the following changed modules:**
   
   - `catalog/camel-catalog`
   - `components/camel-ai/camel-openai`
   - `docs`
   - `dsl/camel-endpointdsl`
   - `test-infra/camel-test-infra-openai-mock`
   
   ---
   
   <details><summary>:microscope: Scalpel shadow comparison — Scalpel: 16 tested, 24 compile-only — current: 13 all tested</summary>
   
   [Maveniverse Scalpel](https://github.com/maveniverse/scalpel) detected **40 affected modules** (current approach: 13).
   
   <details><summary>:warning: Modules only in Scalpel (27)</summary>
   
   - `apache-camel`
   - `camel-allcomponents`
   - `camel-catalog`
   - `camel-catalog-console`
   - `camel-catalog-maven`
   - `camel-catalog-suggest`
   - `camel-componentdsl`
   - `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 16 modules** (5 direct + 11 downstream), **skip tests for 24** (generated code, meta-modules)
   
   <details><summary>Modules Scalpel would test (16)</summary>
   
   - `camel-catalog`
   - `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-openai`
   - `camel-test-infra-all`
   - `camel-test-infra-openai-mock`
   - `camel-yaml-dsl-validator`
   - `camel-yaml-dsl-validator-maven-plugin`
   - `docs`
   
   </details>
   
   <details><summary>Modules with tests skipped (24)</summary>
   
   - `apache-camel`
   - `camel-allcomponents`
   - `camel-catalog-console`
   - `camel-catalog-maven`
   - `camel-catalog-suggest`
   - `camel-componentdsl`
   - `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`
   - `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-openai`: 7 test(s) disabled on GitHub Actions
   
   <details><summary>All tested modules (40 modules, 7m 18s total)</summary>
   
   **Total reactor time:** 7m 18s
   
   | Module | Duration | Status |
   | --- | --- | --- |
   | Camel :: YAML DSL | 58.9s | SUCCESS |
   | Camel :: Launcher | 49.4s | SUCCESS |
   | Camel :: AI :: MCP Server | 45.8s | SUCCESS |
   | Camel :: AI :: OpenAI | 38.2s | SUCCESS |
   | Camel :: JBang :: MCP | 37.9s | SUCCESS |
   | Camel :: JBang :: Plugin :: TUI | 30.6s | SUCCESS |
   | Camel :: AI :: LangChain4j :: Agent | 22.6s | SUCCESS |
   | Camel :: Component DSL | 18.4s | SUCCESS |
   | Camel :: Catalog :: Camel Catalog | 18.0s | SUCCESS |
   | Camel :: JBang :: Plugin :: Kubernetes | 16.2s | SUCCESS |
   | Camel :: Test Infra :: All test services | 14.7s | SUCCESS |
   | Camel :: Docs | 14.2s | SUCCESS |
   | Camel :: Kamelet Main | 8.3s | SUCCESS |
   | Camel :: JBang :: Plugin :: Testing | 7.8s | SUCCESS |
   | Camel :: Catalog :: Camel Report Maven Plugin | 7.4s | SUCCESS |
   | Camel :: Catalog :: Camel Route Parser | 7.2s | SUCCESS |
   | Camel :: Test Infra :: OpenAI Mock | 5.7s | SUCCESS |
   | Camel :: YAML DSL :: Validator | 4.9s | SUCCESS |
   | Camel :: YAML DSL :: Deserializers | 4.9s | SUCCESS |
   | Camel :: All Components Sync point | 4.8s | SUCCESS |
   | Camel :: Catalog :: Maven | 2.6s | SUCCESS |
   | Camel :: YAML DSL :: Maven Plugins | 2.5s | SUCCESS |
   | Camel :: Catalog :: Suggest (deprecated) | 2.3s | SUCCESS |
   | Camel :: YAML DSL :: Validator Maven Plugin | 2.3s | SUCCESS |
   | Camel :: Assembly | 1.7s | SUCCESS |
   | Camel :: Coverage | 1.6s | SUCCESS |
   | Camel :: Catalog :: Dummy Component | 1.2s | SUCCESS |
   | Camel :: Endpoint DSL :: Support | 1.0s | SUCCESS |
   | Camel :: JBang :: Integration tests | 0.9s | SUCCESS |
   | Camel :: JBang :: Plugin :: Generate | 0.9s | SUCCESS |
   | Camel :: JBang :: Plugin :: Edit | 0.9s | SUCCESS |
   | Camel :: JBang :: Main | 0.8s | SUCCESS |
   | Camel :: Catalog :: Console | 0.7s | SUCCESS |
   | Camel :: Launcher :: Container | 0.7s | SUCCESS |
   | Camel :: JBang :: Plugin :: Validate | 0.7s | SUCCESS |
   | Camel :: JBang :: Plugin :: MCP | 0.6s | SUCCESS |
   | Camel :: JBang :: Plugin :: Route Parser | 0.5s | SUCCESS |
   | Camel :: Endpoint DSL | n/a |  |
   | Camel :: Integration Tests | n/a |  |
   | Camel :: JBang :: Core | n/a |  |
   
   **Top 20 slowest modules:**
   - `Camel :: YAML DSL` (58.9s)
   - `Camel :: Launcher` (49.4s)
   - `Camel :: AI :: MCP Server` (45.8s)
   - `Camel :: AI :: OpenAI` (38.2s)
   - `Camel :: JBang :: MCP` (37.9s)
   - `Camel :: JBang :: Plugin :: TUI` (30.6s)
   - `Camel :: AI :: LangChain4j :: Agent` (22.6s)
   - `Camel :: Component DSL` (18.4s)
   - `Camel :: Catalog :: Camel Catalog` (18.0s)
   - `Camel :: JBang :: Plugin :: Kubernetes` (16.2s)
   - `Camel :: Test Infra :: All test services` (14.7s)
   - `Camel :: Docs` (14.2s)
   - `Camel :: Kamelet Main` (8.3s)
   - `Camel :: JBang :: Plugin :: Testing` (7.8s)
   - `Camel :: Catalog :: Camel Report Maven Plugin` (7.4s)
   - `Camel :: Catalog :: Camel Route Parser` (7.2s)
   - `Camel :: Test Infra :: OpenAI Mock` (5.7s)
   - `Camel :: YAML DSL :: Validator` (4.9s)
   - `Camel :: YAML DSL :: Deserializers` (4.9s)
   - `Camel :: All Components Sync point` (4.8s)
   
   </details>
   
   ---
   :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/34472442827)


-- 
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-24670: camel-openai - complete the Responses API support [camel]

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

   <!-- regen-patch -->
   ### :warning: Generated files are out of date
   
   The [CI build](https://github.com/apache/camel/actions/runs/34469740083) regenerated files that are not committed on this PR.
   
   If *Allow edits from maintainers* is enabled, a maintainer bot will automatically
   push a "Regen" commit to this branch shortly.
   
   Otherwise, you can apply the patch manually — the missing changes are available
   as the `regen-patch` artifact of that run:
   
   ```bash
   gh pr checkout 26264 --repo apache/camel
   gh run download 34469740083 --repo apache/camel -n regen-patch
   git apply --index regen.patch && rm regen.patch pr-number
   git commit -m "Regen" && git push
   ```
   
   Alternatively, run `./etc/scripts/regen.sh` locally and commit the resulting changes.
   If the patch does not apply cleanly, update the branch from the base branch first —
   the patch was generated against the merge with the base branch.


-- 
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-24670: camel-openai - complete the Responses API support [camel]

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


##########
components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIResponsesProducer.java:
##########
@@ -134,46 +162,109 @@ private void processInternal(Exchange exchange) throws Exception {
         if (ObjectHelper.isNotEmpty(previousResponseId)) {
             paramsBuilder.previousResponseId(previousResponseId);
         }
+        String conversationId = resolveParameter(in, OpenAIConstants.CONVERSATION_ID, config.getConversationId(),
+                String.class);
+        if (ObjectHelper.isNotEmpty(conversationId)) {
+            paramsBuilder.conversation(conversationId);
+        }
+        if (config.isBackground()) {
+            // a background response is only reachable later if the server stores it
+            paramsBuilder.background(true).store(true);
+        }
 
         OpenAIResponsesSupport.applyBuiltinTools(paramsBuilder, config.getBuiltinTools(),
                 config.getFileSearchVectorStoreIds());
         OpenAIResponsesSupport.applyHostedMcpTools(paramsBuilder, config.getHostedMcpTools());
         OpenAIResponsesSupport.applyAdditionalBodyProperties(paramsBuilder, config.getAdditionalBodyProperty());
 
+        // the MCP servers and route tools of the endpoint are sent as function tools
+        List<ChatCompletionFunctionTool> tools = getEndpoint().getMcpToolState().tools();
+        tools.forEach(tool -> paramsBuilder.addTool(OpenAIResponsesSupport.toFunctionTool(tool)));
+
+        ResponseCreateParams params;
         Class<?> responseClass = resolveOutputClass(in, outputClass);
         if (responseClass != null) {
-            processStructured(exchange, config, paramsBuilder, responseClass, model);
-            return;
+            params = paramsBuilder.text(responseClass).build().rawParams();
+        } else {
+            if (ObjectHelper.isNotEmpty(jsonSchema)) {
+                OpenAIResponsesSupport.applyJsonSchemaTextFormat(paramsBuilder, jsonSchema);
+            }
+            params = paramsBuilder.build();
         }
-        if (ObjectHelper.isNotEmpty(jsonSchema)) {
-            OpenAIResponsesSupport.applyJsonSchemaTextFormat(paramsBuilder, jsonSchema);
+
+        if (!tools.isEmpty() && config.isAutoToolExecution()) {
+            if (config.isBackground()) {
+                throw new IllegalArgumentException(
+                        "background cannot be combined with automatic tool execution, the tool loop needs each answer. "
+                                                   + "Set autoToolExecution=false to handle the function calls in the route");
+            }
+            processToolLoop(exchange, config, params, inputSpec.items(), model);
+            return;
         }
 
-        ResponseCreateParams params = paramsBuilder.build();
         Response response = createResponse(exchange, model, params);
-        finishExchange(exchange, config, response, OpenAIResponsesSupport.extractAssistantText(response));
+        List<ResponseFunctionToolCall> functionCalls = OpenAIResponsesSupport.extractFunctionCalls(response);
+        // with autoToolExecution=false the route handles the function calls requested by the model
+        Object body = functionCalls.isEmpty() ? OpenAIResponsesSupport.extractAssistantText(response) : functionCalls;
+        finishExchange(exchange, config, response, body);
     }
 
-    private void processStructured(
-            Exchange exchange, OpenAIConfiguration config, ResponseCreateParams.Builder paramsBuilder,
-            Class<?> responseClass, String model)
+    /**
+     * Runs the tool loop: the function calls requested by the model are executed on the MCP servers and route tools of
+     * the endpoint, and their results are sent back with the conversation so far until the model answers.
+     */
+    private void processToolLoop(
+            Exchange exchange, OpenAIConfiguration config, ResponseCreateParams params, List<ResponseInputItem> input,
+            String model)
             throws Exception {
-        StructuredResponseCreateParams<?> structuredParams = paramsBuilder.text(responseClass).build();
-        Response raw = createStructuredResponse(exchange, model, structuredParams);
-        finishExchange(exchange, config, raw, OpenAIResponsesSupport.extractAssistantText(raw));
+        List<ResponseInputItem> conversation = new ArrayList<>(input);
+        List<String> toolCallsLog = new ArrayList<>();
+        int iteration = 0;
+
+        while (true) {
+            Response response = createResponse(exchange, model, params.toBuilder().inputOfResponse(conversation).build());
+            List<ResponseFunctionToolCall> functionCalls = OpenAIResponsesSupport.extractFunctionCalls(response);
+            if (functionCalls.isEmpty()) {
+                finishExchange(exchange, config, response, OpenAIResponsesSupport.extractAssistantText(response));
+                setToolHeaders(exchange.getMessage(), iteration, toolCallsLog, false);
+                return;
+            }
+            if (iteration == config.getMaxToolIterations()) {

Review Comment:
   Nit: `maxToolIterations` has slightly different semantics here than in `chat-completion`. The chat loop (`while (iteration < maxIterations)`) makes at most N model calls; this loop checks `iteration == max` *after* the model returned function calls, so it makes up to N+1 model calls and executes N tool batches. Not wrong, but the same option now behaves a little differently between the two operations — worth aligning, or at least a short comment explaining the choice.



##########
components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIResponsesProducer.java:
##########
@@ -134,46 +162,109 @@ private void processInternal(Exchange exchange) throws Exception {
         if (ObjectHelper.isNotEmpty(previousResponseId)) {
             paramsBuilder.previousResponseId(previousResponseId);
         }
+        String conversationId = resolveParameter(in, OpenAIConstants.CONVERSATION_ID, config.getConversationId(),
+                String.class);
+        if (ObjectHelper.isNotEmpty(conversationId)) {
+            paramsBuilder.conversation(conversationId);
+        }
+        if (config.isBackground()) {
+            // a background response is only reachable later if the server stores it
+            paramsBuilder.background(true).store(true);
+        }
 
         OpenAIResponsesSupport.applyBuiltinTools(paramsBuilder, config.getBuiltinTools(),
                 config.getFileSearchVectorStoreIds());
         OpenAIResponsesSupport.applyHostedMcpTools(paramsBuilder, config.getHostedMcpTools());
         OpenAIResponsesSupport.applyAdditionalBodyProperties(paramsBuilder, config.getAdditionalBodyProperty());
 
+        // the MCP servers and route tools of the endpoint are sent as function tools
+        List<ChatCompletionFunctionTool> tools = getEndpoint().getMcpToolState().tools();
+        tools.forEach(tool -> paramsBuilder.addTool(OpenAIResponsesSupport.toFunctionTool(tool)));
+
+        ResponseCreateParams params;
         Class<?> responseClass = resolveOutputClass(in, outputClass);
         if (responseClass != null) {
-            processStructured(exchange, config, paramsBuilder, responseClass, model);
-            return;
+            params = paramsBuilder.text(responseClass).build().rawParams();
+        } else {
+            if (ObjectHelper.isNotEmpty(jsonSchema)) {
+                OpenAIResponsesSupport.applyJsonSchemaTextFormat(paramsBuilder, jsonSchema);
+            }
+            params = paramsBuilder.build();
         }
-        if (ObjectHelper.isNotEmpty(jsonSchema)) {
-            OpenAIResponsesSupport.applyJsonSchemaTextFormat(paramsBuilder, jsonSchema);
+
+        if (!tools.isEmpty() && config.isAutoToolExecution()) {
+            if (config.isBackground()) {
+                throw new IllegalArgumentException(
+                        "background cannot be combined with automatic tool execution, the tool loop needs each answer. "
+                                                   + "Set autoToolExecution=false to handle the function calls in the route");
+            }
+            processToolLoop(exchange, config, params, inputSpec.items(), model);
+            return;
         }
 
-        ResponseCreateParams params = paramsBuilder.build();
         Response response = createResponse(exchange, model, params);
-        finishExchange(exchange, config, response, OpenAIResponsesSupport.extractAssistantText(response));
+        List<ResponseFunctionToolCall> functionCalls = OpenAIResponsesSupport.extractFunctionCalls(response);
+        // with autoToolExecution=false the route handles the function calls requested by the model
+        Object body = functionCalls.isEmpty() ? OpenAIResponsesSupport.extractAssistantText(response) : functionCalls;
+        finishExchange(exchange, config, response, body);
     }
 
-    private void processStructured(
-            Exchange exchange, OpenAIConfiguration config, ResponseCreateParams.Builder paramsBuilder,
-            Class<?> responseClass, String model)
+    /**
+     * Runs the tool loop: the function calls requested by the model are executed on the MCP servers and route tools of
+     * the endpoint, and their results are sent back with the conversation so far until the model answers.
+     */
+    private void processToolLoop(
+            Exchange exchange, OpenAIConfiguration config, ResponseCreateParams params, List<ResponseInputItem> input,
+            String model)
             throws Exception {
-        StructuredResponseCreateParams<?> structuredParams = paramsBuilder.text(responseClass).build();
-        Response raw = createStructuredResponse(exchange, model, structuredParams);
-        finishExchange(exchange, config, raw, OpenAIResponsesSupport.extractAssistantText(raw));
+        List<ResponseInputItem> conversation = new ArrayList<>(input);
+        List<String> toolCallsLog = new ArrayList<>();
+        int iteration = 0;
+
+        while (true) {
+            Response response = createResponse(exchange, model, params.toBuilder().inputOfResponse(conversation).build());

Review Comment:
   Question on the tool loop combined with `conversationId` (listed as untested in the PR description): every iteration re-sends the whole accumulated `conversation` list — the original user input, the `function_call` items and the `function_call_output` items.
   
   With `previous_response_id` that works, because each iteration chains onto the *same* prior response. With `conversation=conv_…` the server appends the input items of every request to the stored conversation, so iteration 2 would store the user message and the `function_call` items a second time (and OpenAI may reject re-submitted `fc_…` ids).
   
   Suggest either sending only the new `function_call_output` items on subsequent iterations when `conversationId` is set, or documenting that `conversationId` should not be combined with automatic tool execution for now.



##########
test-infra/camel-test-infra-openai-mock/src/main/java/org/apache/camel/test/infra/openai/mock/ResponsesRequestHandler.java:
##########
@@ -30,6 +33,7 @@
 public class ResponsesRequestHandler {
 
     private final List<MockExpectation> expectations;
+    private final Map<String, ObjectNode> storedResponses = new ConcurrentHashMap<>();

Review Comment:
   Nit: `storedResponses` is never cleared, unlike `receivedRequests` which is reset in `beforeEach`. Harmless per test class, but ids from one test stay retrievable in the next.



-- 
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