Spring AI Alibaba Multi-Agent Architecture: Collaboration of React and Reflection Agents

Spring AI Alibaba Multi-Agent Architecture: Collaboration of React and Reflection Agents

In the previous articles, we learned about the reasoning-action capabilities of the React Agent and the self-reflection mechanism of the Reflection Agent.

Now, let’s explore how to combine these two agents to build a more powerful Multi-Agent collaboration system.

Collaboration of Agents

Review: Types of Agents We Have Mastered

In the previous articles, we have learned about two important types of agents:

Agent Type Core Capability Working Mode Application Scenarios
React Agent Reasoning-Action Loop Think → Tool Call → Observe → Rethink Complex Problem Solving
Reflection Agent Self-Reflection Improvement Generate → Evaluate → Improve → Regenerate Content Quality Enhancement

What is Multi-Agent?

Multi-Agent refers to a multi-agent system composed of multiple agents with autonomous decision-making and interaction capabilities, which can complete specific tasks or solve complex problems through cooperation, competition, or negotiation.

Advantages of Multi-Agent Collaboration

Now, let’s combine these two agents:

React Agent as the “Execution Expert”:

  • • Responsible for task decomposition and specific execution
  • • Calls various tools to complete operations
  • • Handles complex multi-step processes

Reflection Agent as the “Quality Expert”:

  • • Responsible for planning evaluation and result review
  • • Provides improvement suggestions and optimization plans
  • • Ensures output quality and accuracy

Multi-Agent Collaboration

Formulate Plan
Evaluate Plan
Needs Improvement
Plan Feasible
Execution Result
Evaluate Result
Needs Continuation
Task Completed
User Task
Planning Agent based on React mode task decomposition
Supervisor Agent based on Reflection mode quality control
Is the plan feasible?
Step Executing Agent based on React mode specific execution
Is the task completed?
High-Quality Output

Core Agent Analysis of Multi-Agent: Division of Labor between React and Reflection

1. Planning Agent – Task Planning Expert in React Mode

The Planning Agent adopts the reasoning-action mode of the React Agent, responsible for intelligently decomposing complex tasks into executable step sequences. It acts like an experienced project manager, capable of:

  • Analyzing Task Complexity: Understanding the deeper meaning of user requirements
  • Formulating Execution Plans: Breaking down large tasks into smaller steps
  • Calling Planning Tools: Using PlanningTool to manage plan status

Core Configuration

public OpenmanusController(ChatModel chatModel)throws GraphStateException {
    this.planningClient = ChatClient.builder(chatModel)
        .defaultSystem(PLANNING_SYSTEM_PROMPT)
        .defaultAdvisors(newSimpleLoggerAdvisor())
        .defaultToolCallbacks(Builder.getToolCallList())
        .defaultOptions(OpenAiChatOptions.builder().internalToolExecutionEnabled(false).build())
        .build();

    this.stepClient = ChatClient.builder(chatModel)
        .defaultSystem(STEP_SYSTEM_PROMPT)
        .defaultToolCallbacks(Builder.getManusAgentToolCalls())
        .defaultAdvisors(newSimpleLoggerAdvisor())
        .defaultOptions(OpenAiChatOptions.builder().internalToolExecutionEnabled(false).build())
        .build();

    initGraph();
}

Demonstration of Planning Capability

When a user requests “Help me research the latest trends in AI technology and generate an analysis report,” the Planning Agent outputs:

{
  "planId": "G_12345",
  "steps": [
    "1. Use search tools to find the latest developments in AI technology",
    "2. Organize and analyze the collected technical materials",
    "3. Extract key trends and development directions",
    "4. Generate a structured analysis report document"
  ]
}

2. Supervisor Agent – Quality Control Expert in Reflection Mode

The Supervisor Agent adopts the self-reflection mode of the Reflection Agent, responsible for coordinating the work of various agents, monitoring execution progress, and ensuring task quality. It acts like a strict quality inspector, capable of:

  • Evaluating Plan Feasibility: Checking whether the plan formulated by the Planning Agent is feasible
  • Monitoring Execution Progress: Tracking the execution status of each step
  • Quality Control: Ensuring that the output of each step meets the requirements
  • Dynamic Adjustment: Deciding whether to re-plan based on execution conditions

Core Decision Logic

public String think(OverAllState state) {
    String nextPrompt = (String) state.value("step_prompt").orElseThrow();

    if (nextPrompt.equalsIgnoreCase("Plan completed.")) {
        state.updateState(Map.of("final_output", state.value("step_output").orElseThrow()));
        return "end";
    }

    return "continue";
}

Demonstration of Quality Control Capability

When the Planning Agent submits a plan, the Supervisor Agent conducts a quality assessment:

Input Plan:

{
  "planId": "G_12345",
  "steps": [
    "1. Use search tools to find the latest developments in AI technology",
    "2. Organize and analyze the collected technical materials",
    "3. Extract key trends and development directions",
    "4. Generate a structured analysis report document"
  ]
}

Reflection Process of Supervisor Agent:

✅ Plan Evaluation: Steps are logically clear, forming a complete loop from information collection to report generation
✅ Feasibility Check: Each step has corresponding tool support
✅ Quality Standards: Meet the basic requirements for research reports
→ Decision: Plan approved, start executing step 1

Continuous Supervision During Execution:

After step 1 is completed:
- Reflection: Is the search result comprehensive? How is the information quality?
- Evaluation: ✅ Sufficient AI technology materials obtained
- Decision: Continue executing step 2

After step 2 is completed:
- Reflection: Is the data organization structured? Is key information extracted?
- Evaluation: ✅ Data has been categorized and organized by theme
- Decision: Continue executing step 3

Status Management Mechanism

