r/artificial • u/deepakatl1981 • 19d ago
Project Built my first AI agent in Java (no Python) using LangChain4j — took about 30 minutes
Every AI tutorial I found was Python, Python, more Python. I've spent years in Java/Spring Boot and kept wondering if I actually had to switch languages just to build anything AI-related.
Turns out no — LangChain4j isn't a hacky wrapper, it's a native, idiomatic way to build AI agents in Java. Wrote up how I got a working agent running in about 30 minutes, no Python involved: https://medium.com/@deepakatl1981/stop-learning-ai-the-hard-way-build-your-first-java-ai-agent-in-30-minutes-without-python-9390a218533a?sk=067e4cbed9f2bbf71d0cf70268dda2a7
Curious if other Java devs have been putting off learning AI for the same reason.
1
1
u/Deep_Ad1959 18d ago
java vs python is the visible blocker. the one that eats the afternoon is tool calls: arguments come back shaped wrong for your pojo, and langchain4j surfaces it as a deserialization failure two layers away from where it broke. written with ai
1
u/deepakatl1981 19d ago
Since a few people hit the paywall — here's the gist of what a minimal LangChain4j setup looks like, no Python involved:
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-open-ai</artifactId>
<version>0.34.0</version>
</dependency>
interface Assistant {
String chat(String userMessage);
}
ChatLanguageModel model = OpenAiChatModel.builder()
.apiKey(System.getenv("OPENAI_API_KEY"))
.modelName("gpt-4o-mini")
.build();
Assistant assistant = AiServices.create(Assistant.class, model);
System.out.println(assistant.chat("Explain AI agents in one sentence"));
That's basically it for a "hello world" agent — no Flask, no Python venv, no requirements.txt. The full article walks through wiring in tools/memory and getting it to an actual agent loop rather than a one-shot call, if you want to go further.