langchain4j-cdi: Infuse your Jakarta and MicroProfile applications with all the AI
edburns
0 views
41 slides
Oct 07, 2025
Slide 1 of 41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
About This Presentation
Generative AI burst on to the public scene in November 2022, over ten years after Andrew Ng’s Machine Learning premiered on Coursera. Java developers have long felt like second class citizens, compared to the cool Python kids. LangChain4J changes the game. Java is cool with AI now! This lecture fr...
Generative AI burst on to the public scene in November 2022, over ten years after Andrew Ng’s Machine Learning premiered on Coursera. Java developers have long felt like second class citizens, compared to the cool Python kids. LangChain4J changes the game. Java is cool with AI now! This lecture from 30-year industry veteran Ed Burns explores why it took so long for Java developers to have access to easy-to-use AI libraries, compared to Python developers. This session introduces the new langchain4j-cdi repository within the LangChain4j GitHub organization. Combine the power of Jakarta EE with the reach of LangChain4j. All the idioms you know and love from Jakarta now work with all the AI exposed by LangChain4j: injection, validation, persistence, REST and more!
Size: 18.36 MB
Language: en
Added: Oct 07, 2025
Slides: 41 pages
Slide Content
Session code: 2788 Slide at https://aka.ms/txc-2025 Ed Burns Principal Architect for Java, Microsoft Emily Jiang IBM, STSM, Cloud Native Architect and Advocate langchain4j-cdi: Infuse your Jakarta and MicroProfile applications with all the AI
Ed Burns professional biography Client NCSA Mosaic (1994) SGI Cosmo Web Authoring Sun Netscape 6 OJI Server J2EE JSF (2002) Oracle Java EE Servlet, JSF, Bean Validation, etc. Cloud Java Champion Jakarta EE 11 committer and release coordinator Langchain4j-cdi committer Books
Emily Jiang Java Champion MicroProfile Technical Lead MicroProfile Spec author Jakarta EE committer Langchain4j-cdi committer Book Author Fellowship BCS TechWomen100
Java SE Activation Java Products and Specifications Tomcat Jetty Undertow Spring Framework Spring Boot WebSocket Concurrency JSON-B Validation Persistence Messaging Transactions Messaging Servlet Pages Tag Libraries Expression Language Annotations Authorization Faces REST JSON-P Interceptors Dependency Injection CDI Jakarta EE Core Profile Batch Connectors Mail EJB Security EJB Lite Authentication Data Debugging Support WebLogic Server WebSphere Liberty Open Liberty JBoss EAP WildFly WebSphere Traditional Quarkus Micronaut Helidon Jakarta EE Platform and Web Profile (aka Java EE/J2EE JEE) A note on Spring and Jakarta EE “Spring /Tomcat profile” (not an official name) “Spring /Tomcat profile” (not an official name) Config Fault Tolerance Metrics Health JWT RBAC Open API REST Client Telemetry MicroProfile Not Cloud Native Older Cloud Native Newer Cloud Native E
New to AI? E
Don’t panic! E
Ed’s fairly obvious observations Recognize the market forces that have always been in play. Vendors want adoption. They’ll make it easy to adopt. This is also true with AI. E
James Gosling: I realized if I wanted bankers to use automatic garbage collection, I needed to give them curly braces rather than lots of irritating silly parentheses (LISP). Packaging a new idea for adoption: deliver it on the back of existing ideas. E
AI-enhanced Java applications Why Java? Leverage skills you and your teams already have Scalability, Security, Performance Deeply integrate AI into the logic and flow of your apps AI-enhanced applications Let users ask questions in natural language about documents, policies, etc. Translate content between languages dynamically Summarize meetings or transcripts Answer user-provided information queries Create specialized interactive research assistants J
Create an AI-enhanced Java App Simple LLM use in apps Use an LLM to interact with provided input Swap LLMs by changing configuration and/or dependencies Structured Output Directly integrate LLM responses with code lib Natural Language UI LLM J
Create an AI-enhanced Java App Retrieval Augmented Generation (RAG) Use Retrieval Augmented Generation pattern to extend what LLM knows lib Embedding Computation Docs Natural Language UI LLM Splitting Embedding Computation Vector Store J
What about AI Agents? E
Essential Component of AI Agents LLM Large language model that can comprehend and generate human language Actions and Tools AI Agents may require access to external tools, datasets, APIs, and automation systems to complete tasks. Tool calling enables LLMs to interface with structured tools, such as granting the model access to information beyond the data used in training. Memory Without memory, AI agents cannot remember the previous conversations. Session based context memory to memorize chat conversations. Structured knowledge bases, vector embeddings databases for long-term memory and retrieval of historical data. 16 E
Tool Tool Create an AI-enhanced Java App Java Methods as Tools Let LLM access tools lib Tool Natural Language UI LLM E
Langchain4j Initially, inspired by Langchain A Java library to make interactions with AI models and LLMs Provides a unified API to avoid the need for learning and implements specific APIs for each of them Comprehensive toolbox - tools ranging from low-level prompt templating, chat memory management, and function calling to high-level patterns like Agents and RAG Easy interaction with LLMs and Vector Stores https://github.com/langchain4j/ J
Langchain4j Architecture https://docs.langchain4j.dev/intro Low level: access to all the low-level components such as ChatModel , UserMessage , AiMessage , EmbeddingStore , Embedding, etc High level: interact with LLMs using high-level APIs like AI Services , which hides all the complexity and boilerplate from you J
Langchain4j AIService https://www.sivalabs.in/langchain4j-ai-services-tutorial/ Create an interface without an implementation Use AIServices to retrieve an object of the interface J
Improvement How to easily configure with LLMs? How to make the calling LLMs resilient? How to add telemetry? https://github.com/langchain4j/ J
Introducing Jakarta EE with AI via Langchain4j-cdi 24 E
Langchain4j-cdi with Jakarta EE Declare the AIService via @ RegisterAIService (CDI stereotype). Inject the AIService in other CDI beans via @Inject. Jakarta EE 10 and higher, JDK 17 support and higher. https://github.com/langchain4j/langchainej-cdi E
Langchain4j-cdi with MicroProfile Configuration (MicroProfile Config) • Low-level components are supported: ChatModel , ChatMesage , ChatMemory , EmbeddingStore , Embedding, tools https://github.com/langchain4j/langchainej-cdi E
Langchain4j-cdi with MicroProfile Fault Tolerance (MicroProfile Fault Tolerance) • @Timeout, @Fallback, @Retry, @ CircuitBreaker , etc. Observability (MicroProfile Telemetry) • OpenTelemetry AI Spans • OpenTelemetry AI Metrics https://github.com/langchain4j/langchain4j-cdi E
But what is MCP? https://modelcontextprotocol.io/ E
But what is MCP? https://github.com/modelcontextprotocol/servers Model Context Protocol (MCP) is an open-source standard for connecting AI applications to external systems. Using MCP, an AI enabled application can access tools and data from an MCP server. Not bound by LLM’s training cutoff. An MCP server can be local, communicating over stdio *, or remote, communicating over Streamable -HTTP. MCP servers are composable. E
MCP Architecture MCP Host – an AI app that uses MCP Clients MCP Client – a client to connect to an MCP Server MCP Server – a server that acts as a tool registry and can invoke tools (and other MCP things…) MCP Server LLM AI App / MCP Host JSON-RPC Streaming HTTP MCP Client C1 MCP Client C2 MCP Client C3 MCP Tool T1 MCP Tool T2 Service S1 Service S2 Service S3 REST MCP Tools should be built to return only the data needed (LLM performance is best with smaller responses) MCP Tools should be built to return data in a format that is LLM-friendly (JSON is fine, or yaml , or simple text). Structured output can also be used. MCP Tools should be built to combine common sets of actions into one call (reduces the demand on the LLM to get multiple calls right) J