Skip to content

CAMEL-23382: camel-ai-tool - align spring-ai-chat with camel-ai-tool …#24862

Merged
davsclaus merged 1 commit into
apache:mainfrom
zbendhiba:CAMEL-23382-step3-spring-ai-chat
Jul 21, 2026
Merged

CAMEL-23382: camel-ai-tool - align spring-ai-chat with camel-ai-tool …#24862
davsclaus merged 1 commit into
apache:mainfrom
zbendhiba:CAMEL-23382-step3-spring-ai-chat

Conversation

@zbendhiba

Copy link
Copy Markdown
Contributor

…component

Description

Step 3: Wire camel-spring-ai-chat producer to discover tools from AiToolRegistry

Summary

Migrate the camel-spring-ai-chat producer from camel-spring-ai-tools (CamelToolExecutorCache) to the unified camel-ai-tool module (AiToolRegistry).

  • Bridge adapter: new AiToolSpecToSpringAi converts AiToolSpec → Spring AI ToolCallback, with explicit handling of all AiToolResult subtypes and WARN logging on execution errors
  • Tool deduplication: uses LinkedHashSet to prevent duplicate tools when tags overlap
  • Dependency swap: camel-spring-ai-toolscamel-ai-tool in pom.xml
  • Tests: migrated to AiToolRegistry, replaced Thread.sleep() with Awaitility
  • Docs: updated component docs and upgrade guide with migration instructions

No changes to other modules.

Roadmap

  • Step 1: Create the new camel-ai-tool module - CAMEL-23382: camel-ai-tool - create unified AI tool component #24473
  • Step 2: Wire camel-langchain4j-agent producer to AiToolRegistry
  • Step 3 (this PR): Wire camel-spring-ai-chat producer to AiToolRegistry
  • Step 4: Wire camel-langchain4j-tools producer to AiToolRegistry
  • Step 5: Deprecate camel-langchain4j-tools consumer, remove camel-spring-ai-tools
  • Step 6: Add tool support to camel-openai

…component

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

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

Claude Code on behalf of gnodet

Clean migration — well-structured step in the `camel-spring-ai-tools` → `camel-ai-tool` unification roadmap.

Changes reviewed:

Bridge adapter (`AiToolSpecToSpringAi`)

  • Converts framework-agnostic `AiToolSpec` → Spring AI `ToolCallback` via `FunctionToolCallback.builder()`
  • Exhaustive `AiToolResult` subtype handling: `Success` returns value, `ArgumentError` returns message, `ExecutionError` logs WARN and returns generic error
  • Exchange lifecycle is clean: `createExchange()` in try, `releaseExchange()` in finally
  • Properly passes `inputSchema` when the spec has a JSON schema

Producer wiring (`SpringAiChatProducer`)

  • `CamelToolExecutorCache.getInstance()` → `AiToolRegistry.getOrCreate(getCamelContext())` — context-scoped instead of singleton
  • Tool dedup via `LinkedHashSet` prevents duplicates when tags overlap (e.g., a tool tagged `weather,info` appearing in both tag queries)
  • Clean stream pipeline: collect unique specs → map to ToolCallback

Tests

  • `Thread.sleep(500/1000)` → `Awaitility.await().atMost(5/10, SECONDS).untilAsserted(...)` — proper async assertion
  • Removed manual `@AfterEach` cache cleanup — registry lifecycle tied to CamelContext
  • `testMultipleToolsWithSameTag` → `testToolExecutionWithDifferentInput` — better name for what it actually tests

Documentation

  • Component docs: all `spring-ai-tools` references → `ai-tool`, xref links updated
  • Upgrade guide: clear before/after migration example, notes that chat producer URI is unchanged, lists the dependency swap

No issues found.

@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 requested a review from Croway July 17, 2026 15:31
@github-actions

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat
  • docs

🔬 Scalpel shadow comparison — Scalpel: 10 tested, 28 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 10 modules (2 direct + 8 downstream), skip tests for 28 (generated code, meta-modules)

Modules Scalpel would test (10)
  • camel-jbang-mcp
  • camel-jbang-plugin-mcp
  • camel-jbang-plugin-route-parser
  • camel-jbang-plugin-tui
  • camel-jbang-plugin-validate
  • camel-launcher-container
  • camel-spring-ai-chat
  • camel-yaml-dsl-validator
  • camel-yaml-dsl-validator-maven-plugin
  • docs
Modules with tests skipped (28)
  • 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
  • dummy-component

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

⚠️ Some tests are disabled on GitHub Actions (@DisabledIfSystemProperty(named = "ci.env.name")) and require manual verification:

  • components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat: 21 test(s) disabled on GitHub Actions
All tested modules (38 modules)
  • 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

⚙️ View full build and test results

@oscerd oscerd 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.

LGTM. Nice migration — routing spring-ai-chat through the unified AiToolRegistry/AiToolExecutor rather than its own tool-call handling, and importantly it preserves the security hardening: the bridge passes the raw untrusted LLM args map straight to AiToolExecutor.execute(...) (AiToolSpecToSpringAi.java:46), which drops undeclared args, validates required ones, and rejects camel*/org.apache.camel.* names case-insensitively before setHeader — the CVE-2025-27636 guard — so there's no raw unfiltered header map in the production path. It also follows AiToolResult's note by returning a generic "Tool execution failed" to the LLM for ExecutionError (logging the detail at WARN) while surfacing only framework-generated ArgumentError messages. Tests present, Thread.sleep→Awaitility, upgrade-guide entry added, CI green.

Reviewed with Claude Code on behalf of Andrea Cosentino. This review was generated by an AI agent and may contain inaccuracies; please verify all suggestions before applying.

@davsclaus davsclaus added this to the 4.22.0 milestone Jul 21, 2026
@davsclaus davsclaus added the enhancement New feature or request label Jul 21, 2026
@davsclaus
davsclaus merged commit 0921a8b into apache:main Jul 21, 2026
6 checks passed
@zbendhiba
zbendhiba deleted the CAMEL-23382-step3-spring-ai-chat branch July 21, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

components docs enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants