diff --git a/src/anthropic/lib/tools/_beta_functions.py b/src/anthropic/lib/tools/_beta_functions.py index fd4540da8..5b2044408 100644 --- a/src/anthropic/lib/tools/_beta_functions.py +++ b/src/anthropic/lib/tools/_beta_functions.py @@ -171,7 +171,7 @@ def __init__( self._cache_control = cache_control self._allowed_callers = allowed_callers self._eager_input_streaming = eager_input_streaming - self._input_examples = input_examples + self._input_examples = list(input_examples) if input_examples is not None else None self._strict = strict self.description = description or self._get_description_from_docstring() diff --git a/tests/lib/tools/test_functions.py b/tests/lib/tools/test_functions.py index 1152f5d85..17c334e63 100644 --- a/tests/lib/tools/test_functions.py +++ b/tests/lib/tools/test_functions.py @@ -168,6 +168,21 @@ def get_weather(location: str, unit: str = "celsius") -> str: # noqa: ARG001 "required": ["location"], } + def test_input_examples_materialized_from_iterable(self) -> None: + def lookup(city: str) -> str: + return city + + generator_examples = ({"city": c} for c in ["Kraków", "London"]) + tool = beta_tool(lookup, input_examples=generator_examples) + + # First call to to_dict + first_dict = tool.to_dict() + assert first_dict["input_examples"] == [{"city": "Kraków"}, {"city": "London"}] + + # Second call to to_dict must still have the examples + second_dict = tool.to_dict() + assert second_dict["input_examples"] == [{"city": "Kraków"}, {"city": "London"}] + def test_to_dict_method(self) -> None: def simple_func(message: str) -> str: """A simple function."""