[BUG] 类中定义的工具引发 TypeHintParsingException
作者: faev999创建于 2025年2月17日更新于 2026年9月27日
标签bug
描述错误
将类实例方法定义为工具时,会引发以下错误:smolagents._function_type_hints_utils.TypeHintParsingException: Argument self is missing a type hint in function test_tool
重现错误的代码 示例:
from smolagents import tool, CodeAgent, LiteLLMModel
import os
class Test:
@tool
def test_tool(self, text: str) -> str:
"""
A test tool that takes a text as input and returns a string.
Args:
self: The class object.
text: The input text.
Returns:
string: The output string.
"""
stringer = f"This is a test tool. The text is: {text}"
return stringer
model_manager_agent = LiteLLMModel(
model_id="cerebras/LLaMA-3.3-70b",
api_key=os.getenv("CEREBRAS_API_KEY"),
)
manager_agent = CodeAgent(
tools=[],
model=model_manager_agent,
# prompt_templates=pepper_prompt_templates,
)
test = Test()
manager_agent.tools["test_tool"] = test.test_tool
manager_agent.run("what's up?")错误日志(如果有)
smolagents\_function_type_hints_utils.py", line 287, in _convert_type_hints_to_json_schema
raise TypeHintParsingException(f"Argument {param.name} is missing a type hint in function {func.__name__}")
smolagents._function_type_hints_utils.TypeHintParsingException: Argument self is missing a type hint in function test_tool预期行为 我正在尝试在类中定义工具,因此我可以访问其他方法和属性
内容来源: huggingface/smolagents