name: generate-spring-ai-feature description: Generates a Spring AI 2.0.0-M6 feature on Spring Boot 4.0.6 — ChatClient calls, Advisors, RAG with PgVector, structured output, tool/function calling. Use when the user asks for an AI capability (chat, summarisation, classification, agentic tools).
generate-spring-ai-feature
When to use
Any backend feature that calls a chat model, embeds documents, runs RAG, or exposes tools to a model.
Required design choices
- API surface: a typed
interfacedescribing inputs/outputs as records. Never expose rawString. - ChatClient: built once via
ChatClient.Builder, configured with default Advisors. - Advisors: at least logging + safety. Add
MessageChatMemoryAdvisorif the feature is conversational. Add a RAG advisor if grounding is required. - Structured output: target a
record. Use Spring AI's structured output converters — never parse JSON by hand. - Tool/function calling: declare a typed callback interface, annotate with
@Toolfrom Spring AI 2.0. Always supply explicitconversationIdto chat memory advisors. - Vector store: PgVector if PostgreSQL is present, else the project's default. Configure dimension to match the chosen embedding model.
- Prompts: live in
src/main/resources/prompts/<feature>.st, never inline.
Required rules
- No secrets in code. API keys via env vars +
@ConfigurationPropertiesrecord. - Every model input crossing a tool boundary is validated and sanitised to prevent prompt injection.
- Streaming endpoints use
Flux<String>(server-sent events) orFlowif Kotlin. - Invoke
generate-junit-testandgenerate-integration-test(with Testcontainers Ollama or wiremock) after generation.
Validation
validate-java25-idioms,enforce-documentation, JUnit suite green.scan-source-vulnerabilitiesfinds no prompt-injection vector.
Failure modes
- No vector store configured but RAG requested → ask
architect. - Chosen embedding dimension differs from existing index → stop.