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.
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.
| Framework | Model | Strength |
|---|---|---|
| LangGraph | Agents as explicit state graphs | Complex, cyclic, controllable workflows |
| CrewAI | Role-based agent crews | Multi-agent collaboration with defined roles |
| AutoGen | Conversational multi-agent | Agents that converse to solve problems |
| Semantic Kernel | Microsoft'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:
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
| Situation | Choice |
|---|---|
| Spring Boot app, standard patterns | Spring AI |
| JVM app, want portability or declarative style | LangChain4j |
| Learning, or want full control | No framework — write the loop |
| Need durable execution / complex state graphs | Evaluate a dedicated framework; weigh the runtime cost |
| Genuinely Python-only capability required | Python 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?
Do I need a framework to build an agent?
How do Python frameworks like LangGraph and CrewAI compare?
Should I use Python for agents even if my stack is Java?
Related tutorials
- Multi-Agent Systems (MAS)Building multi-agent systems in Java: orchestrator-worker coordination, agent handoffs, communication protocols and conflict resolution — and the honest case for when one agent is better.
- Building Autonomous Coding AgentsDesign autonomous coding agents in Java: code generation with verification, review agents that bias for precision, refactoring and test-generation agents — with the guardrails they need.
- Memory Systems for AgentsHow agent memory works beyond a chat window: working, episodic and semantic memory, vector-based recall, memory consolidation, and implementing persistent agent memory in Java.
- Agent Evaluation & TestingHow to evaluate and test AI agents: trajectory analysis, benchmarking, hallucination detection, outcome verification and human-in-the-loop evaluation — with Java patterns.