"Roll for Initiative... in Java!"
Welcome, brave adventurer, to the ultimate Spring AI quest! This comprehensive workshop will transform you from a coding apprentice into a master of AI agent orchestration using Java 25 and Spring AI. Through five epic chapters, you'll learn to create, equip, and command digital companions that can think, act, and collaborate like a legendary adventuring party.
Your journey through the realms of AI agents is carefully structured as a progressive quest. Each chapter builds upon the previous one - complete them in order to unlock the full power of Spring AI!
๐งโโ๏ธ Chapter 1: The Art of Agent Summoning
Master the fundamental ritual of agent creation
- Learn what Spring AI is and how it works
- Summon your first AI companion โ a Dungeon Master chatbot
- Configure Amazon Bedrock models and system prompts
- Understand the core concepts of agent development
Equip your agents with community-powered tools
- Discover Spring AI community tools (
spring-ai-agent-utils) - Learn how agents autonomously choose and use tools
- Master web scraping and information gathering with
SmartWebFetchTool - Understand tool registration and the agentic loop
Forge your own custom tools and enchantments
- Transform Java methods into agent tools with
@Tooland@ToolParam - Create the legendary Dice of Destiny
- Master the
//SOURCESdirective for multi-file JBang projects - Build domain-specific capabilities using Java 25 records
Expose tools as remote services through Model Context Protocol
- Build and deploy an MCP server with Spring Boot and
@McpTool - Create an MCP client with an interactive REPL
- Understand distributed tool architectures over Streamable HTTP
- Master external service connections using
SyncMcpToolCallbackProvider
Command multiple agents in perfect harmony
- Build a complete multi-agent D&D system with character inventory management
- Master Agent-to-Agent (A2A) communication with
AgentCardandAgentExecutor - Orchestrate specialized agents (Rules, Character, Game Master) working together
- Implement conversation memory with
MessageChatMemoryAdvisor - Combine A2A, MCP, and RAG in a single architecture
Before you start, commit to one of the two paths below. Both are first-class โ pick the one that fits how you want to work.
For: Java developers curious to try a new way of running Java, and non-Java developers who want a minimal setup.
Tooling: JBang CLI + any text editor (VS Code, Sublime, nano โ whatever you like).
You'll run code like this: jbang DungeonMasterSimple.java
The contract: Follow the workshop instructions exactly as written. If you deviate, you're on your own.
For: Java developers who want to work the way they usually do.
Tooling: IntelliJ IDEA + Maven. No JBang needed.
Prerequisite: You already have IntelliJ IDEA for Java installed on your laptop (Community or Ultimate). This path does not cover installing the IDE.
You'll run code like this: open chapter1-maven/ in IntelliJ, click the green arrow next to main() in DungeonMasterSimple.java.
The contract: Work the way you normally do. If your IntelliJ / Maven / JDK setup has quirks, you're on your own.
โ ๏ธ Pick one and stick to it. Mixing paths (editing the JBang file while running the Maven project, or vice versa) is the fastest way to get confused.
Before embarking on this legendary adventure, ensure you have:
- Java 25 as your trusty spellcasting focus.
Install JBang
JBang runs .java files directly with dependencies declared as //DEPS comments โ no Maven, no Gradle, no pom.xml.
curl -Ls https://sh.jbang.dev | bash -s - app setup
jbang --versionInstall Java 25 via JBang
jbang jdk install 25
jbang jdk default 25
eval $(jbang jdk java-env)
java -version # Should show: openjdk version "25"To make this permanent, add eval $(jbang jdk java-env) to your ~/.bashrc or ~/.zshrc.
Install Java 25
Install JDK 25 the way you normally do โ Amazon Corretto, Homebrew (brew install openjdk@25), or your usual JDK manager. Verify:
java -version # Should show: openjdk version "25"Amazon Bedrock API Key โ this content uses Amazon Bedrock so make sure to get your API key to get started
- Sign in to the Amazon Bedrock Console
- In the left navigation pane, select API keys
- Click the Short-term API keys tab, then choose Generate short-term API key
- Copy the generated API key and set it as an environment variable:
export AWS_BEARER_TOKEN_BEDROCK=<your-api-key>๐ก Tip: A plain
exportonly lives in the current terminal. If you'd like every new shell, IDE run-config, and tool to inherit it, add the line to~/.zshenv(zsh) or~/.bash_profile(bash) instead. This avoids the classic "why isn't my agent answering?" surprise when you open a new terminal mid-workshop.
A sense of adventure and willingness to experiment! ๐ฒ
Before running Chapter 1, paste this into your terminal โ it gives a one-glance health check.
java -version
echo "Bedrock: ${AWS_BEARER_TOKEN_BEDROCK:+OK (length=${#AWS_BEARER_TOKEN_BEDROCK})}${AWS_BEARER_TOKEN_BEDROCK:-MISSING โ see step 3}"You should see openjdk version "25" line and Bedrock: OK (length=NNNN).
If Bedrock says MISSING, revisit Amazon Bedrock API Key step above.
- Progress through each chapter - Don't skip ahead, each chapter introduces essential concepts
- Complete all TODOs - Each chapter has guided exercises to master the concepts
- Test your creations - Run your agents with
jbangand see them come to life - Experiment and explore - Try variations and push the boundaries
Each chapter follows the same magical pattern:
- ๐ README Guide: Complete instructions and background lore
- ๐ฏ TODO Exercises: Hands-on coding challenges to complete
- ๐งช Testing Instructions: How to verify your magical creations work
- ๐ Solution Reference: Complete working examples in the solution branch
Spring AI is a powerful framework for creating AI-powered applications in Java - think of it as your spellbook for summoning digital companions that can interact with tools and services. Like a well-equipped adventuring party, Spring AI provides:
- ๐ญ Agent Creation: Easy summoning via
ChatClientโ the gateway to AI conversations - โ๏ธ Tool Integration: Built-in
@Tool/@ToolParamannotations and community tools - ๐ Model Flexibility: Support for multiple AI providers (Amazon Bedrock, OpenAI, Ollama, and more)
- ๐ External Connections: Integration with services through MCP (Model Context Protocol)
- ๐ฐ Multi-Agent Systems: Coordinate multiple agents using A2A (Agent-to-Agent) protocol
- ๐ค ChatClient: The central abstraction for interacting with an AI model in Spring AI
- ๐ง @Tool: Annotation that transforms a Java method into a callable AI function
- ๐ System Prompt: The character sheet defining your agent's personality and behavior
- ๐ง ChatModel: The bridge to the AI provider (Bedrock, OpenAI, etc.)
- ๐ MCP: Model Context Protocol for connecting to external tool servers
- ๐ฐ A2A: Agent-to-Agent protocol for multi-agent communication
- ๐ JBang: Build tool that runs
.javafiles directly with embedded//DEPSmetadata
The repo ships two parallel views of the same content โ pick the tree that matches your path.
sample-once-upon-spring-ai/
โโโ README.md
โโโ chapter1/ # ๐งโโ๏ธ The Art of Agent Summoning
โ โโโ DungeonMasterSimple.java
โโโ chapter2/ # โ๏ธ AI Agent with Built-in Tools
โ โโโ DungeonMasterWithBuiltInTools.java
โโโ chapter3/ # ๐จ The Adventurer's Arsenal
โ โโโ DiceTools.java
โ โโโ DungeonMasterWithCustomTools.java
โโโ chapter4/ # ๐ The Tavern Notice Board (MCP)
โ โโโ DiceRollMcpServer.java
โ โโโ DungeonMasterMCPClient.java
โ โโโ application.properties
โโโ chapter5/ # ๐ฐ The Council of Agents (A2A)
โโโ agents/
โ โโโ rules/
โ โ โโโ RulesAgent.java # D&D rules lookup agent with RAG
โ โ โโโ RulesTools.java # PDF knowledge base search tools
โ โโโ character/
โ โ โโโ CharacterAgent.java # Character management agent
โ โ โโโ CharacterTools.java # Character CRUD & inventory tools
โ โ โโโ characters.json # Persistent character storage
โ โโโ gamemaster/
โ โโโ GameMasterOrchestrator.java # Spring Boot app with A2A + MCP
โ โโโ GameMasterService.java # Agent discovery & orchestration
โ โโโ GameMasterController.java # REST API endpoints
โโโ test/
โ โโโ test.http # HTTP test requests
โโโ utils/
โโโ CreateKnowledgeBase.java # PDF โ vector store ingestion
sample-once-upon-spring-ai/
โโโ chapter1-maven/ # Mirror of chapter1 โ runs DungeonMasterSimple
โโโ chapter2-maven/ # Mirror of chapter2 โ runs DungeonMasterWithBuiltInTools
โโโ chapter3-maven/ # Mirror of chapter3 โ runs DungeonMasterWithCustomTools
โโโ chapter4-maven-server/ # MCP server (DiceRollMcpServer + application.properties)
โโโ chapter4-maven-client/ # MCP client (DungeonMasterMCPClient)
โโโ chapter5-maven/ # Multi-module Maven project for the A2A council
โโโ rules/ # โ RulesAgent, RulesTools
โโโ character/ # โ CharacterAgent, CharacterTools, characters.json
โโโ gamemaster/ # โ GameMasterOrchestrator, Service, Controller
โโโ utils/ # โ CreateKnowledgeBase
๐ก Chapter 4 is split into two Maven projects (
-serverand-client) because MCP requires the server and client to run as independent processes โ each gets its ownpom.xmland IntelliJ run config. Chapter 5 is a single multi-module project so the four agents share dependencies and can be launched from one IntelliJ window.
You must have permissions to Amazon Bedrock in an AWS account. You can use any model available in your Bedrock console โ simply update the model ID in each chapter's source file to match your preferred model.
This content default to:
- ๐ญ Anthropic Claude (via Amazon Bedrock) โ All chapters
- ๐งฎ Amazon Titan Embed Text V2 โ Chapter 5 (vector store embeddings)
By completing this workshop, you'll master:
- โ
Agent Fundamentals: Create, configure, and deploy AI agents with Spring AI and
ChatClient - โ
Tool Mastery: Use community tools and create custom ones with
@Tool - โ External Integration: Connect agents to external services via MCP
- โ Multi-Agent Systems: Build distributed applications with A2A protocol
- โ
Modern Java: Leverage Java 25 features โ records, unnamed classes, text blocks,
var, and JBang
This workshop is a low-bar, practical intro. Spring AI has many more abstractions than we could cover in five chapters. If you want to go deeper, here's a curated path โ grouped so you can dive into whatever caught your interest.
- ๐ Spring AI Reference Documentation โ the complete guide
- ๐ค ChatClient API โ fluent prompts, system prompts, entity mapping
- ๐งฉ Advisors API โ the interceptor chain behind memory, RAG, and logging (Chapter 5 uses
MessageChatMemoryAdvisor) - ๐ง Tool Calling โ the full
@Tool/@ToolParammodel from Chapters 3โ4 - ๐ Retrieval-Augmented Generation (RAG) โ the patterns behind Chapter 5's rules agent
- ๐๏ธ Vector Stores โ swap the in-memory
SimpleVectorStorefor OpenSearch, pgvector, and more - ๐ง Chat Memory โ short-term conversation memory, the foundation for stateful agents
- ๐ป Spring AI GitHub โ source, issues, and release notes
- ๐ฑ Spring AI Community โ
agent-utils(Chapter 2) and the A2A bindings (Chapter 5) live here
- โ๏ธ Amazon Bedrock Documentation โ model access and setup
- ๐ญ Bedrock Converse API โ the unified inference API
BedrockProxyChatModelcalls under the hood - ๐ Bedrock API keys โ the short-term key you generated in setup
- ๐งฎ Titan Text Embeddings V2 โ the embedding model powering Chapter 5's RAG
- ๐ Model Context Protocol โ the MCP spec (Chapter 4)
- ๐ MCP Java SDK โ the
io.modelcontextprotocolclient/server library you used - ๐ A2A Protocol โ Agent-to-Agent specification (Chapter 5)
- ๐ง Spring AI MCP โ how Spring AI wires MCP into the
ChatClient
- ๐ JBang Documentation โ JBang user guide
- โ JEP 512: Compact Source Files & Instance Main Methods โ why
void main()works without a class - ๐งฑ Spring Modulith โ when your agent grows past a single file and you want clean module boundaries
- ๐๏ธ AWS Agentic AI Patterns โ the pattern catalog (Tool-Based, RAG, Memory, Multi-Agentโฆ) this workshop demonstrates
- ๐ข Amazon Bedrock AgentCore โ managed runtime, memory, gateway, and identity for taking these agents to production
Remember, the most epic adventures are the ones you create yourself. Whether you're building the next great AI application or just exploring the boundaries of what's possible, you now have the tools and knowledge to make it happen.
May your agents be wise, your tools be sharp, and your code compile on the first try! ๐ฒโจ
"The best way to predict the future is to build the agents that will create it." - Modern Developer Wisdom
Happy coding, Agent Master! ๐โ๏ธ๐งโโ๏ธ
