[PR #6468] fix: refactor injection logic to respect function signatures #5054

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

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

State: closed
Merged: Yes


overview

The main purpose of this is to respect tool signatures that request injected args (like ToolRuntime) even when the explicitly specified args_schema does not.

Ex in the following example, we should still inject runtime despite its absence in ArgsSchema

class ArgsSchema(BaseModel):
    some_arg: int = Field(...)

@tool(args_schema=ArgsSchema)
def my_tool(some_arg: int, runtime: ToolRuntime): ...

This is accompanied by https://github.com/langchain-ai/langchain/pull/34051 which has tests that pass w/ this change. This tests injection w/ create_agent (more end to end than tests added in https://github.com/langchain-ai/langchain/pull/33999.

This unblocks the injection of ToolRuntime into MCP tools which is exciting bc that exposes tool call id and state, which we previously were unable to do.

other benefits

  • Cleaner code structure w/ more helpful docs about injected args.
  • Nice perf boost, we're no longer inspecting the annotations of a tool's schema 3 different times to detect store, state, and runtime injections.

additional notes

  1. I could see a world where we want more of this logic to reside on the tools themselves, but tools don't now about LG specific injection types (like ToolRuntime, hence having this logic here for now).
  2. We could separately add validation for the case where something is specified in args_schema and not in the function signature (probably at the tool level though).
**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/6468 **State:** closed **Merged:** Yes --- ## overview The main purpose of this is to respect tool signatures that request injected args (like `ToolRuntime`) even when the explicitly specified `args_schema` does not. Ex in the following example, we should still inject `runtime` despite its absence in `ArgsSchema` ```py class ArgsSchema(BaseModel): some_arg: int = Field(...) @tool(args_schema=ArgsSchema) def my_tool(some_arg: int, runtime: ToolRuntime): ... ``` This is accompanied by https://github.com/langchain-ai/langchain/pull/34051 which has tests that pass w/ this change. This tests injection w/ `create_agent` (more end to end than tests added in https://github.com/langchain-ai/langchain/pull/33999. This unblocks the injection of `ToolRuntime` into MCP tools which is exciting bc that exposes tool call id and state, which we previously were unable to do. ## other benefits * Cleaner code structure w/ more helpful docs about injected args. * Nice perf boost, we're no longer inspecting the annotations of a tool's schema 3 different times to detect store, state, and runtime injections. ## additional notes 1. I could see a world where we want more of this logic to reside on the tools themselves, but tools don't now about LG specific injection types (like `ToolRuntime`, hence having this logic here for now). 2. We could separately add validation for the case where something is specified in `args_schema` and not in the function signature (probably at the tool level though).
yindo added the pull-request label 2026-02-20 17:51:09 -05:00
yindo closed this issue 2026-02-20 17:51:09 -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#5054