Skip to content

Conversation

rickors560
Copy link

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

…react_agent

Enable preprocessing and postprocessing around generate_structured_response
node for enhanced workflow extensibility.
Copy link

vercel bot commented Oct 9, 2025

@rickors560 is attempting to deploy a commit to the LangChain Team on Vercel.

A member of the Team first needs to authorize it.

@rickors560
Copy link
Author

Related Discussion: https://forum.langchain.com/t/add-pre-post-hooks-for-structured-response-generation-in-create-react-agent/1795

This is a draft PR to show the implementation approach discussed in the above thread.

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.

1 participant