Skip to content

fix: add missing edge from generate_structured_response to END#6733

Open
saakshigupta2002 wants to merge 1 commit intolangchain-ai:mainfrom
saakshigupta2002:fix/response-format-infinite-loop
Open

fix: add missing edge from generate_structured_response to END#6733
saakshigupta2002 wants to merge 1 commit intolangchain-ai:mainfrom
saakshigupta2002:fix/response-format-infinite-loop

Conversation

@saakshigupta2002
Copy link

Summary

  • Adds missing edge from generate_structured_response node to END in create_react_agent
  • Fixes infinite loop issue when using response_format parameter
  • The graph now properly terminates after generating structured response

Problem

When response_format is provided to create_react_agent, the generate_structured_response node is added to the graph but no outgoing edge to END is defined. This causes the graph to not terminate properly after generating the structured response, potentially leading to infinite loops until the recursion limit is hit.

Solution

Added an explicit edge from generate_structured_response to END after the node is added to the workflow (line 901-902 in chat_agent_executor.py):

workflow.add_edge("generate_structured_response", END)

This ensures the graph properly terminates after the structured response is generated.

Test plan

  • All existing tests pass (make test-fast - 189 tests passed)
  • Specifically tested structured response related tests (test_react_agent_with_structured_response, test_dynamic_model_with_structured_response, test_post_model_hook_with_structured_output)
  • Lint and format checks pass

Fixes #6731

When response_format is provided to create_react_agent, the
generate_structured_response node was added to the graph but
no outgoing edge to END was defined. This caused the graph to
not terminate properly after generating the structured response,
potentially leading to infinite loops until the recursion limit.

This fix adds an explicit edge from generate_structured_response
to END to ensure proper graph termination.

Fixes langchain-ai#6731
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LangGraph [1.0.6] Bug - Agent infinite looping until recursion limit error is hit

1 participant