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 src/agents/function_schema.py
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).
to_call_args
Converts validated data from the Pydantic model into (args, kwargs), suitable for calling the original function.
Source code in src/agents/function_schema.py
FuncDocumentation
dataclass
Contains metadata about a python function, extracted from its docstring.
Source code in 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 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 providing correct JSON input. |
True
|
Returns:
Type | Description |
---|---|
FuncSchema
|
A |
FuncSchema
|
and other metadata. |
Source code in src/agents/function_schema.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|