Skip to content

Conversation

@sydney-runkle
Copy link
Collaborator

No description provided.

@github-actions github-actions bot added langchain Related to the package `langchain` infra Chores, devops, repo meta changes labels Nov 20, 2025
sydney-runkle added a commit to langchain-ai/langgraph that referenced this pull request Nov 20, 2025
## 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
langchain-ai/langchain#34051 which has tests
that pass w/ this change. This tests injection w/ `create_agent` (more
end to end than tests added in
langchain-ai/langchain#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).
@sydney-runkle sydney-runkle enabled auto-merge (squash) November 20, 2025 16:50
@sydney-runkle sydney-runkle merged commit ee3373a into master Nov 20, 2025
136 of 138 checks passed
@sydney-runkle sydney-runkle deleted the sr/refactor-injection-again branch November 20, 2025 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

infra Chores, devops, repo meta changes langchain Related to the package `langchain`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants