Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Integrating AI into your existing Java applicat...

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →
Avatar for Buhake Sindi Buhake Sindi
September 23, 2026

Integrating AI into your existing Java application using LangChain4J CDI

We are in the age of AI, where large language models (LLMs) are evolving rapidly. A major challenge for enterprise developers is learning to build effective AI agents, orchestrate workflows, and integrate them into existing business applications without breaking the codebase.

Now that LangChain4J is widely adopted in the Java community, the Jakarta EE/MicroProfile working group is introducing LangChain4J-CDI. Powered by Jakarta CDI, this tool enables developers to declaratively build AI agents using configuration or producer methods. It ensures agents are observable and resilient, allowing you to inject them into your application seamlessly.

The full video of the presentation can be found on Riyadh Java User Group's channel: https://www.youtube.com/watch?v=E3kd4I9c9DM

Avatar for Buhake Sindi

Buhake Sindi

September 23, 2026

More Decks by Buhake Sindi

Other Decks in Programming

Transcript

  1. IO.println(“I’m Buhake Sindi”); Enterprise solutions architect, consultant. • 20 years

    of solid Java / Enterprise Java development experience. • Founded Devoxx4Kids South Africa (NPO) – introducing kids to coding, robotics, AI, • etc., in a fun way. Jozi JUG Organiser (monthly Java User Group Meetup in Johannesburg) • JakartaEE / Microprofile Working Group member. • Jakarta EE Ambassador. • Member of the JCP • Tech speaker • Blogger / Content writer • Langchain4J CDI committer. • Fo u n d e r , S i n d i Te c h n o l o g i e s (Pty) Ltd Wednesday, September 23, 2026 Who am I? 2
  2. 🔎 Where to find me? X: @EliteGentleman Other socials: @buhake.sindi

    : [email protected] https://linktr.ee/theEliteGentleman 📧 Fo u n d e r , S i n d i Te c h n o l o g i e s (Pty) Ltd Wednesday, September 23, 2026 AI in the Enterprise: the Jakarta EE Way. 3
  3. AI + Java Wednesday, September 23, 2026 Integrating AI into

    your existing Java application using LangChain4J-CDI 4
  4. What is LangChain4J? • A fully open-source Java library for

    Large Language Model (LLM) integration. • Unified API model for LLM integration. • Comprehensive toolbox, providing common abstraction for common features, including prompt engineering, function and tool calling, RAG, memory management, etc.)  Integrates with a variety of vector stores & document loaders, for easy LLM interactions. • Support AI Agents and Services, through the core feature of AiServices, developers can create AI agents and define its behaviour using Java interfaces. • LangChain4J Agentic, a module for developers to build and orchestrate mult-agent AI systems. • GitHub repo: https://github.com/langchain4j/ Wednesday, September 23, 2026 Bring AI and build AI agents into your Jakarta EE applic ation with LangChain4J CDI. 5
  5. Example of an AiServices • Create an interface without implementation.

    • Register your interface, along with LangChain4J components using AiServices factory. Wednesday, September 23, 2026 Bring AI and build AI agents into your Jakarta EE applic ation with LangChain4J CDI. 6
  6. LangChain4J Agentic • LangChain4J Agentic, a module for developers to

    build and orchestrate mult-agent AI systems. • Provides a set of abstractions and utilities to help you build agentic workflows and pure agentic AI applications, culminating in GOAP (Goal Oriented Action Planning) agentic system. • Features:  AgenticScope, a shared memory and context page where AI agents can write outputs, read required information and track invocation logs.  Support for agentic workflow patterns: sequential, parallel, loops, conditional  Agentic and non-AI patterns: Supervisor, Human-In-The-Loop • Docs: https://docs.langchain4j.dev/tutorials/agents/ Wednesday, September 23, 2026 Bring AI and build AI agents into your Jakarta EE applic ation with LangChain4J CDI. 7
  7. Example of an Agentic service • Create an interface without

    implementation. • Register your interface, along with LangChain4J components using AgenticServices.agentBuilder() factory. Wednesday, September 23, 2026 Bring AI and build AI agents into your Jakarta EE applic ation with LangChain4J CDI. 8
  8. Example of Sequence AI agent Wednesday, September 23, 2026 Bring

    AI and build AI agents into your Jakarta EE applic ation with LangChain4J CDI. 9
  9. For enterprise Java developers… • Familiarity: Jakarta EE APIs are

    familiar with API level interfaces. • What if? • Make low-level APIs configurable? • Apply enterprise-level context and scope to AI services and AI agents? • Apply resiliency to AI services and AI agents with MicroProfile? • Apply Observability to your ChatModel (if supported) and AI agents? Wednesday, September 23, 2026 Presentation Title 10
  10. @Inject AI Agents the Jakarta EE way - LangChain4J-CDI Wednesday,

    September 23, 2026 Integrating AI into your existing Java application using LangChain4J-CDI 11
  11. What is LangChain4J CDI? • A Jakarta EE with AI

    starter project. Initally called SmallRye-LLM.  Donated to LangChain4J and renamed as LangChain4J CDI. • Seamless integration between LangChain4J and CDI (Context and Dependency Injection), since it is a CDI component. • @Inject AI services or AI agents as beans. – The Jakarta EE way. • Declare your AI service with @RegisterAIService annotation on your interface • Use @Register*Agent for agentic workflow • Use the standard @Inject annotation to bring your AI services & agents into your REST resource or other CDI beans. • Requirements: • Jakarta EE 10, and higher • JDK 17, and higher • Tested: Helidon, Quarkus, WildFly, Payara, OpenLiberty, GlassFish • GitHub: https://github.com/langchain4j/langchain4j-cdi Wednesday, September 23, 2026 Presentation Title 12
  12. Getting started Wednesday, September 23, 2026 • Prod ready version:

    1.4.0 • From Maven Central: • GroupId: dev.langchain4j.cdi • Either langchain4j-cdi-portable-ext or langchain4j-cdi-build-compatible-ext • MicroProfile integrated modules: • GroupId: dev.langchain4j.cdi.mp • Configurability: langchain4j-cdi-config • Resiliency: langchain4j-cdi-fault-tolerance • Observability: langchain4j-cdi-telemetry Presentation Title 13
  13. @RegisterAIService • Annotation attribute value matches CDI bean name. •

    Value of “#default” enables the CDI container to select default CDI bean of relevant LangChain4J component. • Empty attribute value disables CDI bean lookup. Wednesday, September 23, 2026 Bring AI and build AI agents into your Jakarta EE applic ation with LangChain4J CDI. 14
  14. @RegisterAIService Wednesday, September 23, 2026 Bring AI and build AI

    agents into your Jakarta EE applic ation with LangChain4J CDI. 15
  15. Configurable • Via Microprofile Config. • All low-level LangChain4J components

    are supported, provided they have a Builder object provided. • All config keys must be prefixed with the dev.langchain4j.plugin. <cdi-bean-name>. Keyword. Wednesday, September 23, 2026 Presentation Title 16
  16. Stateful conversations • LLMs are stateless by default. To build

    a true agent, one needs to include memory. • With addition of ChatMemory component, LangChain4J automatically appends previous messages to current prompts. Wednesday, September 23, 2026 Presentation Title 17
  17. Adding resiliency • Via Microprofile Fault Tolerance. • Apply any

    MP Fault Tolerance interceptor annotations (e.g., @Retry, @Fallback, @Timeout, etc.), the same way you would to existing CDI bean. Wednesday, September 23, 2026 Presentation Title 18
  18. Applying Observability • • • • • • • Wednesday,

    September 23, 2026 Via Microprofile Telemetry. Can register either Span, Metrics, or both. Each ChatModelListener can be assigned via MP Config. “lookup:@all” allows CDI to seek all Telemetry beans and register it to the ChatModel. Alternatively, specify the fullqualified classname of either SpanChatModelListener, MetricsChatModelListener, separated by a comma. OpenTelemetry Semantic Conventi on for Generative AI Spans. OpenTelemetry Semantic Conventi on for Generative AI Metrics. Bring AI and build AI agents into your Jakarta EE applic ation with LangChain4J CDI. 19
  19. Orchestrate your agentic workflows the Jakarta EE way. - LangChain4J-CDI

    Agentic Wednesday, September 23, 2026 Integrating AI into your existing Java application using LangChain4J-CDI 20
  20. LangChain4J CDI Agentic • Langchain4J Agentic, with the power of

    CDI. • Declarative over imperative: compose multi-agents systems with annotation on interfaces instead of hand-written builder/orchestration code. • Portable across runtimes  Tested across the same application servers. Wednesday, September 23, 2026 Presentation Title 21
  21. One annotation per agentic topology SIMPLE SEQUENCE PARALLEL PARALLEL_MAPPER @RegisterSimpleAgent

    @RegisterSequenceAgent @RegisterParallelAgent @RegisterParallelMapperAgen t CONDITIONAL LOOP SUPERVISOR PLANNER @RegisterConditionalAgent @RegisterLoopAgent @RegisterSupervisorAgent @RegisterPlannerAgent HUMAN IN THE LOOP A2A MCP CLIENT 11 topologies total @RegisterHumanInTheLoopAgen t @RegisterA2AAgent @RegisterMcpClientAgent Simple → Sequence → Parallel → Conditional → Loop → Supervisor → Planner → HITL → A2A → MCP Each agentic topology has a dedicated CDI stereotype annotation - pick the pattern, annotate the interface, and LangChain4j CDI generates the implementation. Wednesday, September 23, 2026 Presentation Title 22
  22. CASE STUDY 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 🚗 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. Section 2 — Agentic Workflows 7 steps: agents, workflows, supervisors, HITL, multimodal, A2A. ← This deck's focus. This is exactly the kind of multi-step, judgment-based process that autonomous agents are built for. https://openliberty.github.io/liberty-workshop-langchain4j Builds on and extends the Quarkus LangChain4j Workshop content, adapted for Jakarta EE / LangChain4j-CDI. Integrating AI into your existing Java application using LangChain4J-CDI 07
  23. BUILDING BLOCK #1 The Simple Agent — @RegisterSimpleAgent Declared as

    an interface — no implementation needed. CleaningAgent.java @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. @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, ... ); 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. } No method body — LangChain4j CDI generates the implementation automatically. Integrating AI into your existing Java application using LangChain4J-CDI 09
  24. BUILDING BLOCK #2 Tools — Giving Agents the Power to

    Act @Named makes the tool a discoverable CDI bean by name. CleaningTool.java @Named("cleaning-tool") @ApplicationScoped public class CleaningTool { @Tool exposes the method to agents; its description tells the LLM when to use it. @Tool("Requests a cleaning...") @Transactional public String requestCleaning( Integer carNumber, boolean interiorCleaning, boolean exteriorWash, ... ) { // update status, return summary } 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 Integrating AI into your existing Java application using LangChain4J-CDI LLM decides to call the tool (or not) LLM fills in parameters Tool executes & returns a result Agent responds 10
  25. BUILDING BLOCK #3 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. Agent 1 reads / writes state Workflow Inputs AgenticScope Workflow Result shared state map Agent 2 reads / writes state 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. Integrating AI into your existing Java application using LangChain4J-CDI 11
  26. COMPOSING AGENTS 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(...); } } Integrating AI into your existing Java application using LangChain4J-CDI 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
  27. T H E PAT T E R N L I

    B R A R Y Four Fundamental Workflow Patterns Basic patterns nest inside one another to build sophisticated, deterministic agentic systems. SEQUENTIAL PARALLEL Agent 1 Agent 1 Agent 2 Agent 3 Agent 2 Start Continue Agent 3 Runs one after another; each depends on the last. Runs simultaneously; faster, independent tasks. CONDITIONAL LOOP yes Condition? Agent A no Agent B Executes an agent only when its activation condition is met. Continue? Agent repeat until done no yes Done Continue Runs repeatedly until a stop condition or max-attempts is reached. Integrating AI into your existing Java application using LangChain4J-CDI 13
  28. A U 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. PricingAgent estimate value DispositionAgent SCRAP/SELL/DONATE/KEEP FeedbackAnalysis FleetSupervisorAgent Results decides what to invoke 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. Integrating AI into your existing Java application using LangChain4J-CDI 14
  29. 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. FeedbackTask .cleaning() FeedbackAnalysisWorkflow FeedbackTask .maintenance() FeedbackAnalysisAgent same agent, 3x in parallel itemsKey = "tasks" FeedbackAnalysisResults cleaning / maintenance / disposition FeedbackTask .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. Integrating AI into your existing Java application using LangChain4J-CDI 15
  30. SAFETY & CONTROL 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 HumanApprovalAgent Agent — creates SCRAP/SELL/etc. @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. Integrating AI into your existing Java application using LangChain4J-CDI 16
  31. DISTRIBUTION 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) Runtime 2 — Remote Pricing Service (:8888) PricingAgent FleetSupervisorAgent @RegisterA2AAgent JSONRPC over HTTP AgentCard AgentExecutor capabilities handles tasks a2aServerUrl = "http://localhost:8888" DispositionAgent stays local — only pricing moves remote. 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. Integrating AI into your existing Java application using LangChain4J-CDI 17
  32. PUTTING IT ALL TOGETHER The Complete Miles of Smiles Architecture

    Car Return FeedbackAnalysis FleetSupervisorAgent Parallel Mapper autonomous orchestration PricingAgent remote via A2A Disposition Proposal → Approval HITL gate for high-value cars DispositionAgent local, low-value cars Maintenance / Cleaning routine agents Updated Fleet status + condition CarConditionFeedback final summary One workflow, five agentic patterns — sequential composition, parallel mapping, autonomous supervision, human oversight, and distributed A2A — all declared with CDI annotations. Integrating AI into your existing Java application using LangChain4J-CDI 18
  33. A KEY DISTINCTION 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 Integrating AI into your existing Java application using LangChain4J-CDI 08
  34. Not to be confused with… • Spring Boot LangChain4J: https://docs.langchain4j.dev/tutorials/sp

    ring-boot-integration • Quarkus LangChain4J: https://docs.quarkiverse.io/quarkus-langch ain4j/dev/index.html • Helidon MP LangChain4J: https://helidon.io/docs/v4/mp/guides/lan gchain4j • Micronaut LangChain4J: https://micronaut-projects.github.io/micro naut-langchain4j/latest/guide/ Wednesday, September 23, 2026 Bring AI and build AI agents into your Jakarta EE applic ation with LangChain4J CDI. 35
  35. Finally… • Jakarta Agentic Artificial Intelligence: • Still under development,

    under the Eclipse Foundation. • The project provides a set of vendor-neutral APIs that make it easy, consistent, and reliable to build, deploy, and run AI agents on Jakarta EE runtimes. • Anybody can contribute to the development of the Jakara Agentic AI specifications. • More info: https://jakarta.ee/specifications/agentic-ai/ Wednesday, September 23, 2026 Bring AI and build AI agents into your Jakarta EE applic ation with LangChain4J CDI. 36
  36. Resources Wednesday, September 23, 2026 • LangChain4J-CDI: • Official documentation:

    https://langchain4j.github.io/langchain4j-cdi/ • GitHub: https://github.com/langchain4j/langchain4j-cdi • Example: https://github.com/langchain4j/langchain4j-cdi/tree/main/examples • LangChain4J: • URL: https://docs.langchain4j.dev/ • GitHub: https://github.com/langchain4j/langchain4j • https://github.com/langchain4j/langchain4j • Liberty LangChain4J Workshop:https://openliberty.io/blog/2026/07/10/liberty-langchain4j-wo rkshop.html • Article: Build AI Apps and Agents in Java: Hands-on with LangChain4J (by Lize Raes): https:/ /javapro.io/2025/04/23/build-ai-apps-and-agents-in-java-hands-on-with-langchain4j/ • Article: Bring AI into your Jakarta EE apps with LangChain4J-CDI (formerly SmallRye-LLMM): JavaPRO Magazine, 04-2025, Java 25 – Special Edition. Page, 96 (by Buhake Sindi). https://j avapro.io/2025/10/28/04-2025-java-25-special-edition/ Bring AI and build AI agents into your Jakarta EE applic ation with LangChain4J CDI. 37
  37. THANK YOU Any Questions? Buhake Sindi x: @EliteGentleman Other socials:

    @buhake.sindi https://linktr.ee/theEliteGentleman Wednesday 23 September 2026 Bring AI and build AI agents into your Jakarta EE applic ation with LangChain4J CDI. 38