From 3814b7edbfe79c1e079e80821941926a362b3ae0 Mon Sep 17 00:00:00 2001 From: Ilyass Tabiai Date: Sun, 26 Jan 2025 20:41:45 -0500 Subject: [PATCH] Added type hints existence validation to make error message when missing more explicit --- .../autogen-core/src/autogen_core/tools/_function_tool.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/python/packages/autogen-core/src/autogen_core/tools/_function_tool.py b/python/packages/autogen-core/src/autogen_core/tools/_function_tool.py index 12cee716f23..17eec0701a9 100644 --- a/python/packages/autogen-core/src/autogen_core/tools/_function_tool.py +++ b/python/packages/autogen-core/src/autogen_core/tools/_function_tool.py @@ -1,6 +1,7 @@ import asyncio import functools import warnings +import typing from textwrap import dedent from typing import Any, Callable, Sequence @@ -87,6 +88,12 @@ def __init__( ) -> None: self._func = func self._global_imports = global_imports + + # Validate type hints exist + hints = typing.get_type_hints(func) + if not hints: + raise TypeError(f"Function '{func.__name__}' has no type hints. All parameters must be annotated.") + signature = get_typed_signature(func) func_name = name or func.__name__ args_model = args_base_model_from_signature(func_name + "args", signature)