Building an AI Agent System with the ReACT Pattern in Java
Phase 6 of the Jarvis AI platform explains how a multi-step, streaming AI agent system was built in pure Java and Spring AI using the ReACT pattern.
Phase six of the Jarvis AI platform moves beyond single-turn question answering toward multi-step task solving. While a simple weather query can be handled with one tool call, tasks requiring comparison and summarization need planning, multiple tool invocations, and reasoning between steps — which is exactly what the ReACT (Reason+Act) pattern, built around a THINK-ACT-OBSERVE loop, is designed to provide.
The key architectural choice was leaving the existing chat pipeline (AiOrchestrator) untouched and instead building a fully separate four-layer agent stack: AgentController, AgentOrchestrator, AgentExecutor, AgentPlanner, and ToolRegistry. To parse structured model output reliably, the team replaced fragile indexOf-based parsing with line-anchored regex patterns, switched tool dispatch from substring matching to exact equalsIgnoreCase comparisons, and fixed a bug so that THINK/ACT/OBSERVE events from one reasoning cycle share a single step index.
The implementation uses Flux.create() with a boundedElastic scheduler to keep blocking planning and tool calls off the WebFlux event loop, enforces safety limits like maximum step counts and execution timeouts, checks for client cancellation to avoid wasted background work, and lets a domain-driven state machine (PENDING, RUNNING, COMPLETED, FAILED, CANCELLED) and compare-and-set database updates prevent invalid transitions and race conditions. The end result is a multi-tool agent system built entirely in pure Java with Spring AI — no Python, no LangChain — that streams its reasoning live to the client.