Choosing a JVM Agent Framework: the Same Two-Step Triage in Spring AI, LangChain4j Agentic and Embabel
One ticket, 'I see two charges for my March invoice', classified and answered three ways. Plain Spring AI: two calls in the order you wrote. LangChain4j agentic: two agent interfaces and a sequence, no Spring, 14 jars. Embabel: you ask for a Reply, and the planner runs classify then draft. All three said BILLING.
What you will learn
- Write a classify-then-draft workflow in plain Spring AI with the order in your own code
- Write it with LangChain4j's agentic module as agent interfaces and a sequence object
- Write it with Embabel as typed actions and a goal the planner orders
- Pick a framework by how you want the steps decided, and check versions the day you decide
Before you start
- Spring AI structured output with records
- A supervisor and specialist agents
The less you write by hand, the more the framework decides for you. That is the whole trade-off between the three JVM options in this article. Each one runs the same two-step job on the same ticket: classify it, then draft a reply. The ticket: "I see two charges for my March invoice. Can you refund one of them? Emma".
A warning first. This area moves monthly. The versions here were the ones checked for the recording (Spring AI 2.0.2, langchain4j-agentic 1.23.0-beta33, Embabel 1.5.4). Read the versions on Maven Central the day you decide.
Plain Spring AI: the order is your code
/** The workflow in plain Spring AI: two ChatClient calls, and our own code decides the order. */
@Bean
CommandLineRunner run(ChatClient.Builder builder) {
return args -> {
ChatClient chat = builder.build();
Classification c = chat.prompt()
.system("Classify the support ticket. category: BILLING, ACCOUNT, TEAM or OTHER. "
+ "priority: HIGH, NORMAL or LOW.")
.user(TICKET)
.call().entity(Classification.class);
Reply r = chat.prompt()
.system("Write a reply of at most three sentences to the support ticket. "
+ "Sign off as The Relay Support Team.")
.user("Ticket: " + TICKET + "\nCategory: " + c.category())
.call().entity(Reply.class);
System.out.println("classification: " + c);
System.out.println("reply: " + r.text());
System.out.println("steps: 2, chosen by our code");
};
}
classification: Classification[category=BILLING, priority=HIGH]
reply: Hello Emma, I have noted your issue with the charges ...
steps: 2, chosen by our code
Step one returns a record with entity(). Your code passes the category to step two. The state is handled by hand, which makes it explicit and easy to test.
LangChain4j agentic: the order is a workflow object
public interface Classifier {
@UserMessage("Classify this support ticket as BILLING, ACCOUNT, TEAM or OTHER. "
+ "Answer with the one word only. Ticket: {{ticket}}")
@Agent(description = "Classifies a support ticket", outputKey = "category")
String classify(@V("ticket") String ticket);
}
public interface Drafter {
@UserMessage("Write a reply of at most three sentences to this {{category}} support ticket. "
+ "Sign off as The Relay Support Team. Ticket: {{ticket}}")
@Agent(description = "Drafts the reply", outputKey = "reply")
String draft(@V("ticket") String ticket, @V("category") String category);
}
public static void main(String[] args) {
var model = OllamaChatModel.builder()
.baseUrl("http://localhost:11434").modelName("qwen2.5:3b")
.temperature(0.0).seed(42)
.timeout(Duration.ofMinutes(5)) // the default is 60 s
.build();
Classifier classifier = AgenticServices.agentBuilder(Classifier.class).chatModel(model).build();
Drafter drafter = AgenticServices.agentBuilder(Drafter.class).chatModel(model).build();
// The order is data: a sequence of sub-agents sharing one scope of named values.
UntypedAgent triage = AgenticServices.sequenceBuilder()
.subAgents(classifier, drafter)
.outputKey("reply")
.build();
var result = triage.invokeWithAgenticScope(Map.of("ticket", TICKET));
System.out.println("category: " + result.agenticScope().readState("category"));
System.out.println("reply: " + result.result());
System.out.println("steps: 2, a sequence workflow");
}
category: BILLING
reply: Hello Emma, I understand your concern. Please provide ...
steps: 2, a sequence workflow
An agent is an interface. Its answer is stored under an output key, category, and the drafter reads category from the shared scope by name. The workflow is an object, and the module also has parallel, loop and supervisor builders. The order is data, not method calls. And there is no Spring at all: plain Java with 14 jars.
Embabel: the planner orders the actions
/** The workflow in Embabel: actions with typed inputs and outputs; the planner finds the order. */
@Agent(description = "Triages a support ticket and drafts the reply")
public class TriageAgent {
public record Classification(String category, String priority) {}
public record Reply(String text) {}
@Action
public Classification classify(UserInput ticket, Ai ai) {
return ai.withDefaultLlm().createObject(
"Classify the support ticket. category: BILLING, ACCOUNT, TEAM or OTHER. "
+ "priority: HIGH, NORMAL or LOW. Ticket: " + ticket.getContent(),
Classification.class);
}
@AchievesGoal(description = "A reply to the ticket is drafted")
@Action
public Reply draft(UserInput ticket, Classification classification, Ai ai) {
return ai.withDefaultLlm().createObject(
"Write a reply of at most three sentences to this " + classification.category()
+ " support ticket. Sign off as The Relay Support Team. Ticket: " + ticket.getContent(),
Reply.class);
}
}
actions run: [org.studyeasy.threeways.TriageAgent.classify, org.studyeasy.threeways.TriageAgent.draft]
classification: Classification[category=BILLING, priority=HIGH]
reply: Hello Emma, We noticed two charges in your March invo ...
steps: planned by Embabel
The agent class is a Spring bean. Each action declares an input type and an output type: classify takes UserInput and gives a Classification. The goal is that a Reply exists. draft needs a Classification, so the planner runs classify first. You never wrote the order. Underneath, it runs on Spring AI (2.0.1 in this build).
Side by side
Spring AI is the base layer: models, tools, advisors, memory. The other two add a way to run several steps. Start with the simplest one that fits how you decide the steps. If you can write the path down, plain Spring AI keeps it visible (as in the supervisor article). If you want workflow objects without Spring, LangChain4j's agentic module gives you those. If the order should follow from types and goals, Embabel plans it. The Python side of the same question is in LangGraph vs CrewAI vs the Claude Agent SDK.
Recap
| Plain Spring AI | LangChain4j agentic | Embabel | |
|---|---|---|---|
| Who orders the steps | Your code | A workflow object | A planner, from types and a goal |
| How state moves | Variables you pass | Named values in a shared scope | Typed objects the planner tracks |
| Spring needed | Yes | No | Yes, runs on Spring AI |
| Result on this ticket | BILLING, HIGH | BILLING | BILLING, HIGH |
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Related course on Udemy
FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE
Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)Related posts
What Spring AI 2 Is, and Why a Java Team Wants It
Spring AI 2 is one Spring-style API for AI models: your code talks to a ChatClient, and the provider is a dependency and a setting. Follow one 'I was charged twice' call through advisors and the model to a Java record, see why 20,000 tickets a day is more than one HTTP call, and what the library leaves to you.
Spring AI ChatClient: One API for Any Model, and the Model Is a Property
A small Spring Boot chat service asks llama3.2:3b in Docker through one ChatClient chain, reads 43 tokens in and 60 out from the response, gets the same answer twice at temperature 0 with seed 42, then moves to llama3.2:1b with one environment variable and no code change.
Spring AI Prompt Templates: Placeholders, Few-Shot Messages and Versioned Prompt Files
PromptDesk keeps its prompts in .st files with {customer} and {ticket} placeholders, picks ticket-summary-v1 or v2 with one property, turns a chatty 'I would classify this as BUG' into plain BUG with two example messages, and refuses to send a prompt with a hole in it.
Spring AI Structured Output: From Model JSON to a Java Record, and a Real Ticket Triage Feature
A Triage record with two enums becomes the contract with the model. On llama3.2:3b only native structured output returned a valid record; format text alone left the JSON unclosed and the validation advisor tried three times for the same broken answer. Then Relay's triage: the model picks a category and priority, a config table picks the agent, and a dead model costs the customer one second, not seventy.
