This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 4a68d8fd2344f531a80f9cd50cf46c9a75cac5ed
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Thu Aug 7 13:03:21 2025 +0200

    CAMEL-22326: allow providing factories for creating agents
---
 .../catalog/components/langchain4j-agent.json      | 14 +++++----
 .../camel-ai/camel-langchain4j-agent-api/pom.xml   |  4 +++
 .../langchain4j/agent/api/AgentFactory.java        | 34 ++++++++++++++++++++++
 .../agent/LangChain4jAgentComponentConfigurer.java |  8 ++++-
 .../LangChain4jAgentConfigurationConfigurer.java   |  6 ++++
 .../agent/LangChain4jAgentEndpointConfigurer.java  |  8 ++++-
 .../agent/LangChain4jAgentEndpointUriFactory.java  |  3 +-
 .../langchain4j/agent/langchain4j-agent.json       | 14 +++++----
 .../agent/LangChain4jAgentConfiguration.java       | 18 ++++++++++++
 .../agent/LangChain4jAgentProducer.java            | 14 ++++++++-
 .../Langchain4jAgentComponentBuilderFactory.java   | 17 +++++++++++
 .../LangChain4jAgentEndpointBuilderFactory.java    | 30 +++++++++++++++++++
 12 files changed, 154 insertions(+), 16 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/langchain4j-agent.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/langchain4j-agent.json
index 528c6f36f70..2ead8d34a7b 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/langchain4j-agent.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/langchain4j-agent.json
@@ -25,10 +25,11 @@
   },
   "componentProperties": {
     "agent": { "index": 0, "kind": "property", "displayName": "Agent", 
"group": "producer", "label": "", "required": false, "type": "object", 
"javaType": "org.apache.camel.component.langchain4j.agent.api.Agent", 
"deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "The agent to use for the 
component" },
-    "configuration": { "index": 1, "kind": "property", "displayName": 
"Configuration", "group": "producer", "label": "", "required": false, "type": 
"object", "javaType": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"deprecated": false, "autowired": false, "secret": false, "description": "The 
configuration" },
-    "lazyStartProducer": { "index": 2, "kind": "property", "displayName": 
"Lazy Start Producer", "group": "producer", "label": "producer", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": false, "description": 
"Whether the producer should be started lazy (on the first message). By 
starting lazy you can use this to allow CamelContext and routes to startup in 
situations where a producer may otherwise fail [...]
-    "tags": { "index": 3, "kind": "property", "displayName": "Tags", "group": 
"producer", "label": "", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "Tags for discovering and 
calling Camel route tools" },
-    "autowiredEnabled": { "index": 4, "kind": "property", "displayName": 
"Autowired Enabled", "group": "advanced", "label": "advanced", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": true, "description": 
"Whether autowiring is enabled. This is used for automatic autowiring options 
(the option must be marked as autowired) by looking up in the registry to find 
if there is a single instance of matching t [...]
+    "agentFactory": { "index": 1, "kind": "property", "displayName": "Agent 
Factory", "group": "producer", "label": "", "required": false, "type": 
"object", "javaType": 
"org.apache.camel.component.langchain4j.agent.api.AgentFactory", "deprecated": 
false, "deprecationNote": "", "autowired": true, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "The agent factory to us 
[...]
+    "configuration": { "index": 2, "kind": "property", "displayName": 
"Configuration", "group": "producer", "label": "", "required": false, "type": 
"object", "javaType": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"deprecated": false, "autowired": false, "secret": false, "description": "The 
configuration" },
+    "lazyStartProducer": { "index": 3, "kind": "property", "displayName": 
"Lazy Start Producer", "group": "producer", "label": "producer", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": false, "description": 
"Whether the producer should be started lazy (on the first message). By 
starting lazy you can use this to allow CamelContext and routes to startup in 
situations where a producer may otherwise fail [...]
+    "tags": { "index": 4, "kind": "property", "displayName": "Tags", "group": 
"producer", "label": "", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "Tags for discovering and 
calling Camel route tools" },
+    "autowiredEnabled": { "index": 5, "kind": "property", "displayName": 
"Autowired Enabled", "group": "advanced", "label": "advanced", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": true, "description": 
"Whether autowiring is enabled. This is used for automatic autowiring options 
(the option must be marked as autowired) by looking up in the registry to find 
if there is a single instance of matching t [...]
   },
   "headers": {
     "CamelLangChain4jAgentSystemMessage": { "index": 0, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": 
false, "secret": false, "description": "The system prompt.", "constantName": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgent$Headers#SYSTEM_MESSAGE"
 },
@@ -37,7 +38,8 @@
   "properties": {
     "agentId": { "index": 0, "kind": "path", "displayName": "Agent Id", 
"group": "producer", "label": "", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", 
"autowired": false, "secret": false, "description": "The Agent id" },
     "agent": { "index": 1, "kind": "parameter", "displayName": "Agent", 
"group": "producer", "label": "", "required": false, "type": "object", 
"javaType": "org.apache.camel.component.langchain4j.agent.api.Agent", 
"deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "The agent to use for the 
component" },
-    "tags": { "index": 2, "kind": "parameter", "displayName": "Tags", "group": 
"producer", "label": "", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "Tags for discovering and 
calling Camel route tools" },
-    "lazyStartProducer": { "index": 3, "kind": "parameter", "displayName": 
"Lazy Start Producer", "group": "producer (advanced)", "label": 
"producer,advanced", "required": false, "type": "boolean", "javaType": 
"boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the producer should be started 
lazy (on the first message). By starting lazy you can use this to allow 
CamelContext and routes to startup in situations where a produc [...]
+    "agentFactory": { "index": 2, "kind": "parameter", "displayName": "Agent 
Factory", "group": "producer", "label": "", "required": false, "type": 
"object", "javaType": 
"org.apache.camel.component.langchain4j.agent.api.AgentFactory", "deprecated": 
false, "deprecationNote": "", "autowired": true, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "The agent factory to u 
[...]
+    "tags": { "index": 3, "kind": "parameter", "displayName": "Tags", "group": 
"producer", "label": "", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "Tags for discovering and 
calling Camel route tools" },
+    "lazyStartProducer": { "index": 4, "kind": "parameter", "displayName": 
"Lazy Start Producer", "group": "producer (advanced)", "label": 
"producer,advanced", "required": false, "type": "boolean", "javaType": 
"boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the producer should be started 
lazy (on the first message). By starting lazy you can use this to allow 
CamelContext and routes to startup in situations where a produc [...]
   }
 }
diff --git a/components/camel-ai/camel-langchain4j-agent-api/pom.xml 
b/components/camel-ai/camel-langchain4j-agent-api/pom.xml
index 0d4f473eace..b875f4dd599 100644
--- a/components/camel-ai/camel-langchain4j-agent-api/pom.xml
+++ b/components/camel-ai/camel-langchain4j-agent-api/pom.xml
@@ -48,6 +48,10 @@
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-api</artifactId>
+        </dependency>
     </dependencies>
 
 </project>
\ No newline at end of file
diff --git 
a/components/camel-ai/camel-langchain4j-agent-api/src/main/java/org/apache/camel/component/langchain4j/agent/api/AgentFactory.java
 
b/components/camel-ai/camel-langchain4j-agent-api/src/main/java/org/apache/camel/component/langchain4j/agent/api/AgentFactory.java
new file mode 100644
index 00000000000..eb46faa3b4c
--- /dev/null
+++ 
b/components/camel-ai/camel-langchain4j-agent-api/src/main/java/org/apache/camel/component/langchain4j/agent/api/AgentFactory.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.langchain4j.agent.api;
+
+import org.apache.camel.CamelContextAware;
+
+/**
+ * Provides a common interface for factories of agents.
+ */
+public interface AgentFactory extends CamelContextAware {
+
+    /**
+     * Create a new agent instance (might be cached)
+     *
+     * @return           An agent instance
+     * @throws Exception if unable to create the agent
+     */
+    Agent createAgent() throws Exception;
+}
diff --git 
a/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentComponentConfigurer.java
 
b/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentComponentConfigurer.java
index 339dc8578bf..319f695178b 100644
--- 
a/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentComponentConfigurer.java
+++ 
b/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentComponentConfigurer.java
@@ -31,6 +31,8 @@ public class LangChain4jAgentComponentConfigurer extends 
PropertyConfigurerSuppo
         LangChain4jAgentComponent target = (LangChain4jAgentComponent) obj;
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "agent": 
getOrCreateConfiguration(target).setAgent(property(camelContext, 
org.apache.camel.component.langchain4j.agent.api.Agent.class, value)); return 
true;
+        case "agentfactory":
+        case "agentFactory": 
getOrCreateConfiguration(target).setAgentFactory(property(camelContext, 
org.apache.camel.component.langchain4j.agent.api.AgentFactory.class, value)); 
return true;
         case "autowiredenabled":
         case "autowiredEnabled": 
target.setAutowiredEnabled(property(camelContext, boolean.class, value)); 
return true;
         case "configuration": target.setConfiguration(property(camelContext, 
org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration.class,
 value)); return true;
@@ -43,13 +45,15 @@ public class LangChain4jAgentComponentConfigurer extends 
PropertyConfigurerSuppo
 
     @Override
     public String[] getAutowiredNames() {
-        return new String[]{"agent"};
+        return new String[]{"agent", "agentFactory"};
     }
 
     @Override
     public Class<?> getOptionType(String name, boolean ignoreCase) {
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "agent": return 
org.apache.camel.component.langchain4j.agent.api.Agent.class;
+        case "agentfactory":
+        case "agentFactory": return 
org.apache.camel.component.langchain4j.agent.api.AgentFactory.class;
         case "autowiredenabled":
         case "autowiredEnabled": return boolean.class;
         case "configuration": return 
org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration.class;
@@ -65,6 +69,8 @@ public class LangChain4jAgentComponentConfigurer extends 
PropertyConfigurerSuppo
         LangChain4jAgentComponent target = (LangChain4jAgentComponent) obj;
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "agent": return getOrCreateConfiguration(target).getAgent();
+        case "agentfactory":
+        case "agentFactory": return 
getOrCreateConfiguration(target).getAgentFactory();
         case "autowiredenabled":
         case "autowiredEnabled": return target.isAutowiredEnabled();
         case "configuration": return target.getConfiguration();
diff --git 
a/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentConfigurationConfigurer.java
 
b/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentConfigurationConfigurer.java
index e250e084443..4e61552d23a 100644
--- 
a/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentConfigurationConfigurer.java
+++ 
b/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentConfigurationConfigurer.java
@@ -24,6 +24,8 @@ public class LangChain4jAgentConfigurationConfigurer extends 
org.apache.camel.su
         
org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration 
target = 
(org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration) 
obj;
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "agent": target.setAgent(property(camelContext, 
org.apache.camel.component.langchain4j.agent.api.Agent.class, value)); return 
true;
+        case "agentfactory":
+        case "agentFactory": target.setAgentFactory(property(camelContext, 
org.apache.camel.component.langchain4j.agent.api.AgentFactory.class, value)); 
return true;
         case "tags": target.setTags(property(camelContext, 
java.lang.String.class, value)); return true;
         default: return false;
         }
@@ -33,6 +35,8 @@ public class LangChain4jAgentConfigurationConfigurer extends 
org.apache.camel.su
     public Class<?> getOptionType(String name, boolean ignoreCase) {
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "agent": return 
org.apache.camel.component.langchain4j.agent.api.Agent.class;
+        case "agentfactory":
+        case "agentFactory": return 
org.apache.camel.component.langchain4j.agent.api.AgentFactory.class;
         case "tags": return java.lang.String.class;
         default: return null;
         }
@@ -43,6 +47,8 @@ public class LangChain4jAgentConfigurationConfigurer extends 
org.apache.camel.su
         
org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration 
target = 
(org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration) 
obj;
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "agent": return target.getAgent();
+        case "agentfactory":
+        case "agentFactory": return target.getAgentFactory();
         case "tags": return target.getTags();
         default: return null;
         }
diff --git 
a/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentEndpointConfigurer.java
 
b/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentEndpointConfigurer.java
index e3b50101ee9..a5643be2929 100644
--- 
a/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentEndpointConfigurer.java
+++ 
b/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentEndpointConfigurer.java
@@ -24,6 +24,8 @@ public class LangChain4jAgentEndpointConfigurer extends 
PropertyConfigurerSuppor
         LangChain4jAgentEndpoint target = (LangChain4jAgentEndpoint) obj;
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "agent": 
target.getConfiguration().setAgent(property(camelContext, 
org.apache.camel.component.langchain4j.agent.api.Agent.class, value)); return 
true;
+        case "agentfactory":
+        case "agentFactory": 
target.getConfiguration().setAgentFactory(property(camelContext, 
org.apache.camel.component.langchain4j.agent.api.AgentFactory.class, value)); 
return true;
         case "lazystartproducer":
         case "lazyStartProducer": 
target.setLazyStartProducer(property(camelContext, boolean.class, value)); 
return true;
         case "tags": target.getConfiguration().setTags(property(camelContext, 
java.lang.String.class, value)); return true;
@@ -33,13 +35,15 @@ public class LangChain4jAgentEndpointConfigurer extends 
PropertyConfigurerSuppor
 
     @Override
     public String[] getAutowiredNames() {
-        return new String[]{"agent"};
+        return new String[]{"agent", "agentFactory"};
     }
 
     @Override
     public Class<?> getOptionType(String name, boolean ignoreCase) {
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "agent": return 
org.apache.camel.component.langchain4j.agent.api.Agent.class;
+        case "agentfactory":
+        case "agentFactory": return 
org.apache.camel.component.langchain4j.agent.api.AgentFactory.class;
         case "lazystartproducer":
         case "lazyStartProducer": return boolean.class;
         case "tags": return java.lang.String.class;
@@ -52,6 +56,8 @@ public class LangChain4jAgentEndpointConfigurer extends 
PropertyConfigurerSuppor
         LangChain4jAgentEndpoint target = (LangChain4jAgentEndpoint) obj;
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "agent": return target.getConfiguration().getAgent();
+        case "agentfactory":
+        case "agentFactory": return 
target.getConfiguration().getAgentFactory();
         case "lazystartproducer":
         case "lazyStartProducer": return target.isLazyStartProducer();
         case "tags": return target.getConfiguration().getTags();
diff --git 
a/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentEndpointUriFactory.java
 
b/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentEndpointUriFactory.java
index 984f16790e3..bd83060cc1a 100644
--- 
a/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentEndpointUriFactory.java
+++ 
b/components/camel-ai/camel-langchain4j-agent/src/generated/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentEndpointUriFactory.java
@@ -23,8 +23,9 @@ public class LangChain4jAgentEndpointUriFactory extends 
org.apache.camel.support
     private static final Set<String> SECRET_PROPERTY_NAMES;
     private static final Set<String> MULTI_VALUE_PREFIXES;
     static {
-        Set<String> props = new HashSet<>(4);
+        Set<String> props = new HashSet<>(5);
         props.add("agent");
+        props.add("agentFactory");
         props.add("agentId");
         props.add("lazyStartProducer");
         props.add("tags");
diff --git 
a/components/camel-ai/camel-langchain4j-agent/src/generated/resources/META-INF/org/apache/camel/component/langchain4j/agent/langchain4j-agent.json
 
b/components/camel-ai/camel-langchain4j-agent/src/generated/resources/META-INF/org/apache/camel/component/langchain4j/agent/langchain4j-agent.json
index 528c6f36f70..2ead8d34a7b 100644
--- 
a/components/camel-ai/camel-langchain4j-agent/src/generated/resources/META-INF/org/apache/camel/component/langchain4j/agent/langchain4j-agent.json
+++ 
b/components/camel-ai/camel-langchain4j-agent/src/generated/resources/META-INF/org/apache/camel/component/langchain4j/agent/langchain4j-agent.json
@@ -25,10 +25,11 @@
   },
   "componentProperties": {
     "agent": { "index": 0, "kind": "property", "displayName": "Agent", 
"group": "producer", "label": "", "required": false, "type": "object", 
"javaType": "org.apache.camel.component.langchain4j.agent.api.Agent", 
"deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "The agent to use for the 
component" },
-    "configuration": { "index": 1, "kind": "property", "displayName": 
"Configuration", "group": "producer", "label": "", "required": false, "type": 
"object", "javaType": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"deprecated": false, "autowired": false, "secret": false, "description": "The 
configuration" },
-    "lazyStartProducer": { "index": 2, "kind": "property", "displayName": 
"Lazy Start Producer", "group": "producer", "label": "producer", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": false, "description": 
"Whether the producer should be started lazy (on the first message). By 
starting lazy you can use this to allow CamelContext and routes to startup in 
situations where a producer may otherwise fail [...]
-    "tags": { "index": 3, "kind": "property", "displayName": "Tags", "group": 
"producer", "label": "", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "Tags for discovering and 
calling Camel route tools" },
-    "autowiredEnabled": { "index": 4, "kind": "property", "displayName": 
"Autowired Enabled", "group": "advanced", "label": "advanced", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": true, "description": 
"Whether autowiring is enabled. This is used for automatic autowiring options 
(the option must be marked as autowired) by looking up in the registry to find 
if there is a single instance of matching t [...]
+    "agentFactory": { "index": 1, "kind": "property", "displayName": "Agent 
Factory", "group": "producer", "label": "", "required": false, "type": 
"object", "javaType": 
"org.apache.camel.component.langchain4j.agent.api.AgentFactory", "deprecated": 
false, "deprecationNote": "", "autowired": true, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "The agent factory to us 
[...]
+    "configuration": { "index": 2, "kind": "property", "displayName": 
"Configuration", "group": "producer", "label": "", "required": false, "type": 
"object", "javaType": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"deprecated": false, "autowired": false, "secret": false, "description": "The 
configuration" },
+    "lazyStartProducer": { "index": 3, "kind": "property", "displayName": 
"Lazy Start Producer", "group": "producer", "label": "producer", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": false, "description": 
"Whether the producer should be started lazy (on the first message). By 
starting lazy you can use this to allow CamelContext and routes to startup in 
situations where a producer may otherwise fail [...]
+    "tags": { "index": 4, "kind": "property", "displayName": "Tags", "group": 
"producer", "label": "", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "Tags for discovering and 
calling Camel route tools" },
+    "autowiredEnabled": { "index": 5, "kind": "property", "displayName": 
"Autowired Enabled", "group": "advanced", "label": "advanced", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": true, "description": 
"Whether autowiring is enabled. This is used for automatic autowiring options 
(the option must be marked as autowired) by looking up in the registry to find 
if there is a single instance of matching t [...]
   },
   "headers": {
     "CamelLangChain4jAgentSystemMessage": { "index": 0, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": 
false, "secret": false, "description": "The system prompt.", "constantName": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgent$Headers#SYSTEM_MESSAGE"
 },
@@ -37,7 +38,8 @@
   "properties": {
     "agentId": { "index": 0, "kind": "path", "displayName": "Agent Id", 
"group": "producer", "label": "", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", 
"autowired": false, "secret": false, "description": "The Agent id" },
     "agent": { "index": 1, "kind": "parameter", "displayName": "Agent", 
"group": "producer", "label": "", "required": false, "type": "object", 
"javaType": "org.apache.camel.component.langchain4j.agent.api.Agent", 
"deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "The agent to use for the 
component" },
-    "tags": { "index": 2, "kind": "parameter", "displayName": "Tags", "group": 
"producer", "label": "", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "Tags for discovering and 
calling Camel route tools" },
-    "lazyStartProducer": { "index": 3, "kind": "parameter", "displayName": 
"Lazy Start Producer", "group": "producer (advanced)", "label": 
"producer,advanced", "required": false, "type": "boolean", "javaType": 
"boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the producer should be started 
lazy (on the first message). By starting lazy you can use this to allow 
CamelContext and routes to startup in situations where a produc [...]
+    "agentFactory": { "index": 2, "kind": "parameter", "displayName": "Agent 
Factory", "group": "producer", "label": "", "required": false, "type": 
"object", "javaType": 
"org.apache.camel.component.langchain4j.agent.api.AgentFactory", "deprecated": 
false, "deprecationNote": "", "autowired": true, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "The agent factory to u 
[...]
+    "tags": { "index": 3, "kind": "parameter", "displayName": "Tags", "group": 
"producer", "label": "", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": 
"org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration", 
"configurationField": "configuration", "description": "Tags for discovering and 
calling Camel route tools" },
+    "lazyStartProducer": { "index": 4, "kind": "parameter", "displayName": 
"Lazy Start Producer", "group": "producer (advanced)", "label": 
"producer,advanced", "required": false, "type": "boolean", "javaType": 
"boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the producer should be started 
lazy (on the first message). By starting lazy you can use this to allow 
CamelContext and routes to startup in situations where a produc [...]
   }
 }
diff --git 
a/components/camel-ai/camel-langchain4j-agent/src/main/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentConfiguration.java
 
b/components/camel-ai/camel-langchain4j-agent/src/main/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentConfiguration.java
index 3b64a04dbd6..fa886ec0450 100644
--- 
a/components/camel-ai/camel-langchain4j-agent/src/main/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentConfiguration.java
+++ 
b/components/camel-ai/camel-langchain4j-agent/src/main/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentConfiguration.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.langchain4j.agent;
 
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.langchain4j.agent.api.Agent;
+import org.apache.camel.component.langchain4j.agent.api.AgentFactory;
 import org.apache.camel.spi.Configurer;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriParam;
@@ -31,6 +32,10 @@ public class LangChain4jAgentConfiguration implements 
Cloneable {
     @Metadata(autowired = true)
     private Agent agent;
 
+    @UriParam(description = "The agent factory to use for creating agents if 
no Agent is provided")
+    @Metadata(autowired = true)
+    private AgentFactory agentFactory;
+
     @UriParam(description = "Tags for discovering and calling Camel route 
tools")
     private String tags;
 
@@ -70,4 +75,17 @@ public class LangChain4jAgentConfiguration implements 
Cloneable {
     public void setAgent(Agent agent) {
         this.agent = agent;
     }
+
+    /**
+     * An agent factory creating the agents
+     *
+     * @return the instance of the agent factory in use
+     */
+    public AgentFactory getAgentFactory() {
+        return agentFactory;
+    }
+
+    public void setAgentFactory(AgentFactory agentFactory) {
+        this.agentFactory = agentFactory;
+    }
 }
diff --git 
a/components/camel-ai/camel-langchain4j-agent/src/main/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentProducer.java
 
b/components/camel-ai/camel-langchain4j-agent/src/main/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentProducer.java
index d68f2e526d9..c748c90b954 100644
--- 
a/components/camel-ai/camel-langchain4j-agent/src/main/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentProducer.java
+++ 
b/components/camel-ai/camel-langchain4j-agent/src/main/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentProducer.java
@@ -29,6 +29,7 @@ import dev.langchain4j.service.tool.ToolProviderResult;
 import org.apache.camel.Exchange;
 import org.apache.camel.InvalidPayloadRuntimeException;
 import org.apache.camel.component.langchain4j.agent.api.Agent;
+import org.apache.camel.component.langchain4j.agent.api.AgentFactory;
 import 
org.apache.camel.component.langchain4j.tools.spec.CamelToolExecutorCache;
 import 
org.apache.camel.component.langchain4j.tools.spec.CamelToolSpecification;
 import org.apache.camel.support.DefaultProducer;
@@ -44,6 +45,7 @@ public class LangChain4jAgentProducer extends DefaultProducer 
{
 
     private final LangChain4jAgentEndpoint endpoint;
     private final ObjectMapper objectMapper = new ObjectMapper();
+    private AgentFactory agentFactory;
 
     public LangChain4jAgentProducer(LangChain4jAgentEndpoint endpoint) {
         super(endpoint);
@@ -55,7 +57,12 @@ public class LangChain4jAgentProducer extends 
DefaultProducer {
         Object messagePayload = exchange.getIn().getBody();
         ObjectHelper.notNull(messagePayload, "body");
 
-        Agent agent = endpoint.getConfiguration().getAgent();
+        Agent agent;
+        if (agentFactory != null) {
+            agent = agentFactory.createAgent();
+        } else {
+            agent = endpoint.getConfiguration().getAgent();
+        }
 
         AiAgentBody aiAgentBody = processBody(messagePayload, exchange);
 
@@ -194,5 +201,10 @@ public class LangChain4jAgentProducer extends 
DefaultProducer {
     @Override
     protected void doStart() throws Exception {
         super.doStart();
+
+        agentFactory = endpoint.getConfiguration().getAgentFactory();
+        if (agentFactory != null) {
+            agentFactory.setCamelContext(this.endpoint.getCamelContext());
+        }
     }
 }
diff --git 
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Langchain4jAgentComponentBuilderFactory.java
 
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Langchain4jAgentComponentBuilderFactory.java
index bcf7fce82a3..543885e0610 100644
--- 
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Langchain4jAgentComponentBuilderFactory.java
+++ 
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Langchain4jAgentComponentBuilderFactory.java
@@ -66,6 +66,22 @@ public interface Langchain4jAgentComponentBuilderFactory {
             return this;
         }
     
+        /**
+         * The agent factory to use for creating agents if no Agent is 
provided.
+         * 
+         * The option is a:
+         * 
&lt;code&gt;org.apache.camel.component.langchain4j.agent.api.AgentFactory&lt;/code&gt;
 type.
+         * 
+         * Group: producer
+         * 
+         * @param agentFactory the value to set
+         * @return the dsl builder
+         */
+        default Langchain4jAgentComponentBuilder 
agentFactory(org.apache.camel.component.langchain4j.agent.api.AgentFactory 
agentFactory) {
+            doSetProperty("agentFactory", agentFactory);
+            return this;
+        }
+    
         /**
          * The configuration.
          * 
@@ -165,6 +181,7 @@ public interface Langchain4jAgentComponentBuilderFactory {
                 Object value) {
             switch (name) {
             case "agent": getOrCreateConfiguration((LangChain4jAgentComponent) 
component).setAgent((org.apache.camel.component.langchain4j.agent.api.Agent) 
value); return true;
+            case "agentFactory": 
getOrCreateConfiguration((LangChain4jAgentComponent) 
component).setAgentFactory((org.apache.camel.component.langchain4j.agent.api.AgentFactory)
 value); return true;
             case "configuration": ((LangChain4jAgentComponent) 
component).setConfiguration((org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration)
 value); return true;
             case "lazyStartProducer": ((LangChain4jAgentComponent) 
component).setLazyStartProducer((boolean) value); return true;
             case "tags": getOrCreateConfiguration((LangChain4jAgentComponent) 
component).setTags((java.lang.String) value); return true;
diff --git 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/LangChain4jAgentEndpointBuilderFactory.java
 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/LangChain4jAgentEndpointBuilderFactory.java
index 098b7e805a0..1ce4c56ae4a 100644
--- 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/LangChain4jAgentEndpointBuilderFactory.java
+++ 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/LangChain4jAgentEndpointBuilderFactory.java
@@ -76,6 +76,36 @@ public interface LangChain4jAgentEndpointBuilderFactory {
             doSetProperty("agent", agent);
             return this;
         }
+        /**
+         * The agent factory to use for creating agents if no Agent is 
provided.
+         * 
+         * The option is a:
+         * 
<code>org.apache.camel.component.langchain4j.agent.api.AgentFactory</code> type.
+         * 
+         * Group: producer
+         * 
+         * @param agentFactory the value to set
+         * @return the dsl builder
+         */
+        default LangChain4jAgentEndpointBuilder 
agentFactory(org.apache.camel.component.langchain4j.agent.api.AgentFactory 
agentFactory) {
+            doSetProperty("agentFactory", agentFactory);
+            return this;
+        }
+        /**
+         * The agent factory to use for creating agents if no Agent is 
provided.
+         * 
+         * The option will be converted to a
+         * 
<code>org.apache.camel.component.langchain4j.agent.api.AgentFactory</code> type.
+         * 
+         * Group: producer
+         * 
+         * @param agentFactory the value to set
+         * @return the dsl builder
+         */
+        default LangChain4jAgentEndpointBuilder agentFactory(String 
agentFactory) {
+            doSetProperty("agentFactory", agentFactory);
+            return this;
+        }
         /**
          * Tags for discovering and calling Camel route tools.
          * 


Reply via email to