Skip to content
Concept-Lab
← LangGraphπŸ•ΈοΈ 21 / 42
LangGraph

ReAct using LangGraph - State

Design the ReAct state object: input, agent outcome, and intermediate steps that accumulate execution history.

Core Theory

ReAct state design determines reliability. The graph loop is simple only when state is precise.

Essential fields for this pattern:

  • input: current user objective.
  • agent_outcome: latest AgentAction or AgentFinish.
  • intermediate_steps: ordered list of (action, observation) tuples.

Why intermediate_steps matters: it gives the reasoning node memory of what was already tried, preventing repeated tool calls and enabling corrective reasoning.

Merge behavior is critical: appending steps incorrectly (replace vs add) can erase trace history and break loop decisions. Use additive merge semantics intentionally.

Operational recommendations:

  • Persist state snapshots for long-running workflows.
  • Attach attempt counters and wall-clock budget.
  • Store tool latency/error codes in step metadata.
  • Redact sensitive tool payloads before persistence.

Failure patterns: oversized state (token blowup), duplicate step entries, or stale outcomes not cleared between runs.

Deepening Notes

Source-backed reinforcement: these points are extracted from the LangGraph source note to sharpen architecture and flow intuition.

  • is going to pass and generate the agent action for the Search tool right so this is going to be the updated state so as soon as the react node is done executing it is going to ret
  • T node we'll actually build all of this later in the graph but it is going to send it to the ACT node and then the execute tools the tools are going to be executed and then as soon
  • ol flow is going to go back to the reason node and then all that history is going to be again sent back to the llm in that agent scratch Pad so now it has solved a particular probl
  • erent tool right so we have the second iteration and then we have the agent Reon node again okay it's going to get updated now get system time get system time needs to be called no
  • get system time tool and then it is going to append it and then the final llm call is going to happen in the agent reason node right so this is going to be the updated State and t

Interview-Ready Deepening

Source-backed reinforcement: these points add detail beyond short-duration UI hints and emphasize production tradeoffs.

  • Design the ReAct state object: input, agent outcome, and intermediate steps that accumulate execution history.
  • Why intermediate_steps matters: it gives the reasoning node memory of what was already tried, preventing repeated tool calls and enabling corrective reasoning.
  • Failure patterns: oversized state (token blowup), duplicate step entries, or stale outcomes not cleared between runs.
  • Essential fields for this pattern: input : current user objective.
  • Merge behavior is critical: appending steps incorrectly (replace vs add) can erase trace history and break loop decisions.
  • More agent autonomy increases adaptability but also increases non-determinism and debugging effort.
  • Fine-grained state graphs improve control, but poor state contracts can create brittle routing behavior.
  • Operational recommendations: Persist state snapshots for long-running workflows.

Tradeoffs You Should Be Able to Explain

  • More agent autonomy increases adaptability but also increases non-determinism and debugging effort.
  • Tool-heavy loops improve grounding, but latency and failure surfaces rise with each external dependency.
  • Fine-grained state graphs improve control, but poor state contracts can create brittle routing behavior.

First-time learner note: Think in state transitions, not giant prompts. Keep node responsibilities small and route logic deterministic so each step is easy to reason about.

Production note: Bound autonomy with loop limits, tool policies, and checkpoints. Capture route decisions and state snapshots for replay and incident analysis.

🧾 Comprehensive Coverage

Exhaustive coverage points to ensure complete topic understanding without missing core concepts.

Loading interactive module...

πŸ’‘ Concrete Example

State evolution example: 1) state.input set to security incident query. 2) Reason step writes AgentAction(search_logs). 3) Act step appends (search_logs, observation_1) to intermediate_steps. 4) Next reason sees observation_1 and emits AgentAction(geoip_enrichment). 5) Act appends second tuple. 6) Final reason emits AgentFinish with incident summary. This ordered step history enables deterministic replay and debugging.

🧠 Beginner-Friendly Examples

Guided Starter Example

State evolution example: 1) state.input set to security incident query. 2) Reason step writes AgentAction(search_logs). 3) Act step appends (search_logs, observation_1) to intermediate_steps. 4) Next reason sees observation_1 and emits AgentAction(geoip_enrichment). 5) Act appends second tuple. 6) Final reason emits AgentFinish with incident summary. This ordered step history enables deterministic replay and debugging.

Source-grounded Practical Scenario

Design the ReAct state object: input, agent outcome, and intermediate steps that accumulate execution history.

Source-grounded Practical Scenario

Why intermediate_steps matters: it gives the reasoning node memory of what was already tried, preventing repeated tool calls and enabling corrective reasoning.

🧭 Architecture Flow

Loading interactive module...

🎬 Interactive Visualization

Loading interactive module...

πŸ›  Interactive Tool

Loading interactive module...

πŸ§ͺ Interactive Sessions

  1. Concept Drill: Manipulate key parameters and observe behavior shifts for ReAct using LangGraph - State.
  2. Failure Mode Lab: Trigger an edge case and explain remediation decisions.
  3. Architecture Reorder Exercise: Reorder 5 flow steps into the correct production sequence.

πŸ’» Code Walkthrough

State contract used by the ReAct graph loop.

content/github_code/langgraph/6_react_agent/agent_reason_runnable.py

Reason step using ReAct prompt and tool-enabled runnable.

Open highlighted code β†’

content/github_code/langgraph/6_react_agent/react_state.py

Typed state contract for agent outcome + intermediate steps.

Open highlighted code β†’
  1. Understand each state key before tracing node behavior.

🎯 Interview Prep

Questions an interviewer is likely to ask about this topic. Think through your answer before reading the senior angle.

  • Q1[beginner] What minimum state fields are required for a ReAct graph and why?
    Minimum ReAct state needs input, agent_outcome, and intermediate_steps; without these fields, the loop cannot reason over prior actions or terminate predictably.
  • Q2[beginner] How does intermediate step history improve decision quality?
    Intermediate history improves quality by giving the model evidence of what has already been attempted, preventing redundant tool calls and enabling corrective strategies.
  • Q3[intermediate] What bugs appear if step history is overwritten instead of appended?
    If history is overwritten, you lose causal trace and often trigger repeated actions, premature finishes, or incorrect retries because the model no longer sees prior outcomes.
  • Q4[expert] How do you keep state useful without causing token and storage bloat?
    Control state growth with compact structured summaries, bounded history windows, and redaction/compression rules for large tool payloads.
  • Q5[expert] How would you explain this in a production interview with tradeoffs?
    Best answers connect state shape to runtime behavior: route correctness, retry logic, observability, and cost control.
πŸ† Senior answer angle β€” click to reveal
Use the tier progression: beginner correctness -> intermediate tradeoffs -> expert production constraints and incident readiness.

πŸ“š Revision Flash Cards

Test yourself before moving on. Flip each card to check your understanding β€” great for quick revision before an interview.

Loading interactive module...