Skip to content

ToolRuntime[WithTypeArguments] not supported #6465

@e792a8

Description

@e792a8

Checked other resources

  • This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

from langgraph.prebuilt.tool_node import ToolNode, ToolRuntime
from langgraph.graph import StateGraph, MessagesState, START, END
from langchain_core.messages import AIMessage
from langchain_core.messages.tool import tool_call
from langchain.tools import tool
from dataclasses import dataclass


@dataclass
class MyContext:
    some_info: str


@tool
def get_info_error(rt: ToolRuntime[MyContext]):
    """This tool returns error."""
    return rt.context.some_info


@tool
def get_info_ok_but_no_typechecking(rt: ToolRuntime):
    """This tool is ok, but lacks type checking."""
    return rt.context.some_info  # type: ignore


builder = StateGraph(MessagesState, context_schema=MyContext)
builder.add_node(
    "tool_node", ToolNode([get_info_ok_but_no_typechecking, get_info_error])
)
builder.add_edge(START, "tool_node")
builder.add_edge("tool_node", END)
graph = builder.compile()
result = graph.invoke(
    {
        "messages": [
            AIMessage(
                "_",
                tool_calls=[
                    tool_call(name="get_info_ok_but_no_typechecking", args={}, id="1"),
                    tool_call(name="get_info_error", args={}, id="2"),
                ],
            )
        ]
    },
    context=MyContext(some_info="this is info"),
)
print(result["messages"][-2:])

Error Message and Stack Trace (if applicable)

[ToolMessage(content='this is info', name='get_info_ok_but_no_typechecking', id='cafc05ec-1e87-401a-8150-f7a356046ae1', tool_call_id='1'), 
ToolMessage(content="Error invoking tool 'get_info_error' with kwargs {} with error:\n rt: Field required\n Please fix the error and try again.", name='get_info_error', id='9ae338e5-7672-48f2-9a52-e9ab1d4675f0', tool_call_id='2', status='error')]

Description

The ToolRuntime argument of a @tool function cannot attach type arguments, like ToolRuntime[MyContext, MyStatus], or the runtime is not injected. This makes typechecking some difficult.

System Info

System Information

OS: Linux
OS Version: #1 SMP PREEMPT_DYNAMIC Wed, 15 Oct 2025 11:05:48 +0000
Python Version: 3.13.7 (main, Aug 15 2025, 12:34:02) [GCC 15.2.1 20250813]

Package Information

langchain_core: 1.0.6
langchain: 1.0.8
langchain_community: 0.4.1
langsmith: 0.4.38
langchain_anthropic: 1.0.1
langchain_chroma: 1.0.0
langchain_classic: 1.0.0
langchain_ollama: 1.0.0
langchain_openai: 1.0.2
langchain_text_splitters: 1.0.0
langgraph_api: 0.4.28
langgraph_cli: 0.4.5
langgraph_runtime_inmem: 0.14.1
langgraph_sdk: 0.2.9

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.13.2
anthropic: 0.72.0
blockbuster: 1.5.25
chromadb: 1.3.4
click: 8.3.0
cloudpickle: 3.1.1
cryptography: 44.0.3
dataclasses-json: 0.6.7
httpx: 0.28.1
httpx-sse: 0.4.3
jsonpatch: 1.33
jsonschema-rs: 0.29.1
langgraph: 1.0.3
langgraph-checkpoint: 3.0.0
numpy: 2.3.4
ollama: 0.6.0
openai: 2.6.1
opentelemetry-api: 1.38.0
opentelemetry-sdk: 1.38.0
orjson: 3.11.4
packaging: 25.0
pydantic: 2.12.3
pydantic-settings: 2.11.0
pyjwt: 2.10.1
python-dotenv: 1.2.1
pyyaml: 6.0.3
PyYAML: 6.0.3
requests: 2.32.5
requests-toolbelt: 1.0.0
rich: 14.2.0
sqlalchemy: 2.0.44
SQLAlchemy: 2.0.44
sse-starlette: 2.1.3
starlette: 0.49.1
structlog: 25.5.0
tenacity: 9.1.2
tiktoken: 0.12.0
truststore: 0.10.4
typing-extensions: 4.15.0
uvicorn: 0.38.0
watchfiles: 1.1.1
zstandard: 0.25.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpendingawaiting review/confirmation by maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions