langchain - ✅(Solved) Fix Allow defining `state_schema` through the `@wrap_tool_call` decorator [1 pull requests, 2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#36409Fetched 2026-04-08 01:57:50
View on GitHub
Comments
2
Participants
3
Timeline
8
Reactions
0
Timeline (top)
labeled ×3commented ×2cross-referenced ×1issue_type_added ×1

PR fix notes

PR #36528: feat: add state_schema parameter to @wrap_tool_call decorator

Description (problem / solution / changelog)

Allow defining state_schema through the @wrap_tool_call decorator

Description

This PR adds the state_schema parameter to the @wrap_tool_call decorator, making it consistent with other middleware decorators like @before_model, @after_model, and @wrap_model_call.

Changes

  • Added state_schema parameter to wrap_tool_call function signature and overloads
  • Updated decorator implementation to apply custom state schema to generated middleware
  • Added docstring documentation for the new parameter
  • Added test case test_wrap_tool_call_with_state_schema to verify functionality

Fixes

Closes #36409

How did you verify your code works?

✅ All 20 tests pass in test_wrap_tool_call.py ✅ No breaking changes to existing functionality

Changed files

  • libs/langchain_v1/langchain/agents/middleware/types.py (modified, +7/-2)
  • libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_tool_call.py (modified, +17/-1)
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a feature request, not a bug report or usage question.
  • I added a clear and descriptive title that summarizes the feature request.
  • I used the GitHub search to find a similar feature request and didn't find it.
  • I checked the LangChain documentation and API reference to see if this feature already exists.
  • This is not related to the langchain-community package.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Feature Description

The @wrap_tool_call decorator is the only one that does not accept a state_schema parameter (unlike before/after_agent/model and wrap_model_call). While the official documentation outlines how to handle state within such middlewares (by returning Command instances), the @wrap_tool_call decorator provides no mechanism for specifying the required schema.

Use Case

I want to implement a middleware that wraps every tool call and enforces updates to the agent state. Additionally, I want to follow current best practices by defining custom state directly within the middleware itself.

Proposed Solution

No response

Alternatives Considered

An alternative would be to use a class, but the resulting inconsistency is a greater concern here. In my opinion, there is no clear reason to exclude this parameter.

Additional Context

No response

extent analysis

TL;DR

Consider modifying the @wrap_tool_call decorator to accept a state_schema parameter to enable specifying the required schema for state updates within middlewares.

Guidance

  • Review the implementation of other decorators like before/after_agent/model and wrap_model_call to understand how they handle the state_schema parameter.
  • Investigate the possibility of adding a custom state management mechanism within the middleware itself, as hinted by the official documentation.
  • Evaluate the trade-offs of using a class-based approach as an alternative, considering the potential inconsistency mentioned.
  • Examine the LangChain documentation and API reference again to ensure no existing feature or parameter can achieve the desired functionality.

Notes

The lack of a state_schema parameter in the @wrap_tool_call decorator may be an oversight or a design choice, and further discussion with the LangChain community or maintainers might be necessary to determine the best course of action.

Recommendation

Apply workaround: Modify the @wrap_tool_call decorator or explore alternative state management approaches within the middleware, as the current implementation does not meet the required functionality.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

langchain - ✅(Solved) Fix Allow defining `state_schema` through the `@wrap_tool_call` decorator [1 pull requests, 2 comments, 3 participants]