beginner~2h

ChatClient, Messages & Prompts

A one-line chatClient.prompt(question).call().content() got you a response in Module 02. This module is everything that one line is quietly doing, and how to control it.

Learning objectives

  • Beginner: A single UserMessage per call, no system prompt — fine for a stateless Q&A demo with no persona requirements.
  • Intermediate: A defaultSystem persona plus a file-based PromptTemplate for a specific feature (e.g. a recommendation endpoint), keeping prompt text reviewable outside Java source.
  • Advanced: Recognize when prompt stuffing has silently become your bottleneck (rising latency/cost as your "reference doc" grows) and replace it with RAG — without changing the ChatClient call site at all, since retrieval is added via an Advisor (Module 06/09), not a rewrite of your prompting code.

This is a Pro chapter

Sign in, then upgrade to Pro or Power to unlock this and the full Spring Ecosystem Mastery library.

ChatClient, Messages & Prompts

Next Step

Continue to ChatOptions, Response Types & Streaming← Back to all Spring AI chapters