Spring AI Recipes
AI isn’t just for Python developers anymore. With Spring AI, Java and Spring developers can build powerful AI agents and intelligent applications directly within the platform they already trust for enterprise software.
As I've worked with Spring AI for the past few years, I've created a sizable number of “recipes” in my notebook. Rather than keep them to myself, I've decided to share them for anyone who may learn from them. (All recipes are hosted at Medium.com.)
If you like what you read here, then you should check out my books.
Recently added
All recipes
Explaining Tool Selection
Understanding why an LLM chose a specific tool can be just as important as the tool call itself. Today's Spring AI Recipe shows how to use AugmentedToolCallbackProvider to capture and inspect tool-selection reasoning from the model.
Better LLM Request/Response Logging with ToolCallAdvisor
Sometimes the most interesting part of an LLM interaction isn't the initial prompt or final response - it's everything that happens in between. With Spring AI's ToolCallAdvisor, you can finally see the full tool-calling conversation unfold in your logs, no matter which model abstraction you're using.
Securing an MCP Server with an API Key
Tools give agents power. Security determines who gets to use that power. In this recipe, learn how to add API Key security to your MCP servers.
Adding a Loop to a Graph-Based Workflow
What if your workflow could take a second pass at its own answer before showing it to the user? By adding a simple loop, you can turn a one-shot response into an iterative process that refines itself until it’s actually useful.
Adding Human-in-the-Loop to a Graph-based Agentic Workflow
Sometimes the smartest thing an AI can do is admit that it’s unsure. Instead of guessing, a graph-based agentic workflow can pause, ask for human guidance, and then continue with confidence. See how to add human-in-the-loop to a graph-based workflow.
Building a Graph-Based Agentic Workflow
Completely autonomous agents are like unplanned road trips--flexible and full of adventure, but unpredictable and potentially surprising. Graph-based workflows provide the roadmap, while still allowing intelligent decisions along the way. Build a graph-based agentic workflow with Spring AI Alibaba Graph.
Creating an MCP Client
Build an MCP client and give tools from an MCP server to your agent.
Streamable HTTP MCP Server
So you’ve built an MCP server with STDIO? That’s great! Now take it from local integration to network-accessible service, by creating a Streamable HTTP MCP server.
Creating an STDIO MCP Server
An agent without tools is just thinking really hard.Give it something to do. Create an STDIO MCP server to provide capabilities to an agent.
Enabling Long-Term Memory
Your agent may be smart. But how is its memory? Learn how to add long-term memory to your agents so that it learns and remembers significant information.
Invoking A2A Sub-Agents with TaskTool
A2A isn’t just about exposing agents--it’s about using them. Use TaskTool to invoke A2A sub-agents.
Enabling Agent-to-Agent Communication with A2A
You've built an agent. But if no other agent can find or use it...what’s the point? See how to enable agent discovery and communication using Agent-to-Agent (A2A).
Reusing Agent Behavior with SkillsJars
Tools give capabilities. Skills give direction. SkillsJars make it reusable. Find out how to add plug-and-play agent behavior with Spring AI and SkillsJars.
Guiding Agentic Behavior with Skills
Tools give your agent capabilities. Skills give it direction. Learn how to guide agent behavior with Skills in Spring AI.
Agentic Planning with TodoWriteTool
What if your LLM didn’t just answer questions—but made a plan and executed it? See how to enable agentic planning with TodoWriteTool.
Asking Questions to the User
We often ask questions to LLMs and get back answers. What if the LLM wants to ask us something? See how to use AskUserQuestionTool to make the human a part of the loop.
Logging LLM Requests and Responses
Keep your ChatClient configuration code neat, tidy, and gain the opportunity to enable/disable it with configuration properties.
Composing ChatClient Behavior
Keep your ChatClient configuration code neat, tidy, and gain the opportunity to enable/disable it with configuration properties.
Building a Text-Based Chat Loop Around ChatClient
Build a simple conversational loop with Spring AI’s ChatClient that continuously accepts user input, sends it to an LLM, and returns the response in real time.


