Return to site

🤖☕ JAKARTA AGENTIC AI M1 with 3 code snippets

· jakartaee

🔸 TL;DR

Jakarta EE developers get a familiar annotation-driven model: trigger an agent, make an AI-assisted decision, execute actions, produce an outcome, and recover from failures.

Simplified M1 excerpts below; application-specific types and services are omitted.

🔸 TRUTH

The first Jakarta Agentic AI 1.0 milestone is out! 🎉 It offers an initial specification for community feedback while the implementation, TCK, and final v1 release move closer.

🔸 DEFINITION

Jakarta Agentic AI is a vendor-neutral API for building, deploying, and running AI agents on Jakarta EE. It standardizes agent lifecycles, workflows, CDI integration, and a lightweight LLM facade; not the underlying LLM providers.

1️⃣ DEFINE AN AGENT WORKFLOW

@Agent
public class MonitoringAgent {
 @Inject LargeLanguageModel llm;

 @Trigger
 public void onSystemAlert(Alert alert) {}

 @Decision
 public boolean shouldEscalate(Alert alert) {
 return llm.query(
 "Should this alert be escalated?", alert
 ).toLowerCase().contains("yes");
 }

 @Action
 public void escalateAlert(Alert alert) {
 logger.logEscalation(alert);
 }
}

@Agent creates a CDI bean. @Trigger starts the workflow, @Decision evaluates it, and @Action performs the work.

2️⃣ GET A TYPED LLM RESPONSE

@Decision
public FraudAnalysis analyzeTransaction(
 BankTransaction transaction) {
 return llm.query(
 "Analyze this transaction for fraud.",
 FraudAnalysis.class,
 transaction
 );
}

The LLM facade can deserialize JSON into a domain type through Jakarta JSON Binding, avoiding manual text parsing.

3️⃣ RECOVER FROM LLM FAILURE

@HandleException
@Transactional
public void handleModelUnavailable(
 LLMException e,
 BankTransaction transaction) {
 transaction.setStatus(
 TransactionStatus.NEEDS_REVIEW
 );
 entityManager.merge(transaction);
}

A matching @HandleException method can compensate for workflow failures. Here, an unavailable model routes the transaction to manual review.

🔸 TAKEAWAYS

▪️ Jakarta annotations make agent workflows readable.

▪️ CDI connects agents, LLMs, and enterprise services.

▪️ Typed responses reduce parsing boilerplate.

▪️ Transactions and recovery remain part of the model.

▪️ M1 is not the final 1.0 API, so details may evolve.

A promising step toward portable agentic AI for Jakarta EE. 🚀

#JakartaEE #JakartaAgenticAI #Java #AI #AgenticAI #LLM #CDI #EnterpriseJava

Go further with Java certification:

Java👇

Spring👇

SpringBook👇

JavaBook👇