AI for Java Architects – Part 7

Building AI Agents: Reasoning, Planning, Tools and Autonomous Workflows

“A chatbot answers questions. An agent solves problems.”


Introduction

So far in this series, we have learned:

  • Part 1 — LLM Fundamentals
  • Part 2 — Embeddings and Vector Databases
  • Part 3 — RAG Architecture
  • Part 4 — Building RAG Applications
  • Part 5 — Prompt Engineering
  • Part 6 — Spring AI Deep Dive

At this stage, we can build:

✅ Chatbots

✅ Knowledge assistants

✅ RAG systems

✅ Document search applications

But modern AI is moving beyond answering questions.

The next evolution is:

AI Agents

Agents can:

  • Reason
  • Plan
  • Decide
  • Use tools
  • Observe results
  • Take additional actions

This is where AI starts behaving less like software and more like a digital employee.


Chatbot vs Agent

Chatbot

User
   ↓
LLM
   ↓
Answer

Agent

User
   ↓
Reason
   ↓
Plan
   ↓
Select Tools
   ↓
Execute
   ↓
Observe
   ↓
Respond

Example

User:

Find my open Jira tickets, summarize them, identify blockers, and send me an email.

A chatbot may answer:

You can check Jira.

An agent:

  1. Connects to Jira.
  2. Retrieves tickets.
  3. Summarizes them.
  4. Identifies blockers.
  5. Generates an email.
  6. Sends it.

What Makes an Agent?

Four capabilities:

CapabilityPurpose
ReasoningUnderstand problem
PlanningDecide steps
ToolsExecute actions
MemoryMaintain state

Traditional Software

if(orderAmount > 1000) {
    approve();
}

Rules are predefined.


Agent Systems

Goal:
Process order.

Agent decides:

- Check inventory.
- Verify customer.
- Calculate risk.
- Approve order.

The workflow is dynamic.


The Agent Loop

Most agents follow:

Think
Act
Observe
Repeat

The ReAct Pattern

One of the most important concepts.

ReAct means:

Reason + Act


Example:

User:

What is the weather in Delhi and should I carry an umbrella?

Agent:

Thought

I need weather information.

Action

Call weather service.

Observation

Rain expected.

Final Answer

Carry an umbrella.


ReAct Architecture

Question
    ↓
Thought
    ↓
Action
    ↓
Observation
    ↓
Thought
    ↓
Final Answer

Example: Architecture Agent

User:

Review my microservice architecture.

Agent reasoning:

Thought:
I need architecture documents.

Action:
Search vector database.

Observation:
Found HLD and LLD.

Thought:
Identify risks.

Action:
Analyze architecture.

Final Answer:
Recommendations.

Planning Agents

Complex tasks require plans.

Example:

Build a deployment strategy.

Plan:

  1. Analyze architecture.
  2. Evaluate scalability.
  3. Recommend infrastructure.
  4. Produce design.

Planning Architecture

Goal
   ↓
Planner
   ↓
Tasks
   ↓
Execution
   ↓
Result

Example

User:

Migrate my monolith to microservices.

Planner:

  • Analyze application.
  • Identify domains.
  • Design APIs.
  • Recommend deployment.

Agent Memory

Agents need memory.

Without memory:

User:
My project uses Kafka.

User:
Suggest messaging improvements.

AI:
What messaging system?

With memory:

User:
My project uses Kafka.

User:
Suggest improvements.

AI:
Since you're using Kafka...

Short-Term Memory

Current conversation.


Long-Term Memory

Persistent knowledge.

Examples:

  • User preferences
  • Project information
  • Previous decisions

Tool Calling

Tools give agents superpowers.

Examples:

ToolPurpose
DatabaseQuery data
REST APIFetch information
CalendarSchedule
EmailSend messages
Vector StoreSearch documents
JiraRetrieve tickets

Example Tool

public class HolidayTool {

    public String calculateDate() {
        return "2026-07-15";
    }
}

The agent decides when to use it.


Tool Selection

User:

Calculate the deadline.

Agent:

Thought:
Need holiday calendar.

Action:
Call Holiday Service.

Observation:
15 July.

Final Answer:
Deadline is 15 July.

Multi-Step Execution

User:

Prepare a weekly status report.

Agent:

  1. Retrieve Jira tickets.
  2. Read emails.
  3. Analyze commits.
  4. Generate report.
  5. Send email.

Autonomous Workflows

Traditional:

User
 ↓
Application
 ↓
Response

Agent:

Goal
 ↓
Plan
 ↓
Multiple Actions
 ↓
