Skip to content

CAMEL-23467: camel-aws-bedrock - add invokeAgent and invokeInlineAgent operations#25086

Open
oscerd wants to merge 2 commits into
apache:mainfrom
oscerd:feature/CAMEL-23467-bedrock-invoke-agent
Open

CAMEL-23467: camel-aws-bedrock - add invokeAgent and invokeInlineAgent operations#25086
oscerd wants to merge 2 commits into
apache:mainfrom
oscerd:feature/CAMEL-23467-bedrock-invoke-agent

Conversation

@oscerd

@oscerd oscerd commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Motivation

CAMEL-23467. The aws-bedrock-agent-runtime component did not expose InvokeAgent (invoking a deployed Bedrock agent) or InvokeInlineAgent (defining the agent at invocation time) — the primary entry points for agent-based workflows on Bedrock.

Approach

Both APIs return event-stream responses, and the component already had a working precedent for that in invokeFlow: the AWS SDK async client, a response handler whose visitor collects the emitted events, awaited with join() and unwrapping the CompletionException that wraps AWS service exceptions. Both new operations follow that same shape rather than introducing parallel machinery.

Changes

  • Operations: invokeAgent and invokeInlineAgent added to BedrockAgentRuntimeOperations and wired into the producer.
  • Options (each overridable by header): agentId, agentAliasId, sessionId, streamOutputMode, and for the inline variant foundationModel / instruction. enableTrace is reused and its label/doc widened to cover agents.
  • Async client: provisioned for the two new operations, exactly as for invokeFlow (so users don't pay for a Netty client when only doing synchronous operations).
  • Event handling: all four ResponseStream events (chunk, trace, returnControl, files) are collected. Traces, return-control payloads, files and citations are published as headers. Citations arrive on the chunk attribution rather than as their own event, which is where they're picked up.
  • streamOutputMode: honored with the same semantics as the runtime component — complete (default) accumulates the chunks into a String body, chunks exposes the List<String>. Overridable per exchange by header.
  • Sessions: the agent APIs are session-based, so a session id is generated when neither config nor header supplies one, and the id actually used is always echoed back on CamelAwsBedrockAgentRuntimeSessionId so a route can continue the conversation.
  • POJO mode: pojoRequest=true accepts an InvokeAgentRequest / InvokeInlineAgentRequest unchanged — which is also how the richer inline options (action groups, knowledge bases, collaborators, guardrails) are reachable without adding a dozen URI options.
  • Docs: three new sections in aws-bedrock-agent-runtime-component.adoc plus the supported-operations list.

One thing worth flagging for review: invokeAgent and invokeInlineAgent use parallel but distinct SDK type families (PayloadPart/TracePart/… vs InlineAgentPayloadPart/InlineAgentTracePart/…). The collected traces/return-controls/files are therefore held as the SDK objects and the header metadata documents both variants, rather than pretending a single type applies.

Testing

BedrockAgentRuntimeProducerInvokeAgentTest9 tests, all passing — mirroring the existing invokeFlow test approach (mocked async client capturing the request):

  • request built from string body + endpoint config, for both operations
  • header overrides for agent id/alias/session/trace/endSession/memoryId, and for inline model/instruction
  • session id generated when not configured, and echoed back on the response
  • missing agentId / foundationModel produce a clear validation error
  • streamOutputMode branching shapes the body (String vs List), including the header override

The test uses AssertJ assertions and package-private visibility per project conventions. Note this required adding a test-scoped assertj-core dependency to camel-aws-bedrock — it was not on the module's test classpath. That mirrors how camel-aws2-sqs, camel-aws2-athena and camel-aws2-sts declare it, and the version is managed in parent/pom.xml, so no new version is introduced.

Full reactor mvn clean install -DskipTests from root: success, with catalog/DSL metadata regenerated.

Note on the regenerated aws-bedrock-agent metadata: that component declares headersClass = BedrockAgentRuntimeConstants.class (pre-existing), so adding constants there also regenerates its header metadata. I verified this is index renumbering plus the new entries — all existing Flow* headers remain present (15 → 26 headers, none removed).

Main-only (4.22.0), additive — no backport.

Claude Code on behalf of Andrea Cosentino (@oscerd).

🤖 Generated with Claude Code

…t operations

The aws-bedrock-agent-runtime component did not expose InvokeAgent (invoking a
deployed Bedrock agent) or InvokeInlineAgent (defining the agent at invocation
time), the primary entry points for agent-based workflows on Bedrock.

Both APIs return event streams, so they are implemented on the async client the
same way the existing invokeFlow operation is: a response handler whose visitor
collects the emitted events, awaited with join() and unwrapping the
CompletionException around AWS service exceptions.

- Add invokeAgent and invokeInlineAgent to BedrockAgentRuntimeOperations.
- Add agentId, agentAliasId, sessionId, streamOutputMode and the inline
  foundationModel/instruction options, each overridable by a header.
- Provision the async client for the two new operations, as done for invokeFlow.
- Collect the ResponseStream events (chunk, trace, returnControl, files) and
  publish traces, return-control payloads, files and citations as headers.
  Citations arrive on the chunk attribution rather than as their own event.
- Honor streamOutputMode: complete (default) accumulates the chunks into a
  String body, chunks exposes the List of chunks, matching the runtime component.
- The agent APIs are session based, so a session id is generated when none is
  configured, and the one used is always echoed back on the session id header.

invokeAgent and invokeInlineAgent use parallel but distinct SDK event types, so
the collected traces/returnControls/files are held as the SDK objects and the
header metadata documents both variants.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 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 have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@davsclaus davsclaus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice feature addition — the implementation cleanly follows the established invokeFlow patterns, and the test coverage is solid.

Two minor convention notes inline (non-blocking). This review does not replace specialized review tools such as CodeRabbit, Sourcery, or SonarCloud.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • catalog/camel-catalog
  • components/camel-aws/camel-aws-bedrock
  • dsl/camel-componentdsl
  • dsl/camel-endpointdsl

🔬 Scalpel shadow comparison — Scalpel: 12 tested, 26 compile-only — current: 9 all tested

Maveniverse Scalpel detected 38 affected modules (current approach: 9).

⚠️ Modules only in Scalpel (29)
  • 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

Skip-tests mode would test 12 modules (4 direct + 8 downstream), skip tests for 26 (generated code, meta-modules)

Modules Scalpel would test (12)
  • camel-aws-bedrock
  • 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-launcher-container
  • camel-yaml-dsl-validator
  • camel-yaml-dsl-validator-maven-plugin
Modules with tests skipped (26)
  • 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

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

All tested modules (38 modules)
  • Camel :: AWS2 Bedrock
  • 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 :: YAML DSL
  • Camel :: YAML DSL :: Deserializers
  • Camel :: YAML DSL :: Maven Plugins
  • Camel :: YAML DSL :: Validator
  • Camel :: YAML DSL :: Validator Maven Plugin

⚙️ View full build and test results

…test visibility

Per project conventions, converted BedrockAgentRuntimeProducerInvokeAgentTest to
AssertJ assertions and dropped the public modifier from the class and its
lifecycle/test methods. Adds the test-scoped assertj-core dependency, which was
not yet declared in camel-aws-bedrock (other camel-aws modules already declare
it the same way; the version is managed in the parent).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
@oscerd
oscerd requested a review from davsclaus July 24, 2026 12:04

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well-structured feature addition that cleanly follows the established invokeFlow patterns. The AgentInvocationResult inner class and joinAgentInvocation/resolveRequired helpers are good DRY extractions. Test coverage is solid (9 tests) and documentation is thorough.

Two minor consistency items:

1. streamOutputMode field initialization (low) — In BedrockAgentRuntimeConfiguration.java, the streamOutputMode field is declared as private String streamOutputMode; (defaults to null). The existing BedrockConfiguration (runtime component, line 78) initializes the same field: private String streamOutputMode = "complete";. The defaultValue = "complete" in @UriParam is metadata-only. The code works because prepareAgentResponse treats null as the complete case, but for consistency the field should be initialized:

private String streamOutputMode = "complete";

2. Async client Javadoc (low) — The setBedrockAgentRuntimeAsyncClient Javadoc still says "required for invokeFlow which streams events back" but the async client is now also required for invokeAgent and invokeInlineAgent (both call requireAsyncClient()). Should mention all three streaming operations.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

@davsclaus davsclaus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well-structured feature addition — the implementation cleanly follows the established invokeFlow patterns, the AgentInvocationResult inner class and joinAgentInvocation/resolveRequired/resolveSessionId helpers are good DRY extractions, and the test coverage is solid (9 tests).

The two minor items flagged by @gnodet (streamOutputMode field initialization and async client Javadoc) are the only remaining notes — both non-blocking.

This review does not replace specialized review tools such as CodeRabbit, Sourcery, or SonarCloud.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants