LangChain4j Agent
Send a message to an AI agent of LangChain4j, which can call Camel routes and MCP servers as tools, and return its answer.
What’s inside
-
LangChain4j Agent component, URI syntax:
langchain4j-agent:agentId
Please refer to the above links for usage and configuration details.
Maven coordinates
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-langchain4j-agent-starter</artifactId>
</dependency> Spring Boot Auto-Configuration
Providing an agent model
LangChain4j provider starters can create the ChatModel used by an agent. Add the provider’s -spring-boot-starter variant with Spring Boot 3 or its -spring-boot4-starter variant with Spring Boot 4, then inject the resulting model bean into Camel’s AgentConfiguration. The provider starter does not create Camel’s Agent or AgentConfiguration.
See the LangChain4j Spring Boot integration documentation for provider configuration, and the component documentation for creating and configuring a Camel agent.
The starter supports 27 options, which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
camel.component.langchain4j-agent.agent | The agent that answers the messages, an org.apache.camel.component.langchain4j.agent.api.Agent. It takes precedence over agentConfiguration, and agentFactory takes precedence over it. The option is a org.apache.camel.component.langchain4j.agent.api.Agent type. | Agent | |
camel.component.langchain4j-agent.agent-configuration | The settings of LangChain4j (chat model, chat memory, tools, RAG, guardrails, and so on) from which the producer creates the agent: an AgentWithMemory when a ChatMemoryProvider is set, otherwise an AgentWithoutMemory. The agent and agentFactory options take precedence over it. The option is a org.apache.camel.component.langchain4j.agent.api.AgentConfiguration type. | AgentConfiguration | |
camel.component.langchain4j-agent.agent-factory | The factory whose createAgent method the producer calls for each message, to create the agent that answers it. It takes precedence over agent and agentConfiguration. The option is a org.apache.camel.component.langchain4j.agent.api.AgentFactory type. | AgentFactory | |
camel.component.langchain4j-agent.api-key | The API key or access token of the provider, when the model is created from the provider. | String | |
camel.component.langchain4j-agent.autowired-enabled | 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 type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | Boolean |
camel.component.langchain4j-agent.base-url | The URL of the provider’s API (http://localhost:11434 for a local Ollama), when the model is created from the provider. The provider’s default when not set. | String | |
camel.component.langchain4j-agent.compensate-on-tool-errors | Whether LangChain4j runs the compensating actions when a tool fails: the methods annotated with CompensateFor for the tools that already ran. When set, it replaces the value of the agentConfiguration. Only works when Camel creates the agent, from agentConfiguration or provider. | Boolean | |
camel.component.langchain4j-agent.configuration | The configuration shared by the endpoints. Each endpoint starts from a copy of it. The option is a org.apache.camel.component.langchain4j.agent.LangChain4jAgentConfiguration type. | LangChain4jAgentConfiguration | |
camel.component.langchain4j-agent.custom-provider | The fully qualified class name of the LangChain4j model class of a provider that is not listed in provider (dev.langchain4j.model.jlama.JlamaChatModel), created from the options here through its builder() as a listed provider is. Set either provider or customProvider. | String | |
camel.component.langchain4j-agent.enabled | Whether to enable auto configuration of the langchain4j-agent component. This is enabled by default. | Boolean | |
camel.component.langchain4j-agent.execute-tools-concurrently | Whether LangChain4j runs the tools that the model requests in one response concurrently, on the executor of the agentConfiguration or else on a Camel thread pool; each route tool runs on a copy of the exchange. When set, it replaces the value of the agentConfiguration. Only works when Camel creates the agent, from agentConfiguration or provider. | Boolean | |
camel.component.langchain4j-agent.json-schema | The JSON schema that the answer of the model must follow, inline or as a resource (classpath:, file:, …). Camel sends it to the model as the response format, and the body is the answer as JSON text. Only works when Camel creates the agent, from agentConfiguration or provider, and not together with outputClass: otherwise the producer fails to start. | String | |
camel.component.langchain4j-agent.lazy-start-producer | 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 during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | Boolean |
camel.component.langchain4j-agent.max-tool-calling-round-trips | The maximum number of tool-calling round trips per message, each one model call and the tools that this call requests. A value above 0 replaces the value of the agentConfiguration; with 0, that value applies, or the LangChain4j default when it is not set either. Only works when Camel creates the agent, from agentConfiguration or provider. | 0 | Integer |
camel.component.langchain4j-agent.mcp-clients | The MCP (Model Context Protocol) clients, of type dev.langchain4j.mcp.client.McpClient, whose tools are offered to the model, as references to beans in the registry, for example #myMcpClient1,#myMcpClient2. The producer does not close them. | McpClient> | |
camel.component.langchain4j-agent.mcp-server | The MCP servers whose tools are offered to the model, as mcpServer.myServer.myProperty=myValue, where myServer is the name of the server; the producer creates a client per server when it starts and closes it when it stops. The properties are transportType (stdio by default, or http or streamableHttp, which both use the Streamable HTTP transport), command (comma-separated, for stdio), environment.myKey=myValue (for stdio), url (for HTTP), timeout (in seconds, 60 by default), logRequests, logResponses, and oauthProfile (the camel-oauth profile that supplies a bearer token for HTTP). This is a multi-value option with prefix: mcpServer. | Object> | |
camel.component.langchain4j-agent.model-name | The name of the model at the provider (qwen2.5, gpt-4o-mini, …), when the model is created from the provider. | String | |
camel.component.langchain4j-agent.model-properties | Provider-specific properties of the model, set on the model’s builder as they are (model.numPredict=512 for Ollama, model.maxTokens=1024 for OpenAI), when the model is created from the provider. This is a multi-value option with prefix: model. | Object> | |
camel.component.langchain4j-agent.output-class | The Java class, a POJO with public fields or getters, from which Camel derives the JSON schema that the answer of the model must follow. The body is the answer as JSON text, not an instance of the class. Only works when Camel creates the agent, from agentConfiguration or provider, and not together with jsonSchema: otherwise the producer fails to start. | Object> | |
camel.component.langchain4j-agent.provider | The LangChain4j provider of the chat model that drives the agent, to create the model from the options here (modelName, baseUrl, apiKey, temperature, timeout, and provider-specific model.* properties) instead of an AgentConfiguration bean. The LangChain4j module of the provider (dev.langchain4j:langchain4j-ollama, …) must be on the classpath; the Camel CLI downloads it. Ignored when agent, agentFactory or agentConfiguration is set. For a provider not listed, set customProvider instead. | String | |
camel.component.langchain4j-agent.tags | A comma-separated list of tags. The routes that start from an ai-tool endpoint with one of these tags are offered to the model as tools. The CamelLangChain4jAgentExcludeTags header removes tags from this list for one message. | String | |
camel.component.langchain4j-agent.temperature | The sampling temperature of the model, when the model is created from the provider. | Double | |
camel.component.langchain4j-agent.timeout | The request timeout of the model (30s, 2m), when the model is created from the provider. | Duration | |
camel.component.langchain4j-agent.tool-search | Whether to leave the route tools with searchable=true and the MCP tools out of the first request to the model, and give the model one search tool (tool_search_tool) to find them; the other route tools and the customTools of the agentConfiguration are always sent. It controls what the model sees, not what it may call, and does not search a tool provider set outside Camel. Only works when Camel creates the agent, from agentConfiguration or provider. | false | Boolean |
camel.component.langchain4j-agent.tool-search-embedding-model | The LangChain4j embedding model that turns the tool descriptions and the search query into vectors. Required when toolSearchStrategy is VECTOR, and not used otherwise. The option is a dev.langchain4j.model.embedding.EmbeddingModel type. | EmbeddingModel | |
camel.component.langchain4j-agent.tool-search-max-results | The maximum number of tools that one call of the search tool returns, at least 1. Route tools and MCP tools are ranked together. | 5 | Integer |
camel.component.langchain4j-agent.tool-search-strategy | How tool search ranks route and MCP tools. 'KEYWORD' matches the tool name and description. 'VECTOR' uses cosine similarity and requires toolSearchEmbeddingModel. Vector search does not fall back to keyword search. | keyword | AiToolSearchStrategy |