| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import Dict, List, Union, Iterable, Optional |
| 4 |
from typing_extensions import Literal, Required, TypeAlias, TypedDict |
| 5 |
|
| 6 |
from .._types import SequenceNotStr |
| 7 |
from .._models import set_pydantic_config |
| 8 |
from .cache_control_ephemeral_param import CacheControlEphemeralParam |
| 9 |
|
| 10 |
__all__ = ["ToolParam", "InputSchema"] |
| 11 |
|
| 12 |
|
| 13 |
class InputSchemaTyped(TypedDict, total=False): |
| 14 |
"""[JSON schema](https://json-schema.org/draft/2020-12) for this tool's input. |
| 15 |
|
| 16 |
This defines the shape of the `input` that your tool accepts and that the model will produce. |
| 17 |
""" |
| 18 |
|
| 19 |
type: Required[Literal["object"]] |
| 20 |
|
| 21 |
properties: Optional[Dict[str, object]] |
| 22 |
|
| 23 |
required: Optional[SequenceNotStr[str]] |
| 24 |
|
| 25 |
|
| 26 |
set_pydantic_config(InputSchemaTyped, {"extra": "allow"}) |
| 27 |
|
| 28 |
InputSchema: TypeAlias = Union[InputSchemaTyped, Dict[str, object]] |
| 29 |
|
| 30 |
|
| 31 |
class ToolParam(TypedDict, total=False): |
| 32 |
input_schema: Required[InputSchema] |
| 33 |
"""[JSON schema](https://json-schema.org/draft/2020-12) for this tool's input. |
| 34 |
|
| 35 |
This defines the shape of the `input` that your tool accepts and that the model |
| 36 |
will produce. |
| 37 |
""" |
| 38 |
|
| 39 |
name: Required[str] |
| 40 |
"""Name of the tool. |
| 41 |
|
| 42 |
This is how the tool will be called by the model and in `tool_use` blocks. |
| 43 |
""" |
| 44 |
|
| 45 |
allowed_callers: List[ |
| 46 |
Literal["direct", "code_execution_20250825", "code_execution_20260120", "code_execution_20260521"] |
| 47 |
] |
| 48 |
|
| 49 |
cache_control: Optional[CacheControlEphemeralParam] |
| 50 |
"""Create a cache control breakpoint at this content block.""" |
| 51 |
|
| 52 |
defer_loading: bool |
| 53 |
"""If true, tool will not be included in initial system prompt. |
| 54 |
|
| 55 |
Only loaded when returned via tool_reference from tool search. |
| 56 |
""" |
| 57 |
|
| 58 |
description: str |
| 59 |
"""Description of what this tool does. |
| 60 |
|
| 61 |
Tool descriptions should be as detailed as possible. The more information that |
| 62 |
the model has about what the tool is and how to use it, the better it will |
| 63 |
perform. You can use natural language descriptions to reinforce important |
| 64 |
aspects of the tool input JSON schema. |
| 65 |
""" |
| 66 |
|
| 67 |
eager_input_streaming: Optional[bool] |
| 68 |
"""Enable eager input streaming for this tool. |
| 69 |
|
| 70 |
When true, tool input parameters will be streamed incrementally as they are |
| 71 |
generated, and types will be inferred on-the-fly rather than buffering the full |
| 72 |
JSON output. When false, streaming is disabled for this tool even if the |
| 73 |
fine-grained-tool-streaming beta is active. When null (default), uses the |
| 74 |
default behavior based on beta headers. |
| 75 |
""" |
| 76 |
|
| 77 |
input_examples: Iterable[Dict[str, object]] |
| 78 |
|
| 79 |
strict: bool |
| 80 |
"""When true, guarantees schema validation on tool names and inputs""" |
| 81 |
|
| 82 |
type: Optional[Literal["custom"]] |