Building an AI Agent System with the ReACT Pattern in Java A developer building the Jarvis AI Platform implemented Phase 6, adding an AI agent system using the ReACT (Reason + Act) pattern in Java. The system handles multi-step tasks by repeatedly reasoning, acting, and observing, with a separate orchestration layer that reuses existing tools. Key design decisions include using structured prompts for planning and regex-based parsing to reliably extract action steps. From answering questions to solving problems — Phase 6 of the Jarvis AI Platform After Phase 5, Jarvis could hear, speak, remember conversations, retrieve documents, and use tools. But every interaction was still limited to a single request and a single response. You: "What's the weather in Kathmandu?" Whisper ↓ AiOrchestrator ↓ WeatherTool ↓ Text-to-Speech Jarvis: "It is 22°C and clear." That works well for simple questions. It completely breaks down when a task requires multiple decisions. Imagine asking: Research the top 3 Java AI frameworks, compare them, and summarize the findings. A traditional chatbot usually replies: I don't have enough information to research that. The problem isn't intelligence. The problem is planning. To answer properly, the AI must: That requires multiple tool calls and reasoning between each one. This is exactly what AI agents are designed to do. ReACT stands for: Reason + Act Instead of generating one response, the AI repeatedly performs a reasoning loop. THINK ↓ ACT ↓ OBSERVE ↓ THINK ↓ ACT ↓ OBSERVE ↓ FINAL ANSWER Example: THOUGHT: I should search for Java AI frameworks. ACTION: search INPUT: Java AI frameworks 2026 ↓ OBSERVATION: Spring AI LangChain4j Semantic Kernel ↓ THOUGHT: Now I need comparison data. ↓ ACTION: search INPUT: Spring AI vs LangChain4j ↓ FINAL ANSWER Instead of guessing everything up front, the AI gathers information step by step before producing the final response. The most important design decision of Phase 6 was not modifying the existing chat pipeline . Instead of turning AiOrchestrator into a giant class responsible for both chat and agents, agents became a completely separate orchestration layer. ❌ Wrong AiOrchestrator ↓ Single Chat ↓ Agent Logic ↓ Tool Logic ↓ Everything Mixed Together ✅ Correct AgentController ↓ AgentOrchestrator ↓ AgentExecutor ↓ AgentPlanner ↓ ToolRegistry AiOrchestrator ↑ Remains Completely Unchanged Everything built during Phases 1–5 continues working exactly as before. Agents simply reuse the existing tools. The final architecture looks like this. AgentController ↓ AgentOrchestrator ↓ AgentExecutor ↓ AgentPlanner ↓ ToolRegistry Each component has a single responsibility. Keeping these responsibilities isolated made the implementation significantly easier to maintain. The planner doesn't simply ask the AI for an answer. Instead, it asks for structured output. You are an AI agent. Available tools: - getWeather - calculate - search For every step respond exactly as: THOUGHT: ... ACTION: ... INPUT: ... When enough information has been gathered: THOUGHT: ... FINAL ANSWER: ... This prompt acts as a contract between the model and the parser. The first implementation used indexOf . response.indexOf "ACTION:" ; That failed whenever the literal text ACTION: appeared inside user data. The solution was precompiled regular expressions anchored to the beginning of each line. private static final Pattern ACTION PATTERN = Pattern.compile " ?ms ^ACTION:\\s . ? " + " ?=^ ?:THOUGHT:|INPUT:|FINAL ANSWER: |\\z " ; This guarantees that only real section headers are parsed. The executor coordinates the complete lifecycle. public Flux