The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
fix(core): allow base model annotations for empty model (#34932)
Akshaya Shanbhogue84864d77ed3b
diff --git a/libs/core/langchain_core/tools/base.py b/libs/core/langchain_core/tools/base.pyindex 8eb2ba6643..b2c7b34bca 100644--- a/libs/core/langchain_core/tools/base.py+++ b/libs/core/langchain_core/tools/base.py@@ -1488,7 +1488,7 @@ def get_all_basemodel_annotations(for name, param in inspect.signature(cls).parameters.items():# Exclude hidden init args added by pydantic Config. For example if# BaseModel(extra="allow") then "extra_data" will part of init sig.- if fields and name not in fields and name not in alias_map:+ if name not in fields and name not in alias_map:continuefield_name = alias_map.get(name, name)annotations[field_name] = param.annotationdiff --git a/libs/core/tests/unit_tests/test_tools.py b/libs/core/tests/unit_tests/test_tools.pyindex 0c49cfbef5..76506ae2a4 100644--- a/libs/core/tests/unit_tests/test_tools.py+++ b/libs/core/tests/unit_tests/test_tools.py@@ -2150,12 +2150,17 @@ def test__get_all_basemodel_annotations_v2(*, use_v1_namespace: bool) -> None:class ModelA(BaseModelV1, Generic[A], extra="allow"):a: A+ class EmptyModel(BaseModelV1, Generic[A], extra="allow"):+ passelse:class ModelA(BaseModel, Generic[A]): # type: ignore[no-redef]a: Amodel_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")+ class EmptyModel(BaseModel, Generic[A]): # type: ignore[no-redef]+ model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")+class ModelB(ModelA[str]):b: Annotated[ModelA[dict[str, Any]], "foo"]@@ -2205,6 +2210,10 @@ def test__get_all_basemodel_annotations_v2(*, use_v1_namespace: bool) -> None:actual = get_all_basemodel_annotations(ModelD[int])assert actual == expected+ expected = {}+ actual = get_all_basemodel_annotations(EmptyModel)+ assert actual == expected+def test_get_all_basemodel_annotations_aliases() -> None:class CalculatorInput(BaseModel):