Skip to main content
J AK AR T A E E ¡ M I C R O P R O F I L E ¡ L AN G C H AI N 4 J
LangChain4j-CDI
Building Agentic AI Systems the CDI Way
From a single autonomous agent to distributed, human-supervised multi-agent
workflows using plain CDI beans, annotations, and Jakarta EE / MicroProfile.
Buhake Sindi
• Founder: Sindi Technologies (Pty)
Ltd
• Enterprise Java expert (Java and
Jakarta EE)
• Developer of LangChain4J-CDI
• Full member of the JCP
• Jakarta EE / Microprofile Working
Group member
3
3
T H E F O U N D AT I O N
What Is LangChain4j?
An idiomatic, open-source Java library for building LLM-powered
applications on the JVM.
1 Unified API
One consistent API across popular LLM providers and vector stores.
2 Tools & MCP
Function calling, including native Model Context Protocol support.
3 Agents
The langchain4j-agentic module for autonomous, multi-step workflows.
4 RAG
Retrieval-Augmented Generation made straightforward to implement.
</>
Widely adopted as de-factor AI library
for Java
Java developers can seamlessly integrate to various AI
LLM API and AI tools with consistently, without having to
do various code changes to adopt other LLMs.
This deck focuses on how Jakarta EE / MicroProfile
developers consume LangChain4j through the
LangChain4j-CDI extension — not the Quarkus integration.
03
LangChain4j-CDI Agentic
T H E E X T E N S I O N
What Is LangChain4J-CDI?
Seamless integration between LangChain4j and CDI (Contexts and Dependency Injection) — infuse any Jakarta EE application with AI, the same way
you already build it.
1
Inject AI Services as Beans
@RegisterAIService turns an interface into an injectable
CDI bean.
2
Per-Topology Agent Annotations
@RegisterSimpleAgent, @RegisterSequenceAgent, and
more for multi-agent workflows.
3
Config-Driven LLM Setup
Configure chat models via MicroProfile Config — or your
own adapter.
4
Fault Tolerance Built In
Add @Retry, @Timeout, @CircuitBreaker from
MicroProfile Fault Tolerance.
5
Observability for Free
Monitor AI operations with MicroProfile Telemetry /
OpenTelemetry.
6
Runs on Any Jakarta EE Server
Open Liberty, Payara, Helidon — CDI is portable across
runtimes.
04
LangChain4j-CDI Agentic
AI E n g i n e e r i n g
Building effective agents
Anthropic released common agentic patterns to build agentic systems that can be deployed in production.
✓ Building block: Augmented LLM
The basic building block of agentic systems is an LLM enhanced with augmentations such as retrieval, tools, and memory.
✓ Agentic workflows
Prompt chaining, Routing, Parallelization, Orchestrator-workers, Evaluator-optimizer.
✓
Agents
Agents augmented LLMs mature in key capabilities—understanding complex inputs, engaging in reasoning and planning, using tools reliably, and recovering from
errors. It's used to define specific tasks using LLMs.
✓ Resource/Link
https://www.anthropic.com/engineering/building-effective-agents
05
LangChain4j-CDI Agentic
Ag e n t i c S ys t e m
LangChain4J Agentic
LangChain4J Agentic provides a set of abstractions and utilities to help you
build workflow and pure agentic AI applications, culminating in a Goal-
Oriented Action Planning (GOAP) agentic system.
1 Building block: AI Agent
One consistent API across popular LLM providers and vector stores.
2 Sharing states using AgenticScope
Exchanging of data amongst AI agents.
3 Agentic workflow patterns
Sequential, Loop, Parallel, Conditional.
4 Agentic and Non-AI patterns
Supervisor, Human In The Loop.
</>
Enterprise-ready by design
LangChain4j integrates seamlessly with enterprise Java
frameworks like Jakarta EE, MicroProfile, Quarkus, and
Spring Boot.
This deck focuses on how Jakarta EE / MicroProfile
developers consume LangChain4j through the
LangChain4j-CDI extension — not the Quarkus integration.
03
LangChain4j-CDI Agentic
F o r e n t e r p r i s e J a v a d e v e l o p e r s
Why CDI for Agentic AI?
Agentic systems are just more moving parts. CDI is the tool Jakarta EE developers already use to manage moving parts.
✓ No new mental model
Agents, tools, and workflows are CDI beans with familiar scopes and lifecycle — not a separate framework to learn.
✓ Declarative over imperative
Compose multi-agent systems with annotations on interfaces, instead of hand-written builder/orchestration code.
✓ Enterprise features come as a free, added bonus
Fault tolerance, telemetry, and configuration plug straight into agents via existing MicroProfile specs.
✓ Portable across runtimes
Because it's standard CDI, the same code can run on Open Liberty, Payara, Helidon, and others.
05
LangChain4j-CDI Agentic
T H E AN N O T AT I O N C AT AL O G
One Annotation per Agentic Topology
Each agentic topology has a dedicated CDI stereotype annotation — pick the pattern, annotate the interface, and LangChain4j CDI generates the implementation.
SIMPLE
@RegisterSimpleAgent
SEQUENCE
@RegisterSequenceAgent
PARALLEL
@RegisterParallelAgent
PARALLEL_MAPPER
@RegisterParallelMapperAgen
t
CONDITIONAL
@RegisterConditionalAgent
LOOP
@RegisterLoopAgent
SUPERVISOR
@RegisterSupervisorAgent
PLANNER
@RegisterPlannerAgent
HUMAN IN THE LOOP
@RegisterHumanInTheLoopAgen
t
A2A
@RegisterA2AAgent
MCP CLIENT
@RegisterMcpClientAgent
11 topologies total
Simple → Sequence → Parallel → Conditional →
Loop → Supervisor → Planner → HITL → A2A → MCP
06
LangChain4j-CDI Agentic
C AS E S T U D Y
The Liberty LangChain4j Workshop
A free, hands-on workshop from OpenLiberty
Builds AI-infused applications with Open Liberty and LangChain4j — starting from a simple
chatbot and progressing to fully agentic, multi-agent systems.
1 Section 1 — AI-Infused Apps
10 steps: prompts, streaming, RAG, tools, MCP, guardrails, observability.
2 Section 2 — Agentic Workflows
7 steps: agents, workflows, supervisors, HITL, multimodal, A2A. ← This deck's focus.
github.com/OpenLiberty/liberty-workshop-langchain4j
Builds on and extends the Quarkus LangChain4j Workshop content, adapted for Jakarta EE / LangChain4j-CDI.
The Scenario
“Miles of Smiles”, a car rental company, needs to manage
its fleet: recording feedback on returns, deciding on
cleaning, maintenance, and — when damage is severe —
whether to scrap, sell, donate, or keep a vehicle.
This is exactly the kind of multi-step, judgment-based
process that autonomous agents are built for.
07
LangChain4j-CDI Agentic
A K E Y D I S T I N C T I O N
AI Services vs. AI Agents
Feature AI Services AI Agents
Purpose Answer user questions Perform autonomous tasks
Interaction Reactive — responds to prompts Reactive & proactive — takes action
Tool Usage Can call tools when needed Calls tools to accomplish goals
Workflows Single-agent interactions Multi-agent collaboration
Annotation @SystemMessage / @UserMessage One method per interface (@Agent)
Use Cases Chatbots, Q&A, content generation Automation, decisions, orchestration
08
LangChain4j-CDI Agentic
B U I L D I N G B L O C K # 1
Getting started
Simple imports — On your Maven POM.
09
LangChain4j-CDI Agentic
B U I L D I N G B L O C K # 2
The Simple Agent — @RegisterSimpleAgent
Declared as an interface — no implementation needed.
@SystemMessage defines the agent's role and decision logic.
@UserMessage supplies per-call context via {{ template }} variables.
toolNames wires in CDI-named tool beans the agent may call.
The CleaningAgent decides:
Given return feedback like “dog hair all over the back seat,” should this car
be sent for cleaning — and if so, which services are needed? If not, it
responds CLEANING_NOT_REQUIRED.
CleaningAgent.java
@RegisterSimpleAgent(
name = "cleaning-agent",
description = "Cleaning specialist...",
chatModelName = "chat-model",
toolNames = { "cleaning-tool" },
scope = ApplicationScoped.class
)
public interface CleaningAgent {
@SystemMessage("""
You handle intake for the cleaning
department. Submit a request to the
requestCleaning function if needed.
Otherwise respond "CLEANING_NOT_REQUIRED".
""")
@UserMessage("""
Car: {{carMake}} {{carModel}} ({{carYear}})
Feedback: {{feedback}}
""")
String processCleaning(
@V("carMake") String carMake, ...
);
}
No method body — LangChain4j CDI generates the implementation automatically.
09
LangChain4j-CDI Agentic
B U I L D I N G B L O C K # 3
Tools — Giving Agents the Power to Act
CleaningTool.java
@Named("cleaning-tool")
@ApplicationScoped
public class CleaningTool {
@Tool("Requests a cleaning...")
@Transactional
public String requestCleaning(
Integer carNumber,
boolean interiorCleaning,
boolean exteriorWash, ...
) {
// update status, return summary
}
}
@Named makes the tool a discoverable CDI bean by name.
@Tool exposes the method to agents; its description tells the LLM when to use
it.
Parameters define exactly what information the agent must supply.
Local or remote tools can run in-process or be reached over MCP.
Tool Execution Flow
Agent receives feedback LLM analyzes it LLM decides to call the tool (or
not)
LLM fills in parameters Tool executes & returns a result Agent responds
10
LangChain4j-CDI Agentic
B U I L D I N G B L O C K # 4
AgenticScope — Shared Context for Collaboration
A shared map of key-value state that lets independent agents read what they need and write what they produce — without being tightly coupled to each
other.
Workflow Inputs AgenticScope
shared state map
Agent 1
reads / writes state
Agent 2
reads / writes state
Workflow Result
Populated automatically from the workflow method's inputs.
Updated automatically from each agent's outputKey after it runs.
Also tracks the full invocation sequence for observability.
11
LangChain4j-CDI Agentic
C O M P O S I N G AG E N T S
Sequential Workflows — @RegisterSequenceAgent
CarProcessingWorkflow.java
@RegisterSequenceAgent(
name = "car-processing-workflow",
subAgentNames = {
"cleaning-agent",
"car-condition-feedback-agent"
},
outputKey = "carConditions"
)
public interface CarProcessingWorkflow {
CarConditions processCarReturn(...);
@Output
static CarConditions output(
String carCondition,
String cleaningAgentResult
) {
// combine both agents' results
return new CarConditions(...);
}
}
Runs agents one after another — also called “prompt chaining.”
subAgentNames lists the CDI bean names to execute, in order.
outputKey stores each result in the AgenticScope for the next agent.
@Output method combines multiple agents' results into one typed
record.
When to use
Each agent needs the previous agent's output.
Example: process feedback → update condition → notify.
12
LangChain4j-CDI Agentic
T H E P AT T E R N L I B R AR Y
Four Fundamental Workflow Patterns
Basic patterns nest inside one another to build sophisticated, deterministic agentic systems.
SEQUENTIAL
Agent 1 Agent 2 Agent 3
Runs one after another; each depends on the last.
PARALLEL
Start
Agent 1
Agent 2
Agent 3
Runs simultaneously; faster, independent tasks.
CONDITIONAL
Condition?
yes
Agent A
no
Agent B
Executes an agent
only when its
activation condition is
met.
LOOP
Agent
repeat until done
Runs repeatedly until a stop condition or max-attempts is reached.
13
LangChain4j-CDI Agentic
Continue
Continue
Continue?
yes
Done
no
AU T O N O M O U S O R C H E S T R AT I O N
The Supervisor Pattern — @RegisterSupervisorAgent
Instead of hardcoded routing, an AI supervisor autonomously decides which sub-agents to invoke — and in what order — based on runtime context.
FeedbackAnalysis
Results
FleetSupervisorAgent
decides what to invoke
PricingAgent
estimate value
DispositionAgent
SCRAP/SELL/DONATE/KEEP
MaintenanceAgent
if needed
CleaningAgent
if needed
Supervisor vs. Conditional Workflow
Conditional: hardcoded if/else logic, fixed rules, simple to maintain by editing code. Supervisor: AI-driven decisions that adapt to context — update prompts, not code.
14
LangChain4j-CDI Agentic
R E U S E O V E R D U P L I C AT I O N
One Agent, Many Tasks —
@RegisterParallelMapperAgent
Instead of three near-identical agents for cleaning, maintenance, and disposition, run one parameterized agent multiple times in parallel.
FeedbackAnalysisWorkflow
itemsKey = "tasks"
FeedbackTask
.cleaning()
FeedbackTask
.maintenance()
FeedbackTask
.disposition()
FeedbackAnalysisAgent
same agent, 3x in parallel
FeedbackAnalysisResults
cleaning / maintenance / disposition
@SystemMessage("{{taskSystemInstructions}}") the instructions are data, not hardcoded — the same interface becomes a cleaning, maintenance, or disposition analyzer.
itemsKey = "tasks" tells the framework which collection to iterate over, running the sub-agent once per item.
@Output method converts the raw List<String> result into a structured, named record for downstream agents.
15
LangChain4j-CDI Agentic
S AF E T Y & C O N T R O L
Human-in-the-Loop — @RegisterHumanInTheLoopAgent
Any vehicle worth more than $15,000 must be reviewed by a human before disposition. The agent method itself pauses execution until a decision is made.
PricingAgent
value > $15,000
DispositionProposal
Agent — creates SCRAP/SELL/etc.
HumanApprovalAgent
@HumanInTheLoop — blocks on Future.get()
Human Reviewer
Approve / Reject in UI
Approved → execute SCRAP/SELL/DONATE. Rejected → fall back to
Maintenance/Cleaning.
Two-phase workflow — propose, then review, then execute.
CompletableFuture bridges the paused agent and the REST approval endpoint.
Timeout-safe defaults to REJECTED if no decision arrives in time.
Full audit trail of who approved what, when, and why.
16
LangChain4j-CDI Agentic
D I S T R I B U T I O N
Agent-to-Agent (A2A) — @RegisterA2AAgent
Let a different team own and scale the pricing service independently — reachable from any application over an open protocol.
Runtime 1 — Car Management (:9080)
FleetSupervisorAgent PricingAgent
@RegisterA2AAgent
a2aServerUrl = "http://localhost:8888"
DispositionAgent stays local — only pricing moves remote.
JSON-
RPC
over
HTTP
Runtime 2 — Remote Pricing Service (:8888)
AgentCard
capabilities
AgentExecutor
handles tasks
PricingAgent
AI Service (local logic)
Why A2A? Separation of concerns, independent scaling, reusable across client apps, technology-independent.
Tasks vs. Messages Pricing uses a Task: a long-running job with a defined goal and tracked state.
17
LangChain4j-CDI Agentic
P U T T I N G I T AL L T O G E T H E R
The Complete Miles of Smiles Architecture
Car Return FeedbackAnalysis
Parallel Mapper
FleetSupervisorAgent
autonomous orchestration
PricingAgent
remote via A2A
Disposition Proposal → Approval
HITL gate for high-value cars
DispositionAgent
local, low-value cars
Maintenance / Cleaning
routine agents
CarConditionFeedback
final summary
Updated Fleet
status + condition
One workflow, five agentic patterns — sequential composition, parallel mapping, autonomous supervision, human oversight, and distributed A2A — all declared with CDI annotations.
18
LangChain4j-CDI Agentic
W R AP P I N G U P
Key Takeaways
✓
CDI-native agents
Agents, tools, and workflows are just managed CDI beans —
familiar scopes, familiar lifecycle.
✓
Declarative composition
One annotation per topology: simple, sequence, parallel,
conditional, loop, supervisor, and more.
✓
Progressive sophistication
Start with a single agent and grow into supervised, human-
gated, distributed systems — same model throughout.
✓
Safety is built in
Human-in-the-Loop and fault tolerance let you dial
autonomy up or down as trust grows.
✓
Distribution when it pays off
A2A lets specialized agents be owned by other teams and
reused across applications.
✓
Portable across Jakarta EE
Because it's standard CDI, it isn't locked to one runtime or
one framework.
19
LangChain4j-CDI Agentic
T H AN K Y O U
Go & Build Something Agentic
Same CDI you already know. A whole new class of applications.
LangChain4j-CDI
github.com/langchain4j/langchain4j-cdi
Liberty LangChain4j Workshop
github.com/OpenLiberty/liberty-workshop-langchain4j
LangChain4j-CDI Documentation
langchain4j.github.io/langchain4j-cdi/
Built on the OpenLiberty “Miles of Smiles” case study — no Quarkus LangChain4j content used.
LangChain4j Agents Docs
docs.langchain4j.dev/tutorials/agents
Thank you
Buhake Sindi
X/Twitter: @EliteGentleman
LinkedIn / Facebook / Instagram: Buhake Sindi