Skip to content
JavaAgentic

Type at least two characters. Try “RAG”, “pgvector” or “tool calling”.

Agent Frameworks Compared

A practical comparison of agent frameworks for Java developers: LangChain4j, Spring AI, and how the Python ecosystem (LangGraph, CrewAI, AutoGen) compares — plus when to use no framework at all.

Intermediate4 min readUpdated
On this page

There are many agent frameworks and a lot of noise about them. For a Java developer the practical choice is narrower than the landscape suggests, and often the answer is "no framework". This tutorial compares the real options and gives you a way to decide.

Key Takeaways

  • On the JVM, the mature choices are LangChain4j and Spring AI.
  • Many agents need no framework — a bounded loop around a tool-calling model.
  • Python frameworks (LangGraph, CrewAI, AutoGen) are capable but cost you a second runtime.
  • Choose a framework for durable execution, complex graphs or built-in observability — not by default.

The JVM options

LangChain4j

Declarative AiServices, broad integrations, framework-neutral. You define an interface with tools, memory and retrieval, and it runs the agent loop.

Agent agent = AiServices.builder(Agent.class)
        .chatModel(model)
        .tools(new InvestigationTools())
        .chatMemoryProvider(id -> MessageWindowChatMemory.withMaxMessages(20))
        .maxSequentialToolsInvocations(8)
        .build();

Best when you want portability across frameworks or the declarative style. See LangChain4j agents and tools.

Spring AI

Fluent ChatClient with advisors and tools, auto-configured in Spring Boot, Micrometer observability out of the box.

ChatClient agent = builder
        .defaultSystem(GOAL)
        .defaultTools(new InvestigationTools())
        .build();

Best when you are already in Spring Boot and want configuration, metrics and testing to follow your existing conventions. See Spring AI function calling.

The Python ecosystem, briefly

You will hear these names; here is what they are, so you can evaluate honestly rather than by hype.

FrameworkModelStrength
LangGraphAgents as explicit state graphsComplex, cyclic, controllable workflows
CrewAIRole-based agent crewsMulti-agent collaboration with defined roles
AutoGenConversational multi-agentAgents that converse to solve problems
Semantic KernelMicrosoft's orchestration SDK.NET and Python enterprise integration

They are genuinely capable. They are also Python-first, and adopting one means running a Python service alongside your JVM stack.

The "no framework" option

A surprising amount of agent work needs no framework beyond a model client. A ReAct agent is a loop:

An agent without a framework
public String run(String goal) {
    List<Message> conversation = new ArrayList<>(List.of(system(GOAL), user(goal)));
 
    for (int step = 0; step < MAX_STEPS; step++) {
        Response response = model.call(conversation, tools);
 
        if (response.isFinalAnswer()) {
            return response.text();
        }
        // Execute the requested tool, append the result, loop.
        ToolResult result = execute(response.toolCall());
        conversation.add(assistant(response.toolCall()));
        conversation.add(toolResult(result));
    }
    return "Reached step limit without concluding.";
}

That is a complete, debuggable agent in a dozen lines. You control the loop, the budget, the logging and the guardrails directly — no framework magic to reverse-engineer when it misbehaves.

Choosing

SituationChoice
Spring Boot app, standard patternsSpring AI
JVM app, want portability or declarative styleLangChain4j
Learning, or want full controlNo framework — write the loop
Need durable execution / complex state graphsEvaluate a dedicated framework; weigh the runtime cost
Genuinely Python-only capability requiredPython framework as a separate service

The decision is smaller than the discourse. Start with LangChain4j or Spring AI, or no framework at all, and add complexity only when a concrete need appears.

Next

Frequently Asked Questions

What is the best agent framework for Java?
For JVM applications, LangChain4j and Spring AI are the two mature choices. LangChain4j offers a declarative AiServices style and broad integrations; Spring AI fits naturally into Spring Boot with auto-configuration and Micrometer observability. For many agents you need no dedicated framework at all — a bounded loop around a tool-calling model is often enough.
Do I need a framework to build an agent?
No. A basic ReAct agent is a loop around a model that supports tool calling, and both Spring AI and LangChain4j run that loop for you already. Dedicated agent frameworks add value for durable execution, complex multi-agent graphs and built-in observability — reach for them when you hit those needs, not by default.
How do Python frameworks like LangGraph and CrewAI compare?
LangGraph models agents as explicit state graphs, good for complex, cyclic workflows; CrewAI focuses on role-based multi-agent collaboration; AutoGen on conversational multi-agent patterns. They are Python-first. On the JVM you get comparable capability from LangChain4j and Spring AI without leaving your stack, which usually outweighs any single feature difference.
Should I use Python for agents even if my stack is Java?
Rarely worth it. Adding a Python service means a second runtime, deployment pipeline and on-call surface, plus a network hop between your data and the agent. If your data, security and operations are on the JVM, building agents there with LangChain4j or Spring AI avoids all of that. Cross the language boundary only for a capability you genuinely cannot get on the JVM.

Related tutorials