shirts-agent

A Spring Boot and Spring AI example. An AI agent recommends a t-shirt in a requested color by calling a @Tool method over an in-memory catalog.

Java 21Spring Boot 3.5.6Spring AI 1.1.8OpenAI gpt-4o-miniMaven
View source on GitHub Read the full README

How it works

ShirtController receives the request, ShirtService validates it, and ShirtAgent asks the model to find a shirt. The model calls ShirtCatalogTool.findShirtByColor and returns a structured Shirt. Invalid input returns HTTP 400 without calling the model.

Stack and infrastructure

AreaStatusDetails
PersistenceNoneIn-memory catalog of four shirts
MessagingNot usedNo broker or events
CloudNot usedCalls the OpenAI API
DockerNot usedNo Dockerfile or compose file; port 8080

Run it locally

git clone https://github.com/josesaid/shirts-agent.git
cd shirts-agent
export OPENAI_API_KEY=sk-...
mvn spring-boot:run

curl -X POST http://localhost:8080/api/shirts/recommend \
  -H "Content-Type: application/json" \
  -d '{"item":"playera","color":"red"}'

Requires JDK 21 and Maven 3.9 or later. Unit tests run with mvn test and do not call the model.

Endpoint

MethodPathPurpose
POST/api/shirts/recommendRecommend a shirt by item and color