Spring / Spring AI interview questions
What message types does Spring AI support in a Prompt?
A Prompt in Spring AI wraps a list of typed Message objects that correspond directly to the role-based message structure used by modern LLM APIs. Spring AI defines four concrete message types:
| Class | Role | When to use |
|---|---|---|
SystemMessage | system | Set the model persona, constraints, and instructions for the whole conversation |
UserMessage | user | The end-user's current input or question |
AssistantMessage | assistant | A prior AI response — used to reconstruct conversation history for multi-turn dialogs |
ToolResponseMessage | tool | The result returned from a function/tool call, sent back to the model to complete its answer |
When you build a Prompt manually you construct these objects yourself:
List<Message> messages = List.of(
new SystemMessage("You are a concise code reviewer. Focus on correctness."),
new UserMessage("Review this method:\n" + code)
);
Prompt prompt = new Prompt(messages,
OpenAiChatOptions.builder().temperature(0.2).build());
ChatResponse response = chatModel.call(prompt);In practice, when using ChatClient you rarely construct message objects directly — the .system() and .user() builder methods create them under the hood. You only need to deal with AssistantMessage and ToolResponseMessage explicitly when managing your own conversation history or implementing custom tool loops.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
