Menu

1 / 2

Building an AI Shirt Agent with Java and Spring AI: Tools, ChatClient, and REST

DEV Community: java·Said Olano·about 19 hours ago
#itR4yoyc
#devtojava#devto#dev#tool#fullscreen
Reading 0:00
15s threshold

Introduction

Large language models are good at understanding requests, but they do not know your inventory, your prices, or your business rules. The usual answer is to give the model tools : ordinary Java methods it can call when it needs information. The model decides when to call a tool, your code runs it, and the model uses the result to answer.

Spring AI brings this pattern into the Spring ecosystem. You define a tool with an annotation, hand it to a ChatClient , and ask for a typed response. In this article we build a small but complete example:

An agent that returns a t-shirt (in Spanish, playera ) in a requested color.

A REST controller that receives the item and the color as a JSON request.

A service that is injected with the agent and orchestrates the call.

The code is written for Spring Boot 3 and Spring AI 1.x.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.