Skip to content

Tools

src.data_models.tools.FunctionParameters

Bases: BaseModel

Schema for function parameters following JSON Schema specification.

This class defines the structure for function parameters using JSON Schema. It specifies the type, properties, required fields, and whether additional properties are allowed.

Attributes:

Name Type Description
type str

The type of the parameters object, always "object".

properties Dict[str, Dict[str, Any]]

Mapping of parameter names to their JSON Schema definitions.

required Optional[List[str]]

List of required parameter names.

additionalProperties Optional[bool]

Whether additional properties beyond those specified are allowed.

Example
parameters = FunctionParameters(
    type="object",
    properties={
        "location": {
            "type": "string",
            "description": "City name or coordinates"
        }
    },
    required=["location"]
)
Source code in src/data_models/tools.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class FunctionParameters(BaseModel):
    """Schema for function parameters following JSON Schema specification.

    This class defines the structure for function parameters using JSON Schema.
    It specifies the type, properties, required fields, and whether additional
    properties are allowed.

    Attributes:
        type (str): The type of the parameters object, always "object".
        properties (Dict[str, Dict[str, Any]]): Mapping of parameter names to their
            JSON Schema definitions.
        required (Optional[List[str]]): List of required parameter names.
        additionalProperties (Optional[bool]): Whether additional properties beyond
            those specified are allowed.

    Example:
        ```python
        parameters = FunctionParameters(
            type="object",
            properties={
                "location": {
                    "type": "string",
                    "description": "City name or coordinates"
                }
            },
            required=["location"]
        )
        ```
    """
    type: str = "object"
    properties: Dict[str, Dict[str, Any]]
    required: Optional[List[str]] = None
    additionalProperties: Optional[bool] = None

src.data_models.tools.Function

Bases: BaseModel

Represents a function that can be called by the model.

Defines the structure of a callable function, including its name, description, parameters, and validation settings.

Attributes:

Name Type Description
name str

Function identifier, must be 1-64 characters and contain only alphanumeric characters, underscores, and hyphens.

description Optional[str]

Human-readable description of what the function does.

parameters Optional[FunctionParameters]

Schema defining the function's parameters.

strict Optional[bool]

Whether to enforce strict parameter validation. Defaults to False.

Example
function = Function(
    name="get_weather",
    description="Get current weather for a location",
    parameters=FunctionParameters(...),
    strict=True
)
Source code in src/data_models/tools.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class Function(BaseModel):
    """Represents a function that can be called by the model.

    Defines the structure of a callable function, including its name,
    description, parameters, and validation settings.

    Attributes:
        name (str): Function identifier, must be 1-64 characters and contain only
            alphanumeric characters, underscores, and hyphens.
        description (Optional[str]): Human-readable description of what the
            function does.
        parameters (Optional[FunctionParameters]): Schema defining the function's
            parameters.
        strict (Optional[bool]): Whether to enforce strict parameter validation.
            Defaults to False.

    Example:
        ```python
        function = Function(
            name="get_weather",
            description="Get current weather for a location",
            parameters=FunctionParameters(...),
            strict=True
        )
        ```
    """
    name: str = Field(..., max_length=64, pattern="^[a-zA-Z0-9_-]+$")
    description: Optional[str] = None
    parameters: Optional[FunctionParameters] = None
    strict: Optional[bool] = Field(default=False)

src.data_models.tools.Tool

Bases: BaseModel

Represents a tool that the model can use.

A tool is a wrapper around a function that can be called by the model. Currently, only function-type tools are supported.

Attributes:

Name Type Description
type Literal['function']

The type of tool, currently only "function" is supported.

function Function

The function definition for this tool.

Example
tool = Tool(
    type="function",
    function=Function(
        name="get_weather",
        description="Get current weather",
        parameters=FunctionParameters(...),
        strict=True
    )
)
Source code in src/data_models/tools.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class Tool(BaseModel):
    """Represents a tool that the model can use.

    A tool is a wrapper around a function that can be called by the model.
    Currently, only function-type tools are supported.

    Attributes:
        type (Literal["function"]): The type of tool, currently only "function"
            is supported.
        function (Function): The function definition for this tool.

    Example:
        ```python
        tool = Tool(
            type="function",
            function=Function(
                name="get_weather",
                description="Get current weather",
                parameters=FunctionParameters(...),
                strict=True
            )
        )
        ```
    """
    type: Literal["function"] = "function"
    function: Function

src.data_models.tools.ToolsList

Bases: BaseModel

Container for a list of tools.

Manages a collection of tools that can be provided to the model, with a maximum limit of 128 tools.

Attributes:

Name Type Description
tools List[Tool]

List of tool definitions, maximum length of 128.

Source code in src/data_models/tools.py
102
103
104
105
106
107
108
109
110
111
class ToolsList(BaseModel):
    """Container for a list of tools.

    Manages a collection of tools that can be provided to the model,
    with a maximum limit of 128 tools.

    Attributes:
        tools (List[Tool]): List of tool definitions, maximum length of 128.
    """
    tools: List[Tool] = Field(..., max_length=128)