Reflection
Reflection improves on planning by reflecting on the result. The output is critiqued before it is final, and the critique feeds another attempt.
Two shapes
- Doer and reflector. The doer agent produces the work. A separate reflector agent critiques it. Both are specialized, each with its own prompt. The loop repeats until the reflector is satisfied. LangChain’s version has a generator and a critic persona that loop a set number of times.
- Self-reflection. A single agent runs the critique loop on its own output, as an inner loop, and carries on until it is happy with it.
The research version, Reflexion, keeps the reflections as text in memory so later attempts can use them, with no change to model weights.
In LangGraph
The doer and the reflector are two nodes. A conditional edge decides whether to go around again.
from typing_extensions import TypedDictfrom langchain.chat_models import init_chat_modelfrom langgraph.graph import END, START, StateGraph model = init_chat_model("anthropic:claude-sonnet-5") class State(TypedDict): task: str draft: str critique: str rounds: int def doer(state: State): prompt = ( f"Task: {state['task']}\nPrevious draft: {state['draft']}\n" f"Critique: {state['critique']}\nWrite an improved answer." ) return {"draft": model.invoke(prompt).content, "rounds": state["rounds"] + 1} def reflector(state: State): prompt = ( f"Critique this answer to '{state['task']}'. " f"Reply APPROVED if it needs no change.\n\n{state['draft']}" ) return {"critique": model.invoke(prompt).content} def satisfied(state: State): if state["critique"].startswith("APPROVED") or state["rounds"] >= 3: return END return "doer" builder = StateGraph(State)builder.add_node("doer", doer)builder.add_node("reflector", reflector)builder.add_edge(START, "doer")builder.add_edge("doer", "reflector")builder.add_conditional_edges("reflector", satisfied, ["doer", END])graph = builder.compile()The reflector is the new part: it returns a critique, or the word the router watches for. The round cap in the router matters as much as the approval check. Without it, a reflector that is never satisfied loops forever.
The cost
Every round costs tokens and time. LangChain is direct about this: the approach trades extra compute for a shot at better output, which suits knowledge-heavy work where quality beats speed and is a poor fit for low-latency use. It also needs more orchestration and more prompt engineeringPrompt engineeringEngineering the instruction given to the model.Opens in a new tab, since two agents need two good prompts. Reflection is one of the defenses in hallucination preventionHallucination preventionIt cannot be switched off, so it is stacked: prompt, context and flow together.Opens in a new tab, and it composes with ReActReActReason, act, observe, repeat: planning, tool use and a loop in one pattern.Opens in a new tab and planningPlanningBreak a high-level goal into steps, store the plan, and work through it.Opens in a new tab.
Sources
- Reflection Agents, LangChain Blog · accessed October 5, 2026
- Reflexion: Language Agents with Verbal Reinforcement Learning, arXiv · accessed October 5, 2026