From 3c9e0667790c1dd21d438e60c7ecba24d10f074f Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 24 Feb 2025 13:22:29 +0000 Subject: [PATCH] feat: add TypedDict for tool arguments Co-Authored-By: Joe Moura --- src/crewai/tools/tool_calling.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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." )