Skip to content

rkp4u/agent_demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Agentic AI in Practice — From Concept to Code

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.

Agents

1. Payment Investigation Agent

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

2. Credit Risk Assessment Agent

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

Architecture

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.

Tech Stack

Component Version
Java 21
Spring Boot 3.4.1
LangChain4j 1.1.0
LangGraph4j 1.8.4
LLM OpenAI GPT-4o-mini

Getting Started

Prerequisites

  • Java 21+
  • An OpenAI API key

Setup

  1. Clone the repository:

    git clone https://github.com/rkp4u/agent_demo.git
    cd agent_demo
  2. Set your API key (choose one):

    Option A — Environment variable:

    export OPENAI_API_KEY=your-key-here

    Option B — .env file (not committed):

    echo "export OPENAI_API_KEY=your-key-here" > .env
    source .env

    Option C — IntelliJ: Add OPENAI_API_KEY=your-key-here in Run Configuration > Environment variables.

  3. Run the application:

    ./gradlew bootRun
  4. Open the UI: http://localhost:8080

API Endpoints

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"}'

UI

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

Project Structure

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors