This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 74cf6a2bbd38 CAMEL-26584: camel-aws-bedrock - clear the retrieve token
on the last page (#29157)
74cf6a2bbd38 is described below
commit 74cf6a2bbd381621c6445f70fd7581e77e56686b
Author: Andrea Cosentino <[email protected]>
AuthorDate: Wed Nov 4 16:27:00 2026 +0100
CAMEL-26584: camel-aws-bedrock - clear the retrieve token on the last page
(#29157)
Co-authored-by: OpenAI Codex <[email protected]>
---
.../agentruntime/BedrockAgentRuntimeProducer.java | 4 ++
.../BedrockAgentRuntimeProducerRetrieveTest.java | 58 ++++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 9 ++++
3 files changed, 71 insertions(+)
diff --git
a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/agentruntime/BedrockAgentRuntimeProducer.java
b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/agentruntime/BedrockAgentRuntimeProducer.java
index e25ca7f615c6..f69e4b5aa9a5 100644
---
a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/agentruntime/BedrockAgentRuntimeProducer.java
+++
b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/agentruntime/BedrockAgentRuntimeProducer.java
@@ -272,9 +272,13 @@ public class BedrockAgentRuntimeProducer extends
DefaultProducer {
message.setHeader(BedrockAgentRuntimeConstants.RETRIEVED_RESULTS,
results);
if (ObjectHelper.isNotEmpty(response.nextToken())) {
message.setHeader(BedrockAgentRuntimeConstants.NEXT_TOKEN,
response.nextToken());
+ } else {
+ message.removeHeader(BedrockAgentRuntimeConstants.NEXT_TOKEN);
}
if (ObjectHelper.isNotEmpty(response.guardrailActionAsString())) {
message.setHeader(BedrockAgentRuntimeConstants.RETRIEVE_GUARDRAIL_ACTION,
response.guardrailActionAsString());
+ } else {
+
message.removeHeader(BedrockAgentRuntimeConstants.RETRIEVE_GUARDRAIL_ACTION);
}
message.setBody(results);
}
diff --git
a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/agentruntime/BedrockAgentRuntimeProducerRetrieveTest.java
b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/agentruntime/BedrockAgentRuntimeProducerRetrieveTest.java
index bfb17ee3dcaa..6694d8a7366f 100644
---
a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/agentruntime/BedrockAgentRuntimeProducerRetrieveTest.java
+++
b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/agentruntime/BedrockAgentRuntimeProducerRetrieveTest.java
@@ -47,6 +47,7 @@ import
software.amazon.awssdk.services.bedrockagentruntime.model.RetrieveRespons
import software.amazon.awssdk.services.bedrockagentruntime.model.SearchType;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -54,6 +55,7 @@ import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
public class BedrockAgentRuntimeProducerRetrieveTest {
@@ -186,6 +188,62 @@ public class BedrockAgentRuntimeProducerRetrieveTest {
assertEquals("page-2-token",
result.getMessage().getHeader(BedrockAgentRuntimeConstants.NEXT_TOKEN));
}
+ @Test
+ public void retrieveClearsNextTokenOnLastPage() {
+ assertLastPageClearsNextToken(null);
+ }
+
+ @Test
+ public void retrieveClearsEmptyNextTokenOnLastPage() {
+ assertLastPageClearsNextToken("");
+ }
+
+ private void assertLastPageClearsNextToken(String nextToken) {
+ KnowledgeBaseRetrievalResult chunk =
KnowledgeBaseRetrievalResult.builder()
+ .content(RetrievalResultContent.builder().text("last
chunk").build())
+ .score(0.87)
+ .build();
+
when(syncClient.retrieve(any(RetrieveRequest.class))).thenAnswer(invocation -> {
+ capturedRequest.set(invocation.getArgument(0,
RetrieveRequest.class));
+ return
RetrieveResponse.builder().retrievalResults(chunk).nextToken(nextToken).guardrailAction("NONE").build();
+ });
+
+ Exchange result = template.send("direct:retrieve", exchange -> {
+ exchange.getMessage().setBody("what is camel?");
+
exchange.getMessage().setHeader(BedrockAgentRuntimeConstants.NEXT_TOKEN,
"last-page-token");
+ exchange.getMessage().setHeader("correlationId", "request-1");
+ });
+
+ assertNull(result.getException());
+ assertEquals("last-page-token", capturedRequest.get().nextToken());
+
assertFalse(result.getMessage().getHeaders().containsKey(BedrockAgentRuntimeConstants.NEXT_TOKEN));
+ assertEquals(List.of(chunk), result.getMessage().getBody());
+ assertSame(result.getMessage().getBody(),
+
result.getMessage().getHeader(BedrockAgentRuntimeConstants.RETRIEVED_RESULTS));
+ assertEquals("NONE",
result.getMessage().getHeader(BedrockAgentRuntimeConstants.RETRIEVE_GUARDRAIL_ACTION));
+ assertEquals("request-1",
result.getMessage().getHeader("correlationId"));
+ }
+
+ @Test
+ public void retrieveClearsAbsentGuardrailAction() {
+ when(syncClient.retrieve(any(RetrieveRequest.class))).thenReturn(
+
RetrieveResponse.builder().nextToken("next-page-token").build());
+
+ Exchange result = template.send("direct:retrieve", exchange -> {
+ exchange.getMessage().setBody("what is camel?");
+
exchange.getMessage().setHeader(BedrockAgentRuntimeConstants.RETRIEVE_GUARDRAIL_ACTION,
"INTERVENED");
+ exchange.getMessage().setHeader("correlationId", "request-1");
+ });
+
+ assertNull(result.getException());
+
assertFalse(result.getMessage().getHeaders().containsKey(BedrockAgentRuntimeConstants.RETRIEVE_GUARDRAIL_ACTION));
+ assertEquals("next-page-token",
result.getMessage().getHeader(BedrockAgentRuntimeConstants.NEXT_TOKEN));
+ assertEquals(List.of(), result.getMessage().getBody());
+ assertSame(result.getMessage().getBody(),
+
result.getMessage().getHeader(BedrockAgentRuntimeConstants.RETRIEVED_RESULTS));
+ assertEquals("request-1",
result.getMessage().getHeader("correlationId"));
+ }
+
@Test
public void retrieveSendsMapBodyAsJson() {
Map<String, Object> body = new LinkedHashMap<>();
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index e4b731389b10..e214e81ac9f6 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -904,6 +904,15 @@ If you replaced these dependencies to use another HTTP
client implementation, na
`software.amazon.awssdk.http.service.impl` (synchronous clients) or
`software.amazon.awssdk.http.async.service.impl`
(asynchronous clients): Camel then leaves the choice of the HTTP client to the
AWS SDK.
+=== camel-aws-bedrock - retrieval pagination
+
+The `retrieve` operation of `aws-bedrock-agent-runtime` now removes the
+`CamelAwsBedrockAgentRuntimeNextToken` header when the response has no
continuation token.
+Previously, an incoming token could remain on the final page. Pagination loops
should stop
+when this header is absent.
+The `CamelAwsBedrockAgentRuntimeRetrieveGuardrailAction` header is also
removed when the response
+has no guardrail action, so an action from an earlier page cannot survive.
+
=== camel-aws-bedrock - the invoke operations send the body, not its toString()
The invoke operations of `aws-bedrock` now convert the message body to bytes,
so a byte[], an InputStream or a file is