Function schema
FuncSchema
dataclass
Captures the schema for a python function, in preparation for sending it to an LLM as a tool.
Source code in .tmp/v0/src/agents/function_schema.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 72 73 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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
params_pydantic_model
instance-attribute
A Pydantic model that represents the function's parameters.
params_json_schema
instance-attribute
The JSON schema for the function's parameters, derived from the Pydantic model.
takes_context
class-attribute
instance-attribute
Whether the function takes a RunContextWrapper argument (must be the first argument).
strict_json_schema
class-attribute
instance-attribute
Whether the JSON schema is in strict mode. We strongly recommend setting this to True, as it increases the likelihood of correct JSON input.
return_annotation
class-attribute
instance-attribute
The resolved return annotation, including Annotated metadata when present.
to_call_args
Converts validated data from the Pydantic model into (args, kwargs), suitable for calling the original function.
Raises:
| Type | Description |
|---|---|
ModelBehaviorError
|
If the |
Source code in .tmp/v0/src/agents/function_schema.py
FuncDocumentation
dataclass
Contains metadata about a Python function, extracted from its docstring.
Source code in .tmp/v0/src/agents/function_schema.py
description
instance-attribute
The description of the function, derived from the docstring.
generate_func_documentation
generate_func_documentation(
func: Callable[..., Any],
style: DocstringStyle | None = None,
) -> FuncDocumentation
Extracts metadata from a function docstring, in preparation for sending it to an LLM as a tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
The function to extract documentation from. |
required |
style
|
DocstringStyle | None
|
The style of the docstring to use for parsing. If not provided, we will attempt to auto-detect the style. |
None
|
Returns:
| Type | Description |
|---|---|
FuncDocumentation
|
A FuncDocumentation object containing the function's name, description, and parameter |
FuncDocumentation
|
descriptions. |
Source code in .tmp/v0/src/agents/function_schema.py
function_schema
function_schema(
func: Callable[..., Any],
docstring_style: DocstringStyle | None = None,
name_override: str | None = None,
description_override: str | None = None,
use_docstring_info: bool = True,
strict_json_schema: bool = True,
) -> FuncSchema
Given a Python function, extracts a FuncSchema from it, capturing the name, description,
parameter descriptions, and other metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
The function to extract the schema from. |
required |
docstring_style
|
DocstringStyle | None
|
The style of the docstring to use for parsing. If not provided, we will attempt to auto-detect the style. |
None
|
name_override
|
str | None
|
If provided, use this name instead of the function's |
None
|
description_override
|
str | None
|
If provided, use this description instead of the one derived from the docstring. |
None
|
use_docstring_info
|
bool
|
If True, uses the docstring to generate the description and parameter descriptions. |
True
|
strict_json_schema
|
bool
|
Whether the JSON schema is in strict mode. If True, we'll ensure that the schema adheres to the "strict" standard the OpenAI API expects. We strongly recommend setting this to True, as it increases the likelihood of the LLM producing correct JSON input. |
True
|
Returns:
| Type | Description |
|---|---|
FuncSchema
|
A |
FuncSchema
|
and other metadata. |