A demo project showcasing AI agent orchestration using Spring Boot, LangChain4j, and LangGraph4j. Features two banking-domain agents that demonstrate the ReAct (Reason + Act) pattern with real-time visualization.
Investigates failed payment transactions by autonomously querying multiple banking systems.
How it works:
- Accepts a transaction ID
- Queries the transaction database
- Routes to the correct payment network (VISA / GIRO / PayNow) based on the provider
- Looks up error codes
- Produces a structured investigation report with root cause and recommendations
Tools: queryTransactionDb, checkCardNetwork, checkGiroStatus, checkPayNowStatus, lookupErrorCodes
Evaluates loan applicants by gathering data from multiple sources and producing a risk assessment.
How it works:
- Accepts an applicant ID
- Fetches credit bureau data
- Verifies income
- Checks existing loans
- Applies risk rules
- Flags anomalies
- Produces a risk assessment report with approval/denial recommendation
Tools: fetchCreditBureau, verifyIncome, checkExistingLoans, applyRiskRules, flagAnomalies
Both agents use the ReAct pattern — a single agent that loops through:
Think -> Pick Tool -> Execute -> Observe -> Repeat (until done)
Built with LangGraph4j's StateGraph:
START -> Human Input -> Agent (ReAct) <-> Tool Executor -> Final Report -> END
Note: ReAct was chosen for demo purposes — it visually shows the LLM reasoning at each step. In production, the Credit Risk agent would benefit from a fixed parallel graph for better performance and lower cost.
| Component | Version |
|---|---|
| Java | 21 |
| Spring Boot | 3.4.1 |
| LangChain4j | 1.1.0 |
| LangGraph4j | 1.8.4 |
| LLM | OpenAI GPT-4o-mini |
- Java 21+
- An OpenAI API key
-
Clone the repository:
git clone https://github.com/rkp4u/agent_demo.git cd agent_demo -
Set your API key (choose one):
Option A — Environment variable:
export OPENAI_API_KEY=your-key-hereOption B —
.envfile (not committed):echo "export OPENAI_API_KEY=your-key-here" > .env source .env
Option C — IntelliJ: Add
OPENAI_API_KEY=your-key-herein Run Configuration > Environment variables. -
Run the application:
./gradlew bootRun
-
Open the UI: http://localhost:8080
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/payment/investigate |
Run payment investigation |
POST |
/api/creditrisk/assess |
Run credit risk assessment |
Payment Investigation:
curl -X POST http://localhost:8080/api/payment/investigate \
-H "Content-Type: application/json" \
-d '{"transactionId": "TXN-98432"}'Credit Risk Assessment:
curl -X POST http://localhost:8080/api/creditrisk/assess \
-H "Content-Type: application/json" \
-d '{"applicantId": "APP-2024-1001"}'The demo includes a hybrid visualization UI combining:
- Agent Graph (left panel) — shows the LangGraph nodes lighting up as execution progresses
- Chat Interface (right panel) — displays the agent's reasoning chain with expandable steps and a final report card
src/main/java/com/demo/agent/
AgentDemoApplication.java
payment/
PaymentAgentGraph.java # LangGraph state machine
PaymentAgentState.java # Agent state definition
PaymentAgentService.java # Service layer
PaymentAgentController.java # REST endpoint
tools/
QueryTransactionDb.java # Simulated transaction DB
CheckCardNetwork.java # VISA/Mastercard lookup
CheckGiroStatus.java # GIRO transfer status
CheckPayNowStatus.java # PayNow transfer status
LookupErrorCodes.java # Error code reference
PaymentToolExecutor.java # Tool dispatcher
creditrisk/
CreditRiskAgentGraph.java
CreditRiskAgentState.java
CreditRiskAgentService.java
CreditRiskAgentController.java
tools/
FetchCreditBureau.java
VerifyIncome.java
CheckExistingLoans.java
ApplyRiskRules.java
FlagAnomalies.java
CreditRiskToolExecutor.java
src/main/resources/
application.yml # Config (API key via env var)
static/
index.html # Demo UI