mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
feat: add TypedDict for tool arguments
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -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, Field
|
||||||
from pydantic import BaseModel as PydanticBaseModel
|
from pydantic import BaseModel as PydanticBaseModel
|
||||||
from pydantic import Field as PydanticField
|
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):
|
class ToolCalling(BaseModel):
|
||||||
tool_name: str = Field(..., description="The name of the tool to be called.")
|
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."
|
..., description="A dictionary of arguments to be passed to the tool."
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,6 +25,6 @@ class InstructorToolCalling(PydanticBaseModel):
|
|||||||
tool_name: str = PydanticField(
|
tool_name: str = PydanticField(
|
||||||
..., description="The name of the tool to be called."
|
..., 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."
|
..., description="A dictionary of arguments to be passed to the tool."
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user