Create_react_agent and intermediate_steps without an AgentExecutor

I am creating an agent using create_react_agent. I wish to see the intermediate_steps but if i use AgentExecutor, I do not have control since it runs all the steps before it gives me back the control. I need to use a conditional_edge for which i need to see the intermediate steps after each tool execution. Somehow, i get back the AgentAction/AgentFinish object but i do not see the tool execution and hence, i am unable to populate intermediate_steps with the latest step that was executed. This, in turn, doesn’t let me execute the next step. Hope I’m making sense. Do let me know if you have any thoughts.

If there is a better way of doing this, do let me know.

Thanks.

With create_react_agent, the intermediate steps are stored in the graph state, not in a separate intermediate_steps field like with AgentExecutor. The LangGraph agent automatically handles tool execution and stores results in the state. To access intermediate steps after each tool execution, check the messages field in your graph state it contains the full conversation history including tool calls and responses. If you need custom logic between tool executions, modify the agent graph by adding conditional edges that examine the current state and decide whether to continue or interrupt. You can also access the last tool result by looking at the most recent ToolMessage in the state.

This is the state that i am seeing last -
{‘messages’: [HumanMessage(content=“1. Go to https://www.snapdeal.com/ and search for a laptop.”, additional_kwargs={}, response_metadata={}, id=‘54bafa5e-5702-4060-a13b-ce38eb26035a’),
AIMessage(content=‘’, additional_kwargs={}, response_metadata={}, id=‘ffc77d76-8bb2-4569-9f65-3a6a769c1585’, tool_calls=[{‘name’: ‘run_query_tool’, ‘args’: {‘query’: ‘https://www.snapdeal.com/’}, ‘id’: ‘tool_call_id_run_query_tool’, ‘type’: ‘tool_call’}]), ToolMessage(content=‘https://www.snapdeal.com’, name=‘run_query_tool’, id=‘242cce48-d574-48b8-b755-524a638747de’, tool_call_id=‘tool_call_id_run_query_tool’),
AIMessage(content=‘’, additional_kwargs={}, response_metadata={}, id=‘402645c5-9071-486a-8ddc-112788d9a909’, tool_calls=[{‘name’: ‘run_query_tool’, ‘args’: {‘query’: ‘https://www.snapdeal.com’}, ‘id’: ‘tool_call_id_run_query_tool’, ‘type’: ‘tool_call’}]), ToolMessage(content=‘https://www.snapdeal.com’, name=‘run_query_tool’, id=‘e1354f03-b231-4a7d-9214-a91a63a68237’, tool_call_id=‘tool_call_id_run_query_tool’)]}
It is calling the same tool over and over again since there is no place where it can see that the tool was already successfully called…can you tell me where am i going wrong…thanks.

Btw, I am using MessagesState to store the state (graph = StateGraph(MessagesState)).