Function schema
FuncSchemadataclass
Captures the schema for a python function, in preparation for sending it to an LLM as a tool.
Source code insrc/agents/function_schema.py
params_pydantic_modelinstance-attribute
A Pydantic model that represents the function's parameters.
params_json_schemainstance-attribute
The JSON schema for the function's parameters, derived from the Pydantic model.
takes_contextclass-attribute
instance-attribute
Whether the function takes a RunContextWrapper argument (must be the first argument).
strict_json_schemaclass-attribute
instance-attribute
Whether the JSON schema is in strict mode. Westrongly recommend setting this to True,as it increases the likelihood of correct JSON input.
to_call_args
Converts validated data from the Pydantic model into (args, kwargs), suitable for callingthe original function.
Source code insrc/agents/function_schema.py
FuncDocumentationdataclass
Contains metadata about a python function, extracted from its docstring.
Source code insrc/agents/function_schema.py
descriptioninstance-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 toauto-detect the style. | None |
Returns:
Type | Description |
---|---|
FuncDocumentation | A FuncDocumentation object containing the function's name, description, and parameter |
FuncDocumentation | descriptions. |
Source code insrc/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 aFuncSchema
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 willattempt 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 thedocstring. | None |
use_docstring_info | bool | If True, uses the docstring to generate the description and parameterdescriptions. | True |
strict_json_schema | bool | Whether the JSON schema is in strict mode. If True, we'll ensure thatthe schema adheres to the "strict" standard the OpenAI API expects. Westronglyrecommend setting this to True, as it increases the likelihood of the LLM providingcorrect JSON input. | True |
Returns:
Type | Description |
---|---|
FuncSchema | A |
FuncSchema | and other metadata. |
Source code insrc/agents/function_schema.py
188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
|