Result

Agent Components

User
   ↓
Planner
   ↓
Memory
   ↓
Tools
   ↓
LLM
   ↓
Response

Agent Types

1. Tool Agent

Uses external APIs.

Example:

  • Weather
  • Databases

2. Planning Agent

Creates tasks.


3. Research Agent

Searches information.


4. Coding Agent

Writes code.


5. Workflow Agent

Executes business processes.


Enterprise Agent Examples

Support Agent

  • Search tickets.
  • Find solutions.

Architecture Agent

  • Analyze HLD.
  • Identify risks.

Incident Agent

  • Read logs.
  • Suggest root causes.

DevOps Agent

  • Analyze deployment failures.

HR Agent

  • Answer policy questions.

Java Example

@Service
public class ArchitectureAgent {

    public String review(String architecture) {

        return chatClient.prompt()
                .system("""
                    You are an architect.
                    Analyze risks.
                    Recommend improvements.
                    """)
                .user(architecture)
                .call()
                .content();
    }
}

Spring AI and Agents

Spring AI provides:

  • ChatClient
  • Memory
  • Tools
  • Advisors

This enables agent development.


Agent State

Agents maintain:

Goal
Current Task
Completed Tasks
Observations
Results

Example

Goal:

Deploy application.

State:

Task 1 Completed.

Task 2 Failed.

Retry required.

Reflection

Advanced agents can review their own work.

Example:

Generated answer.

Review answer.

Improve answer.

Return final version.

This increases quality.


Agent Guardrails

Agents are powerful.

Therefore they require limits.

Examples:

  • Maximum steps.
  • Approved tools.
  • Human approval.
  • Cost limits.

Human-in-the-Loop

Example:

Agent:
Ready to deploy.

Human:
Approve.

Agent:
Proceed.

Very important in enterprises.


Agent Architecture

User
   ↓
Planner
   ↓
Reasoner
   ↓
Tool Executor
   ↓
Memory
   ↓
Response

AI Agent Example for Your Architecture

Imagine:

Enterprise Architecture Agent

Capabilities:

  • Read HLD.
  • Read LLD.
  • Search Confluence.
  • Query Jira.
  • Analyze APIs.
  • Generate recommendations.

User:

Review our deadline processing system.

Agent:

  • Reads architecture.
  • Searches requirements.
  • Reviews APIs.
  • Suggests improvements.

Production Incident Agent

Input:

  • Logs
  • Metrics
  • Traces

Agent:

  1. Analyze failures.
  2. Find similar incidents.
  3. Suggest root cause.

Cost Considerations

Agents can make multiple calls.

Example:

Plan

Search

Analyze

Review

Summarize

5 LLM calls.

Monitoring costs becomes important.


Failure Handling

Tools may fail.

Example:

Weather API unavailable.

Agent:

  • Retry.
  • Use fallback.
  • Ask user.

Observability

Track:

  • Steps executed.
  • Tools called.
  • Latency.
  • Cost.
  • Errors.

Java Analogy

JavaAgents
ServiceAgent
MethodTool
WorkflowPlan
SessionMemory
Business RulesReasoning
State MachineAgent State

Interview Questions

What is an AI agent?

A system that can reason, plan, and act.


What is ReAct?

Reason plus action.


Why are tools important?

They allow interaction with external systems.


What is agent memory?

Persistent context.


Why human approval?

To reduce risks.


Hands-On Exercise

Build:

Jira Status Agent

Features:

  • Retrieve tickets.
  • Summarize issues.
  • Identify blockers.
  • Generate email.

Enterprise Project

Production Support Agent

Tools:

  • Logs API
  • Monitoring API
  • Incident database

Capabilities:

  • Root cause analysis.
  • Similar incidents.
  • Recommendations.

Key Takeaways

✔ Agents reason.

✔ Agents plan.

✔ Agents use tools.

✔ Agents maintain memory.

✔ Agents execute workflows.

✔ Agents can work autonomously.

✔ Guardrails are essential.


What’s Next?

Part 8 — Multi-Agent Systems and Agentic AI Architectures

Topics:

  • Supervisor agents.
  • Team agents.
  • Hierarchical agents.
  • Agent communication.
  • Agent orchestration.
  • Enterprise multi-agent systems.
  • LangGraph.
  • Agent workflows.

Because one intelligent agent is useful.

Multiple collaborating agents may transform enterprise software.


“The most exciting question in AI is no longer ‘What can the model answer?’ but rather ‘What can the agent accomplish?'”

Leave a Reply

Your email address will not be published. Required fields are marked *