[PR #6258] [DRAFT] feat(prebuilt): add pre/post hooks for structured response in create_react_agent #4937

Closed
opened 2026-02-20 17:50:59 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/6258

State: closed
Merged: No


Description:
This PR adds pre_structured_response_hook and post_structured_response_hook parameters to the create_react_agent function, enabling preprocessing and post-processing around the generate_structured_response node for enhanced workflow extensibility.

What's added:

  • pre_structured_response_hook: Optional hook executed before structured response generation
  • post_structured_response_hook: Optional hook executed after structured response generation
  • Updated workflow graph creation to properly route through the new hooks
  • Comprehensive test coverage for all hook combinations with existing pre_model_hook and post_model_hook
  • Updated interrupt handling to support the new hook nodes

Use Cases:

  • Pre-hook: Message filtering, context preparation, input validation before structured output
  • Post-hook: Response validation, transformation, logging, or error handling after structured generation

Implementation Details:

  • Hooks are integrated as separate workflow nodes (not inline function calls)
  • Maintains backward compatibility - all existing functionality works unchanged
  • Proper edge routing ensures correct execution flow in all hook combinations
  • Works with both tool-calling and non-tool-calling agent configurations

Issue: N/A (Enhancement request)

Dependencies: None

**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/6258 **State:** closed **Merged:** No --- **Description:** This PR adds `pre_structured_response_hook` and `post_structured_response_hook` parameters to the `create_react_agent` function, enabling preprocessing and post-processing around the `generate_structured_response` node for enhanced workflow extensibility. ### What's added: - `pre_structured_response_hook`: Optional hook executed before structured response generation - `post_structured_response_hook`: Optional hook executed after structured response generation - Updated workflow graph creation to properly route through the new hooks - Comprehensive test coverage for all hook combinations with existing `pre_model_hook` and `post_model_hook` - Updated interrupt handling to support the new hook nodes ### Use Cases: - **Pre-hook**: Message filtering, context preparation, input validation before structured output - **Post-hook**: Response validation, transformation, logging, or error handling after structured generation ### Implementation Details: - Hooks are integrated as separate workflow nodes (not inline function calls) - Maintains backward compatibility - all existing functionality works unchanged - Proper edge routing ensures correct execution flow in all hook combinations - Works with both tool-calling and non-tool-calling agent configurations **Issue:** N/A (Enhancement request) **Dependencies:** None
yindo added the pull-request label 2026-02-20 17:50:59 -05:00
yindo closed this issue 2026-02-20 17:50:59 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#4937