diff --git a/src/crewai/tools/tool_calling.py b/src/crewai/tools/tool_calling.py index 16c5e0bfc..4380b154f 100644 --- a/src/crewai/tools/tool_calling.py +++ b/src/crewai/tools/tool_calling.py @@ -1,13 +1,22 @@ -from typing import Any, Dict, Optional +from typing import Any, Dict, Optional, TypedDict from pydantic import BaseModel, Field from pydantic import BaseModel as PydanticBaseModel from pydantic import Field as PydanticField +class ToolArguments(TypedDict, total=False): + """Arguments that can be passed to a tool. + + Set total=False to make all fields optional, which maintains backward + compatibility with existing tools that may not use all arguments. + """ + question: str + + class ToolCalling(BaseModel): tool_name: str = Field(..., description="The name of the tool to be called.") - arguments: Optional[Dict[str, Any]] = Field( + arguments: Optional[ToolArguments] = Field( ..., description="A dictionary of arguments to be passed to the tool." ) @@ -16,6 +25,6 @@ class InstructorToolCalling(PydanticBaseModel): tool_name: str = PydanticField( ..., description="The name of the tool to be called." ) - arguments: Optional[Dict[str, Any]] = PydanticField( + arguments: Optional[ToolArguments] = PydanticField( ..., description="A dictionary of arguments to be passed to the tool." )