feat: add TypedDict for tool arguments

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-02-24 13:22:29 +00:00
parent a3b3b411df
commit 3c9e066779

View File

@@ -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."
)