mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-25 00:52:25 +02:00
`_get_all_injected_args` runs `get_input_schema()`, `get_type_hints`, and `inspect.signature` on every tool for every `ToolNode` construction. When the same tool objects are passed to repeated `create_agent` calls (the common case), this work was repeated from scratch each time. Add a module-level cache keyed by `id(tool)`. The cache entry stores a strong reference to the tool alongside the result, which prevents GC from reusing the id for a different object and making an incorrect cache hit. The `entry[0] is tool` identity check provides a second safety guard. `BaseTool` (Pydantic v2 BaseModel) is not hashable, so `@lru_cache` cannot be used directly — hence the id-based dict approach. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>