This repository demonstrates how to build a decision-making AI agent using the Embabel Framework and Spring Boot. The application showcases an agent that uses conditional logic to handle an e-commerce product replacement workflow. Based on product inventory, the agent intelligently decides whether to issue a replacement or process a refund, all orchestrated by Embabel's planner.
📖 Complete Guide: For detailed explanations and a full code walkthrough, read our comprehensive tutorial.
👉 Embabel Framework Condition Annotation: Building Decision Making AI Agents
🎥 Video Tutorial: Prefer hands-on learning? Watch our step-by-step implementation guide.
👉 YouTube Tutorial - Embabel Framework @Condition Annotation - Build AI Agents with Conditional Logic
This application showcases an intelligent agent with a rule-based workflow:
- Conditional Logic using Embabel's
@Conditionannotation to control the agent's flow. - Decision-Making Workflow that chooses between issuing a replacement or a refund.
- Dynamic Planning where the agent forms a plan based on runtime inventory status.
- Separation of Concerns using deterministic Java for business rules (inventory check) and an LLM for creative tasks (generating user messages).
- A REST API Endpoint for easy integration and testing of the agent's decision-making capabilities.
Before running this application, ensure you have:
- Java 21 or higher
- OpenRouter API Key (free tier available at OpenRouter.ai)
git clone https://github.com/BootcampToProd/embabel-condition-demo-ecommerce-replacement-agent.git
cd embabel-condition-demo-ecommerce-replacement-agentProvide your OpenRouter API key as an environment variable. You can set this in your IDE's run configuration or directly in your terminal.
OPENROUTER_API_KEY={YOUR_OPENROUTER_API_KEY}mvn clean installmvn spring-boot:runThe application will start on http://localhost:8080.
Once the application is running, you can test the agent's conditional logic by sending POST requests for both an in-stock and an out-of-stock product.
curl --location 'http://localhost:8080/api/v1/ecommerce/product/replacement' \
--header 'Content-Type: application/json' \
--data '{
"productSku": "SKU-HDPHN-01",
"problemDescription": "The headphones have a crackling sound in the right ear."
}'{
"decisionCode": "REPLACEMENT_ISSUED",
"message": "Your return has been approved. A replacement unit has been ordered and will be shipped to you soon."
}curl --location 'http://localhost:8080/api/v1/ecommerce/product/replacement' \
--header 'Content-Type: application/json' \
--data '{
"productSku": "SKU-KBD-05",
"problemDescription": "The W key on my keyboard is not working."
}'{
"decisionCode": "REFUND_ISSUED",
"message": "We're sorry, but the product you requested a replacement for is currently out of stock. A refund has been issued to your original payment method."
}