Spring AI · Agentic patterns
Routing Workflow
Classify an input first, then answer it with a prompt written for that category. A Spring AI example of the routing pattern from "Building Effective Agents".
The routing
- billingCharges, refunds and payment options
- technicalSteps and workarounds
- accountRecovery and security checks
- productFeature education and examples
input → classifier → one route → answer
Two variations
Classifier
The model reads the input and returns its reasoning and one route name, as structured output.
Handlers
Each route has its own prompt. The router sends the input to the one the classifier chose.
Stack
| Language | Java 17 or later |
|---|---|
| Framework | Spring Boot 4.1.1 with Spring AI |
| Models | Anthropic Claude through the Spring AI model starter |
| Output | Structured classifier output mapped to a record |
Run it
export ANTHROPIC_API_KEY=your-key
./mvnw spring-boot:run
The demo runs three sample support tickets through the router and prints each answer.
Classes
RoutingWorkflow | Classifies the input and runs the selected route's prompt. |
|---|---|
RoutingResponse | Record with reasoning and selection. |
Application | Defines the four routes and runs the sample tickets. |