Skip to content

fix(prebuilt): support generic type arguments for ToolRuntime injection#6509

Merged
Sydney Runkle (sydney-runkle) merged 5 commits into
langchain-ai:mainfrom
dumko2001:fix/tool-runtime-generic
Jan 12, 2026
Merged

fix(prebuilt): support generic type arguments for ToolRuntime injection#6509
Sydney Runkle (sydney-runkle) merged 5 commits into
langchain-ai:mainfrom
dumko2001:fix/tool-runtime-generic

Conversation

@dumko2001

Copy link
Copy Markdown
Contributor

Description:
This PR fixes an issue where injection types (like ToolRuntime) were not recognized by ToolNode when used with generic type arguments (e.g., ToolRuntime[MyContext]).

Previously, the _is_injection check relied solely on isinstance and issubclass, which fail for typing._GenericAlias objects. This update adds a check using typing.get_origin() to correctly identify the base class of generic types, ensuring the runtime is injected correctly even when type hints are present.

Issue: Fixes #6465

Dependencies: None

Twitter handle: @SidharthRajmoh2

@vercel

vercel Bot commented Nov 27, 2025

Copy link
Copy Markdown

Sidharth Rajmohan (@dumko2001) is attempting to deploy a commit to the LangChain Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py Outdated
Comment thread libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much. This is consistent w/ the logic we have for checking the origin in langchain-core as well.

It's actually a bit odd that these functions aren't unified.

@sydney-runkle Sydney Runkle (sydney-runkle) merged commit cb2faa7 into langchain-ai:main Jan 12, 2026
56 checks passed
@dumko2001

Sidharth Rajmohan (dumko2001) commented Jan 13, 2026

Copy link
Copy Markdown
Contributor Author

Welcome Sydney! . I’m already digging into the core for some other PRs (#6511 , #6512 ), so I’m happy to take a stab at cleaning this up. Let me know if you'd like me to open a PR for it!

xingshuozhu1998 pushed a commit to xingshuozhu1998/langgraph that referenced this pull request May 1, 2026
…on (langchain-ai#6509)

**Description:**
This PR fixes an issue where injection types (like `ToolRuntime`) were
not recognized by `ToolNode` when used with generic type arguments
(e.g., `ToolRuntime[MyContext]`).

Previously, the `_is_injection` check relied solely on `isinstance` and
`issubclass`, which fail for `typing._GenericAlias` objects. This update
adds a check using `typing.get_origin()` to correctly identify the base
class of generic types, ensuring the runtime is injected correctly even
when type hints are present.

**Issue:** Fixes langchain-ai#6465

**Dependencies:** None

**Twitter handle:** @SidharthRajmoh2

---------

Co-authored-by: Sydney Runkle <54324534+sydney-runkle@users.noreply.github.com>
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.

ToolRuntime[WithTypeArguments] not supported

2 participants