Create_react_agent internal loop

Does a react_agent.invoke too, runs a loop internally like an AgentExecutor and return the final result after finishing the entire execution? This is what i am seeing which is surprising.

  1. Why would I use an AgentExecutor then?
  2. Is there a way to see the Action, Though output using an agent created with create_react_agent (the way a ZERO_SHOT_REACT_AGENT gives?

Code:
langgraph_agent = create_react_agent(model, tools, prompt=prompt)
messages = langgraph_agent.invoke({“messages”: [(“human”, query)]})

1 Like

Yes, create_react_agent().invoke() runs a complete loop internally and returns the final result, similar to AgentExecutor. The difference is that create_react_agent creates a LangGraph-based agent which offers better state management, streaming, and debugging capabilities compared to the legacy AgentExecutor.

To see intermediate steps (Action/Thought outputs), use streaming instead of invoke():

for event in langgraph_agent.stream({"messages": [("human", query)]}):
    print(event)  # Shows each step including tool calls and thoughts

Or use astream_events() for more granular control over what intermediate data you want to observe during execution.

1 Like

Thanks, @AbdulBasit . Much appreciated.