The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
core[patch]: make get_all_basemodel_annotations public (#27761)
Bagatur5d337326b049
diff --git a/libs/core/langchain_core/tools/base.py b/libs/core/langchain_core/tools/base.pyindex 4de0452020..9782234dfb 100644--- a/libs/core/langchain_core/tools/base.py+++ b/libs/core/langchain_core/tools/base.py@@ -449,7 +449,7 @@ class ChildTool(BaseTool):def tool_call_schema(self) -> type[BaseModel]:full_schema = self.get_input_schema()fields = []- for name, type_ in _get_all_basemodel_annotations(full_schema).items():+ for name, type_ in get_all_basemodel_annotations(full_schema).items():if not _is_injected_arg_type(type_):fields.append(name)return _create_subset_model(@@ -962,7 +962,7 @@ def _is_injected_arg_type(type_: type) -> bool:)-def _get_all_basemodel_annotations(+def get_all_basemodel_annotations(cls: Union[TypeBaseModel, Any], *, default_to_bound: bool = True) -> dict[str, type]:# cls has no subscript: cls = FooBar@@ -980,7 +980,7 @@ def _get_all_basemodel_annotations(orig_bases: tuple = getattr(cls, "__orig_bases__", ())# cls has subscript: cls = FooBar[int]else:- annotations = _get_all_basemodel_annotations(+ annotations = get_all_basemodel_annotations(get_origin(cls), default_to_bound=False)orig_bases = (cls,)@@ -994,7 +994,7 @@ def _get_all_basemodel_annotations(# if class = FooBar inherits from Baz, parent = Bazif isinstance(parent, type) and is_pydantic_v1_subclass(parent):annotations.update(- _get_all_basemodel_annotations(parent, default_to_bound=False)+ get_all_basemodel_annotations(parent, default_to_bound=False))continuediff --git a/libs/core/tests/unit_tests/runnables/test_runnable.py b/libs/core/tests/unit_tests/runnables/test_runnable.pyindex 7b03b53c21..d1f67a6c8d 100644--- a/libs/core/tests/unit_tests/runnables/test_runnable.py+++ b/libs/core/tests/unit_tests/runnables/test_runnable.py@@ -1891,6 +1891,13 @@ async def test_prompt_with_chat_model_async()+ condition=sys.version_info[1] == 13,+ reason=(+ "temporary, py3.13 exposes some invalid assumptions about order of batch async "+ "executions."+ ),+)@freeze_time("2023-01-01")async def test_prompt_with_llm(mocker: MockerFixture, snapshot: SnapshotAssertiondiff --git a/libs/core/tests/unit_tests/test_tools.py b/libs/core/tests/unit_tests/test_tools.pyindex 065e36c866..ce7ea4894b 100644--- a/libs/core/tests/unit_tests/test_tools.py+++ b/libs/core/tests/unit_tests/test_tools.py@@ -47,9 +47,9 @@ from langchain_core.tools import (from langchain_core.tools.base import (InjectedToolArg,SchemaAnnotationError,- _get_all_basemodel_annotations,_is_message_content_block,_is_message_content_type,+ get_all_basemodel_annotations,)from langchain_core.utils.function_calling import convert_to_openai_functionfrom langchain_core.utils.pydantic import PYDANTIC_MAJOR_VERSION, _create_subset_model@@ -1904,19 +1904,19 @@ def test__get_all_basemodel_annotations_v2(use_v1_namespace: bool) -> None:c: dictexpected = {"a": str, "b": Annotated[ModelA[dict[str, Any]], "foo"], "c": dict}- actual = _get_all_basemodel_annotations(ModelC)+ actual = get_all_basemodel_annotations(ModelC)assert actual == expectedexpected = {"a": str, "b": Annotated[ModelA[dict[str, Any]], "foo"]}- actual = _get_all_basemodel_annotations(ModelB)+ actual = get_all_basemodel_annotations(ModelB)assert actual == expectedexpected = {"a": Any}- actual = _get_all_basemodel_annotations(ModelA)+ actual = get_all_basemodel_annotations(ModelA)assert actual == expectedexpected = {"a": int}- actual = _get_all_basemodel_annotations(ModelA[int])+ actual = get_all_basemodel_annotations(ModelA[int])assert actual == expectedD = TypeVar("D", bound=Union[str, int])@@ -1930,7 +1930,7 @@ def test__get_all_basemodel_annotations_v2(use_v1_namespace: bool) -> None:"c": dict,"d": Union[str, int, None],}- actual = _get_all_basemodel_annotations(ModelD)+ actual = get_all_basemodel_annotations(ModelD)assert actual == expectedexpected = {@@ -1939,7 +1939,7 @@ def test__get_all_basemodel_annotations_v2(use_v1_namespace: bool) -> None:"c": dict,"d": Union[int, None],}- actual = _get_all_basemodel_annotations(ModelD[int])+ actual = get_all_basemodel_annotations(ModelD[int])assert actual == expected@@ -1961,19 +1961,19 @@ def test__get_all_basemodel_annotations_v1() -> None:c: dictexpected = {"a": str, "b": Annotated[ModelA[dict[str, Any]], "foo"], "c": dict}- actual = _get_all_basemodel_annotations(ModelC)+ actual = get_all_basemodel_annotations(ModelC)assert actual == expectedexpected = {"a": str, "b": Annotated[ModelA[dict[str, Any]], "foo"]}- actual = _get_all_basemodel_annotations(ModelB)+ actual = get_all_basemodel_annotations(ModelB)assert actual == expectedexpected = {"a": Any}- actual = _get_all_basemodel_annotations(ModelA)+ actual = get_all_basemodel_annotations(ModelA)assert actual == expectedexpected = {"a": int}- actual = _get_all_basemodel_annotations(ModelA[int])+ actual = get_all_basemodel_annotations(ModelA[int])assert actual == expectedD = TypeVar("D", bound=Union[str, int])@@ -1987,7 +1987,7 @@ def test__get_all_basemodel_annotations_v1() -> None:"c": dict,"d": Union[str, int, None],}- actual = _get_all_basemodel_annotations(ModelD)+ actual = get_all_basemodel_annotations(ModelD)assert actual == expectedexpected = {@@ -1996,7 +1996,7 @@ def test__get_all_basemodel_annotations_v1() -> None:"c": dict,"d": Union[int, None],}- actual = _get_all_basemodel_annotations(ModelD[int])+ actual = get_all_basemodel_annotations(ModelD[int])assert actual == expected