@Override
public Map<string, object=""> apply(OverAllState t)throws Exception {
    String planStr = (String) t.value("plan").orElseThrow();
    Plan plan = planningTool.getGraphPlan(parsePlan(planStr).getPlan_id());

    Optional<object> optionalOutput = t.value("step_output");
    if (optionalOutput.isPresent()) {
        String finalStepOutput = String.format("This is the final output of step %s:\n %s",
            plan.getCurrentStep(), optionalOutput.get());
        plan.updateStepStatus(plan.getCurrentStep(), finalStepOutput);
    }

    String promptForNextStep = plan.isFinished() ? "Plan completed." : plan.nextStepPrompt();
    return Map.of("step_prompt", promptForNextStep);
}</object></string,>

3. Step Executing Agent – Task Execution Expert in React Mode

The Step Executing Agent also adopts the reasoning-action mode of the React Agent, equipped with a rich toolset, responsible for executing specific operational steps. It acts like an all-round technical expert, capable of:

  • Understanding Execution Instructions: Accurately understanding the tasks assigned by the Supervisor Agent
  • Selecting Appropriate Tools: Choosing the most suitable tools from the toolbox
  • Executing Specific Operations: Calling tools to complete actual work
  • Feedback Execution Results: Reporting execution results to the Supervisor Agent

Demonstration of Execution Capability

When the Supervisor Agent assigns the task “Use search tools to find the latest developments in AI technology,” the execution process of the Step Executing Agent is as follows:

Step 1: Reasoning Phase

🧠 Thinking: Need to search for AI technology development information
- Analysis: User needs the latest AI technology materials
- Judgment: Should use GoogleSearch tool
- Strategy: Search keyword "AI technology development trends 2024"

Step 2: Action Phase

🔧 Calling GoogleSearch tool:
- Input: {"query": "AI技术发展趋势 2024", "num_results": 10}
- Execute: Initiate search request
- Status: Tool call successful

Step 3: Observation Phase

👀 Analyzing search results:
✅ Found 10 related articles
✅ Includes hot topics like large models, machine learning, autonomous driving
✅ Information sources are authoritative (IEEE, Nature, MIT, etc.)
→ Judgment: Search result quality is good, task completed

Execution Output Report:

{
  "step": 1,
  "status": "completed",
  "tool_used": "GoogleSearch",
  "results_summary": "Successfully obtained 10 articles on AI technology development",
  "key_findings": [
      "Large model technology continues to break through",
      "Multimodal AI becomes a new trend",
      "AI is deeply applied in vertical fields"
  ],
  "next_action": "Wait for Supervisor Agent instructions"
}

Analysis of React + Reflection Collaboration Process

Practical Case: Collaborative Execution of Market Research Task

When a user requests “Help me research the latest trends in AI technology and generate an analysis report,” we can see how the React Agent and Reflection Agent collaborate:

Phase One: Task Planning and Quality Assessment

Supervisor AgentPlanning AgentUserSupervisor AgentPlanning AgentUserReact Mode: Reasoning-DecompositionReflection Mode: Evaluation-Improvement"Research AI technology development trends and generate report"🧠 Thinking: How to decompose this task?📋 Formulate: Generate detailed execution plan📋 Return detailed execution plan🤔 Reflection: Is this plan feasible?✅ Evaluation: Are the steps executable?📝 Plan quality assessment completed

Phase Two: Task Execution and Continuous Supervision

UserToolsetStep Executing AgentSupervisor AgentUserToolsetStep Executing AgentSupervisor AgentReact Mode: Reasoning-Action LoopReflection Mode: Quality CheckReact Mode: Continue Reasoning-ActionReflection Mode: Continuous Quality ControlFinal Quality Check"✅ Plan approved, start executing step 1"🧠 Thinking: What tool to use?🔧 Action: Call GoogleSearch👀 Observation: Obtain search results"📊 Step 1 completed: AI technology materials found"🤔 Reflection: How is the result quality?"✅ Quality qualified, continue to step 2"🧠 Thinking: How to organize data?🔧 Action: Data extraction and processing"📈 Step 2 completed: Data organization completed"🤔 Reflection: Is the information comprehensive?"✅ Continue executing report generation"🔧 Call FileSaver to generate report document"📄 All steps executed"🤔 Reflection: Overall task completion?"🎉 High-quality AI technology research report generated"

Conclusion

Essence of Technological Breakthrough: Innovation in Agent Collaboration Mode

The greatest innovation of the Multi-Agent system lies in the perfect combination of the two agent modes we have previously learned:

  1. 1. Deep Application of React Agent Mode:
  • • Planning Agent: Uses React mode for task decomposition
  • • Step Executing Agent: Uses React mode for executing specific operations
  • • Demonstrates the powerful execution capability of the reasoning-action loop
  • 2. Clever Integration of Reflection Agent Mode:
    • • Supervisor Agent: Uses Reflection mode for quality control
    • • Continuously evaluates plan feasibility and execution quality
    • • Demonstrates the quality assurance capability of the self-reflection mechanism
  • 3. Ingenious Design of Collaboration Mechanism:
    • • Achieves state sharing between agents through StateGraph
    • • Implements dynamic process scheduling through conditional edges
    • • Enhances overall performance through asynchronous execution

    Reviewing our path, we can see the clear evolution of agent technology:

    Traditional Function Call Single Tool Call
    React Agent Reasoning-Action Loop
    Reflection Agent Self-Reflection Improvement
    Multi-Agent Collaborative Intelligent System
    

    Each step is a leap in capability:

    • • Function Call → React Agent: From passive response to active reasoning
    • • React Agent → Reflection Agent: From execution capability to quality awareness
    • • Reflection Agent → Multi-Agent: From individual intelligence to collective intelligence

    Reference Links

    [1]https://arxiv.org/abs/2501.06322

    Leave a Comment