LangGraph / swarm and supervisor: Build Reflection Enabled Agentic
Implement agentic systems with reflection mechanisms using langgraph-swarm and langgraph-supervisor respectively. From this point on, I will no longer dwell on the debate of whether to call them “agents” or “workflows,” but will directly use the term “agentic systems.”
Looking back at previous articles, an Agentic Reflection system can be implemented from scratch using LangGraph, and similarly through LlamaIndex’s AgentWorkflow. In fact, such a system is a classic researcher-reviewer-reporter system, and a basic agentic system should at least have such a mechanism.
Introduction
Supervisor and Swarm
Supervisor
Full code
Swarm
Full code
Comparing to LlamaIndex’s AgentWorkflow
Ref.
Introduction
Actually, since OpenAI and xAI released Deep Research and Deep Search, “research systems” have become a typical use case for agentic systems.
Starting with Agents, from my perspective, although it’s not the smallest unit in an agentic system (in principle, a single LLM completion is), at least in all the various architectures circulating online that we’ve seen, each node (the workflows section in the diagram below) should be an agent, or at least some logic wrapped around an LLM.

The “Reflection Enabled” we’ve been talking about, if explained using the diagram above, is most directly the “Evaluator-optimizer” flow. So far, I haven’t used any “Tool” methods to implement reflection on LLM completion, such as the Agent part on the left of the diagram.
Return to our goal, we aim to achieve the classic researcher-reviewer-reporter model. “Evaluator-optimizer” is precisely a scenario that provides reviews.
Similarly, LangChain provides two new sets of components, similar to LlamaIndex, allowing us to easily build such a graph-based agentic system.
Note that all components for this experiment are under the langgraph namespace; generally, methods with the same name but not under langgraph are not used in this experiment. For example, there are actually two create_react_agent() functions in the entire LangChain project, including one in LangGraph.
Supervisor and Swarm
I don’t want to overcomplicate the issue here. For details, you can refer to the diagrams on the official website:
https://github.com/langchain-ai/langgraph-supervisor-py
https://github.com/langchain-ai/langgraph-swarm-py
Here, I only want to point out one thing: hand-off will occur in either case. The difference is that the supervisor uses a prompt to enable AI self-routing, which is very similar to the “Orchestrator” and “Routing” in the diagram above. Swarm, on the other hand, is based on the “tool level” where developers have to use a tool to specify “from where to where, maybe when.”
Supervisor
As we have mentioned many times, a hand-off mechanism will occur. In the supervisor, the hand-off is determined by it. In our case, the plan is the priority, and then the plan will submit the results to the supervisor, who will then activate the regression. The results of the regression will be submitted, and then the supervisor decides to use the critic. The critic’s reflection will allow the supervisor to decide whether to have a regression revision or report the final results.

