Function schema
FuncSchema
dataclass
捕获 Python 函数的 schema,为将其作为工具发送到 LLM 做准备。
Source code in src/agents/function_schema.py
params_pydantic_model
instance-attribute
表示函数参数的 Pydantic 模型。
params_json_schema
instance-attribute
从 Pydantic 模型派生出的函数参数的 JSON schema。
takes_context
class-attribute
instance-attribute
函数是否接收 RunContextWrapper 参数(必须是第一个参数)。
strict_json_schema
class-attribute
instance-attribute
JSON schema 是否为严格模式。我们强烈建议将其设置为 True, 因为这会提高正确 JSON 输入的概率。
to_call_args
将 Pydantic 模型中验证过的数据转换为 (args, kwargs),以便调用原始函数。
Source code in src/agents/function_schema.py
FuncDocumentation
dataclass
包含从 Python 函数 docstring 中提取的元数据。
Source code in src/agents/function_schema.py
generate_func_documentation
generate_func_documentation(
func: Callable[..., Any],
style: DocstringStyle | None = None,
) -> FuncDocumentation
从函数 docstring 中提取元数据,为将其作为工具发送到 LLM 做准备。
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[..., Any]
|
要提取文档的函数。 |
required |
style
|
DocstringStyle | None
|
用于解析 docstring 的风格。如果未提供,将尝试自动检测风格。 |
None
|
Returns:
Type | Description |
---|---|
FuncDocumentation
|
包含函数名称、描述和参数描述的 FuncDocumentation 对象。 |
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
给定一个 Python 函数,从中提取 FuncSchema
,捕获名称、描述、参数描述及其他元数据。
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[..., Any]
|
要提取 schema 的函数。 |
required |
docstring_style
|
DocstringStyle | None
|
用于解析 docstring 的风格。如果未提供,将尝试自动检测风格。 |
None
|
name_override
|
str | None
|
如果提供,则使用该名称替代函数的 |
None
|
description_override
|
str | None
|
如果提供,则使用该描述替代从 docstring 派生的描述。 |
None
|
use_docstring_info
|
bool
|
如果为 True,则使用 docstring 生成描述和参数描述。 |
True
|
strict_json_schema
|
bool
|
JSON schema 是否为严格模式。如果为 True,将确保 schema 符合 OpenAI API 期望的“strict”标准。我们强烈 建议将其设置为 True,因为这会提高 LLM 提供正确 JSON 输入的概率。 |
True
|
Returns:
Type | Description |
---|---|
FuncSchema
|
包含函数名称、描述、参数描述及其他元数据的 |
Source code in src/agents/function_schema.py
181 182 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 |
|