Skip to main content

Agentic AI – with Java (Spring Boot POC)

 

This project is a simple Agentic AI Proof of Concept built using Spring Boot + Spring AI + OpenRouter (LLM).

It demonstrates how an AI Agent can investigate a problem step-by-step (like a human engineer) instead of following a fixed hardcoded workflow.


🎯 What Problem Does It Solve?

Given a goal like:

“Why is my Order API slow?”

The agent will:

  1. Check system metrics

  2. Check database performance

  3. Check Kafka lag (optional)

  4. Correlate results

  5. Find the root cause

  6. Stop automatically


🤖 What Is “Agentic AI” Here?

This is NOT a chatbot.

This is:

A state machine where an LLM is used only to decide the next step.

The LLM:

  • Does NOT access DB

  • Does NOT access metrics

  • Does NOT execute anything

It only says:

“Check metrics”
“Now check DB”
“Now we are done”

All real work is done by Java code (tools).


🏗️ Architecture (Simple View)

User Goal ↓ Agent Loop ↓ LLM decides next action ↓ Java executes tool (DB / Metrics / Kafka) ↓ Result stored in memory ↓ Loop again until root cause found

🔁 Agent Execution Loop (Core Idea)

while(not finished): build prompt using (goal + memory) ask LLM what to do next execute that tool in Java store result in memory check stop condition

This is called:

Think → Act → Observe → Think → Act → Stop


🧩 Components

1. ObservabilityAgent

  • The main orchestrator

  • Runs the loop

  • Talks to LLM

  • Calls tools

  • Decides when to stop

2. Tools (Simulated)

  • MetricsTool → returns API latency

  • DbTool → returns slow query info

  • KafkaTool → returns consumer lag

(You can replace these with real Prometheus / DB / Kafka later.)

3. MemoryStore

  • Stores investigation history

  • Passed back to LLM every iteration

  • Prevents the agent from “forgetting”

4. LLM (via OpenRouter)

  • Used only for decision making

  • Returns which action to perform next


🛑 Very Important Design Rule

The agent is NOT allowed to run forever.

The code contains hard stop conditions, for example:

  • If a slow query is found → STOP

  • If max iterations reached → STOP

Never let an LLM control termination in production systems.


▶️ How to Run

1. Get a Free API Key

2. Configure application.yml

spring: ai: openai: api-key: YOUR_OPENROUTER_KEY base-url: https://openrouter.ai/api/v1 chat: options: model: mistralai/mistral-7b-instruct:free server: port: 8080

3. Run Spring Boot App

4. Call in Browser

http://localhost:8080/analyze?goal=Why is Order API slow?

or

http://localhost:8080/analyze?goal=Why is my system metrics?

✅ Example Output

FINAL DIAGNOSIS: CHECK_DB => Found slow query: SELECT * FROM orders WHERE status='PENDING' (no index)

🧠 What This Demonstrates (Interview Points)

  • Agentic AI = LLM + Loop + Tools + Memory

  • LLM used as decision engine, not execution engine

  • Deterministic execution + probabilistic reasoning

  • Safe termination conditions

  • Real-world use case: production incident investigation


🚫 What This Is NOT

  • Not a chatbot

  • Not autonomous

  • Not replacing real code

  • Not suitable for core transaction logic

It is for:

Diagnosis, investigation, exploration, triage, decision support


🚀 Future Improvements

  • Replace fake tools with:

    • Prometheus client

    • Real DB queries

    • Kafka Admin client

  • Use Spring AI Tool Calling instead of parsing text

  • Add Verifier Agent

  • Add Planner Agent


🏁 Final Summary

This project shows how to build a controlled, safe, enterprise-style Agentic AI system using Spring Boot, where an LLM helps in reasoning, but all execution remains in deterministic Java code.

Comments

Popular posts from this blog

Camunda Spring Boot with Shared Engine with War file

This is the only one website (may be first) to show an example to create working war file for camunda shared engine using Spring Boot. We analysed the problem using pure spring boot "starter" dependencies that it contains camunda engine plus tomcat, so even when you remove tomcat using either <provided> or <exclude>, it continues to run on tomcat as its already with in camunda engine. And when you try to create war file and paste in into shared camunda engine outside then that war will no work. This is because that war you created containing camunda engine and a tomcat inside it and when you paste into another outside camunda engine, it gets confused to which camunda to use. Hence I worked on this and brought a mix version of spring and spring boot implementation of camunda. So here you go....and thanks me later :) Here is the pom file -------------------------------------------------------------------------------------------- <?xml version=...

Introduction to Reactive Programming in Java with Project Reactor

Introduction to Reactive Programming in Java with Project Reactor we will go through below: 1. Introduction to Reactive Programming What is reactive programming? Key principles of reactive systems: Responsive : Systems should respond in a timely manner. Resilient : Systems should be fault-tolerant. Elastic : Systems should scale as needed. Message-driven : Systems should use asynchronous messaging. Comparison between imperative programming and reactive programming. 2. Understanding Reactive Streams Publisher , Subscriber , Subscription , and Processor interfaces. The four key signals: onNext() , onComplete() , onError() , and onSubscribe() . Backpressure handling in reactive systems. 3. Introduction to Project Reactor What is Project Reactor? Key classes: Mono and Flux . Mono : Represents 0 or 1 item. Flux : Represents 0 to N items. Non-blocking nature and how it helps in building scalable systems. 4. Building a Reactive Application with Project Reactor Demonstrating how to use Mono ...

Password Keeper - Secret Diary - Offline Password keeper - Secret Manager - MySecrets -PNSoft - password manager

You might be having account in many banks or other websites for which you cannot remember passwords, there’s simply no way to easily remember every single password without duplicating passwords. This is where a password manager comes in—as long as you create a strong master password that you can remember, that’s the last password you’ll need to deal with. One Key to ALL Locks :) Data breaches are caused by weak or reused passwords. To keep your information secure, you need a strong, unique password for every account. But when you have hundreds of accounts, how do you keep track of all your passwords? That’s where password managers come in. They help you create one master password which will keep your all your passwords.  MySecrets -PNSoft   is a  free and password manager  primarily for  Windows .  MySecrets -PNSoft stores usernames, passwords, and other fields, including free-form notes in an encrypted  file . This file can be protected b...