CAMEL-24614: camel-langchain4j-agent - clear error when no agent can be resolved (validated at process time) - #26077
Conversation
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 9 tested, 27 compile-only — current: 9 all testedMaveniverse Scalpel detected 36 affected modules (current approach: 9).
|
… resolved When an endpoint has no agent, agentConfiguration or agentFactory and no registry bean matches its agentId, lookupByNameAndType returns null and the producer later threw an opaque NullPointerException in process() at agent.chat(). Validate in doStart that an agent (or agentFactory) is available and throw a clear IllegalArgumentException naming the endpoint and how to configure it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ka4dAcJMpxahMfk3kmG5Ls Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
e9c564b to
39321e5
Compare
…time to support late endpoint configuration The producer resolved the agent once at doStart() and failed fast there when nothing resolved. That broke the supported pattern of configuring an agent on the endpoint after the route has started (e.g. tests and dynamic wiring set endpoint.getConfiguration().setAgent(...) post-start). Move the resolution and the clear error to process(): re-resolve from the endpoint configuration when no agent/agentFactory is set, and throw a descriptive IllegalArgumentException instead of an opaque NullPointerException only when nothing can be resolved. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011y1gCrVvA3FowKoRM9EvmT Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
|
Heads-up on the latest push: the approach changed in response to CI. The original commit failed fast in Claude Code on behalf of oscerd |
gnodet
left a comment
There was a problem hiding this comment.
Solid fix. The process()-time validation correctly preserves the supported late-configuration pattern while giving a clear IllegalArgumentException instead of an opaque NPE.
The test covers the happy path for the error message. All ast-grep findings on this file (broad-exception-catch at lines 199, 459, 536, 575, 691) are pre-existing and not introduced by this PR.
No issues found.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
🔄 Backport BotPort PRs created:
ℹ️ If you push additional commits after |
Issue
CAMEL-24614
Problem
LangChain4jAgentProducerresolves the agent from the registry withlookupByNameAndType(agentId, Agent.class), which returnsnullwhen no matching bean exists. With noagent/agentConfiguration/agentFactoryconfigured and no registry bean namedagentId,agentstays
nullandprocess()fails with an opaqueNullPointerExceptionatagent.chat(...)instead ofa clear configuration error.
Fix
Resolve the agent and report the error in
process()rather than atdoStart(). When noagent/agentFactoryis set, re-resolve from the endpoint configuration(
endpoint.getConfiguration().getAgent()) and, only if that still yields nothing, throw a clearIllegalArgumentExceptionnaming the endpoint and the configuration options.Doing this at process time (instead of failing fast in
doStart()) preserves the supported pattern ofconfiguring an agent on the endpoint after the route has started — used by dynamic wiring and by
several existing tests that call
endpoint.getConfiguration().setAgent(...)post-start. Failing fast indoStart()broke those flows (e.g.LangChain4jAgentMcpToolProviderFilterTest).Testing
LangChain4jAgentMissingAgentTestsends an exchange through a route whose endpoint has anunresolvable agent and asserts the clear
IllegalArgumentException("No agent could be resolved")surfaces on the exchange.
camel-langchain4j-agentunit suite green (includes the late-configuration tests).mvn -Psourcecheck validategreen.🤖 Generated with Claude Code