aregmi.net
Resume

The core pieces you use in every Spring AI project

essentials core-concepts spring-ai overview

Spring AI Essentials

Before jumping into specific examples, here's the stuff that shows up in every Spring AI project.

ChatClient

Everything starts with ChatClient. Think of it like RestTemplate but for LLMs.

@Bean
ChatClient chatClient(ChatClient.Builder builder) {
    return builder
        .defaultSystem("You are a helpful assistant.")
        .build();
}

Inject it, call .prompt(), get a response. That's the whole pattern.

How every call works

Same shape every time:

  1. Build a prompt (system message + user message)
  2. Add advisors if you need them (memory, RAG, logging)
  3. Call the model — .call() for sync, .stream() for streaming
  4. Get the response — string, entity, or structured type
String answer = chatClient.prompt()
    .user("What is Spring AI?")
    .call()
    .content();

The key pieces

Thing What it does
ChatClient Sends prompts, gets responses
@Tool Lets the LLM call your Java methods
ChatMemory Remembers previous messages
Advisor Middleware for requests/responses
.entity() Maps LLM output to Java objects

Each of these has its own page: