惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
云风的 BLOG
云风的 BLOG
Martin Fowler
Martin Fowler
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
量子位
Engineering at Meta
Engineering at Meta
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
罗磊的独立博客
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog RSS Feed
I
InfoQ
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
V2EX

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Run your first AI agent in Java — for free, with Mistral
sekka · 2026-05-27 · via DEV Community

Every "build an AI agent" tutorial I find assumes two things: you write Python, and you have a paid OpenAI key. I write Java and I didn't want to pay just to experiment.

So here's the version nobody writes: a real LLM-backed agent, on the JVM, for free — using Mistral's free tier and AgentFlow4J, an open-source orchestration runtime on top of Spring AI. About ten minutes, start to finish.

Step 1 — Create a Mistral account

Go to console.mistral.ai and sign up (email, Google, or GitHub). You land on La Plateforme, the developer console.

Step 2 — Get a free API key

Open API KeysCreate new key, name it, copy it (you only see it once).

Export it in your shell — never commit it:

export MISTRAL_API_KEY="sk-...your-key..."

Enter fullscreen mode Exit fullscreen mode

mistral-small is covered by the free tier, which is plenty for building and testing.

Step 3 — Add the dependencies

AgentFlow4J ships via JitPack. Add it plus Spring AI's Mistral starter:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.github.datallmhub.agentflow4j</groupId>
    <artifactId>agentflow4j-starter</artifactId>
    <version>v0.6.0</version>
</dependency>
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-starter-model-mistral-ai</artifactId>
</dependency>

Enter fullscreen mode Exit fullscreen mode

Step 4 — Point Spring AI at Mistral

# application.yml
spring:
  ai:
    mistralai:
      api-key: ${MISTRAL_API_KEY}
      chat:
        options:
          model: mistral-small-latest
          temperature: 0.3

Enter fullscreen mode Exit fullscreen mode

Step 5 — Write and run an agent

@Bean
CommandLineRunner demo(ChatClient.Builder chatClientBuilder) {
    Agent assistant = ExecutorAgent.builder()
            .name("assistant")
            .chatClient(chatClientBuilder.build())
            .systemPrompt("You are a concise, helpful assistant. Answer in one sentence.")
            .build();

    return args -> {
        AgentResult result = assistant.execute(
                AgentContext.of("What is backpressure in reactive streams?"));
        System.out.println("\nMistral says: " + result.text() + "\n");
    };
}

Enter fullscreen mode Exit fullscreen mode

Run with MISTRAL_API_KEY set, and you get a real answer from Mistral — your first LLM agent in Java, for free.

Why a runtime, not just a ChatClient?

A single call is easy. Real systems chain agents, pass state, retry, and need guardrails. That's what AgentFlow4J adds on top of Spring AI: graph orchestration, typed state, checkpoint/resume, and governance gates (budget caps, tool/state policies, human approval) — all idiomatic Java, no Python, no sidecar.

The cookbook has five runnable recipes (RAG, ticket triage, web research, Slack bot, batch processing) if you want to go further.


It's open source (Apache 2.0). If you've been wanting to build agents without leaving the JVM, I'd genuinely love your feedback: github.com/datallmhub/agentflow4j