research_supervisor = create_supervisor(
[
plan_agent,
regression_agent,
critic_agent,
report_agent,
],
model=supervisor_model,
supervisor_name="ResearchSupervisor",
tools=[
get_current_datetime,
],
prompt="""You are the ResearchSupervisor, an AI coordinator responsible for orchestrating a team of specialized AI agents. Your ONLY role is to manage the workflow by activating the appropriate agent at the appropriate time. You are NOT responsible for evaluating the quality or content of any agent's work.
## WORKFLOW COORDINATION RESPONSIBILITIES
1. **Start with PlanAgent**:
- Always begin the workflow by activating the PlanAgent
- The PlanAgent will create a regression plan based on the user's request
- After the PlanAgent completes its plan, activate the RegressionAgent
2. **Activate RegressionAgent**:
- After the PlanAgent has finished, activate the RegressionAgent
- Provide the RegressionAgent with the plan created by the PlanAgent
- After the RegressionAgent completes its work, activate the CriticAgent
3. **Activate CriticAgent**:
- After the RegressionAgent has finished, activate the CriticAgent
- The CriticAgent will evaluate the regression findings
- Based on the CriticAgent's decision:
* If the CriticAgent requests revisions, activate the RegressionAgent again
* If the CriticAgent approves the regression, activate the ReportAgent
4. **Activate ReportAgent**:
- After the CriticAgent has approved the regression, activate the ReportAgent
- The ReportAgent will create the final report based on the regression findings
- IMPORTANT: Once the ReportAgent submits its report, the workflow is COMPLETE
- Do NOT activate any other agents after the ReportAgent has submitted its report
- The entire process ends when the ReportAgent delivers its final report
## AGENT ACTIVATION RULES
- **Sequential Activation**:
* PlanAgent → RegressionAgent → CriticAgent → [RegressionAgent if revisions needed] → ReportAgent → END
* Each agent must complete its task before the next agent is activated
- **Iteration Management**:
* Allow up to 3 iterations between RegressionAgent and CriticAgent
* If 3 iterations have occurred, proceed to the ReportAgent regardless of the CriticAgent's decision
- **Communication Protocol**:
* When activating an agent, simply pass along the previous agent's output
* Do not add your own analysis, feedback, or evaluation
* Your messages should be brief and focused only on activating the next agent
- **Workflow Completion**:
* The workflow is COMPLETE after the ReportAgent submits its report
* Do NOT activate any agent after the ReportAgent has finished
* Do NOT start a new cycle of agents after the report is delivered
* Simply acknowledge that the process is complete after the report is submitted
## IMPORTANT LIMITATIONS
- You do NOT evaluate the quality of any agent's work
- You do NOT provide feedback on any agent's output
- You do NOT modify any agent's content
- You do NOT make decisions about the research content
- You ONLY manage the workflow by activating agents in the correct sequence
- You MUST END the workflow after the ReportAgent submits its report
Remember:
- Use less than 10 internet search queries.
- Your ONLY responsibility is to ensure the correct agent is activated at the correct time in the workflow sequence.
- The workflow ENDS after the ReportAgent delivers its final report.
""",
).compile(
name="ResearchSupervisor",
checkpointer=checkpointer,
store=store,
)
According to the official introduction, a supervisor controls multiple agents. If you need “hierarchy,” you can also have a supervisor control multiple other supervisors. However, from the prompt, we need to define how the supervisor orchestrates these things; please read the prompt carefully.
Full code
Swarm
In a swarm, all agents within the agentic system are on the same level, and their relationships are determined directly through explicitly defined hand-off tools. Do not be misled by the image itself; in fact, there is no hierarchical relationship between them. In this diagram, the relationship between regression and critic is very clear; they repeatedly “kick ball” with each other (check “Evaluator-optimizer” flow).

plan_agent = create_react_agent(
model=plan_model,
name="PlanAgent",
checkpointer=checkpointer,
tools=[
create_handoff_tool(
agent_name="RegressionAgent", # agent to swarm
description="Transfer the PlanAgent's regression plan to the RegressionAgent who will execute the plan and gather information according to it.",
),
],
prompt=...)
regression_agent = create_react_agent(
model=regression_model,
name="RegressionAgent",
checkpointer=checkpointer,
tools=[
# open_url,
web_search,
get_current_datetime,
create_handoff_tool(
agent_name="CriticAgent", # agent to swarm
description="Transfer the RegressionAgent's regression findings to the CriticAgent who will evaluate the quality and relevance of the findings.",
),
],
prompt=....)
citic_agent = create_react_agent(
model=critic_model,
name="CriticAgent",
checkpointer=checkpointer,
tools=[
create_handoff_tool(
agent_name="RegressionAgent", # agent to swarm
description="Transfer the CriticAgent's feedback to the RegressionAgent who will revise the regression findings based on the feedback.",
),
create_handoff_tool(
agent_name="ReportAgent", # agent to swarm
description="Transfer the CriticAgent's approved regression findings to the ReportAgent who will create the final report.",
),
],
prompt=.....)
research_swarm = create_swarm(
[
plan_agent,
regression_agent,
critic_agent,
report_agent,
],
default_active_agent="PlanAgent",
).compile(
name="ResearchSwarm",
# Important: compile the swarm with a checkpointer to remember
# previous interactions and last active agent
checkpointer=checkpointer,
# store=store,
)
Unlike supervisors, swarm agentic systems are based on explicit multi-agents. Attempting to involve a supervisor in a swarm will result in an error.
Here’s a reminder: although the hand-off tool is a key focus, it’s actually best to mention the hand-off logic in the prompt of each agent. Refer to the code for details.
Full code
Comparing to LlamaIndex’s AgentWorkflow
Supervisor is more like AgentWorkflow. In fact, if you look at the source code of AgentWorkflow, it also has a hand-off tool internally, and the scheduling guidance is implemented through prompts. Here is the detailed code for reference:
Ref.
•Agents: https://ppc.land/content/files/2025/01/Newwhitepaper_Agents2.pdf
•Building Effective Agents: https://www.anthropic.com/research/building-effective-agents
•AGENTIC RETRIEVAL-AUGMENTED GENERATION: A SURVEY ON AGENTIC RAG https://arxiv.org/pdf/2501.09136