From ce04a922e3b7e66106e3862e059bc53ed1d40de5 Mon Sep 17 00:00:00 2001 From: Sydney Runkle Date: Tue, 21 Apr 2026 08:42:20 -0400 Subject: [PATCH] perf(core): cache BaseTool.tool_call_schema and args as cached_property Co-Authored-By: Claude Sonnet 4.6 --- libs/core/langchain_core/tools/base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/core/langchain_core/tools/base.py b/libs/core/langchain_core/tools/base.py index 7026a2e8fb1..e28cd2290c6 100644 --- a/libs/core/langchain_core/tools/base.py +++ b/libs/core/langchain_core/tools/base.py @@ -552,6 +552,7 @@ class ChildTool(BaseTool): model_config = ConfigDict( arbitrary_types_allowed=True, + ignored_types=(functools.cached_property,), ) @property @@ -564,7 +565,7 @@ class ChildTool(BaseTool): keys = {k for k in self.args if k != "kwargs"} return len(keys) == 1 - @property + @functools.cached_property def args(self) -> dict: """Get the tool's input arguments schema. @@ -583,7 +584,7 @@ class ChildTool(BaseTool): json_schema = input_schema.model_json_schema() return cast("dict", json_schema["properties"]) - @property + @functools.cached_property def tool_call_schema(self) -> ArgsSchema: """Get the schema for tool calls, excluding injected arguments.