用途:帮助开发者让大语言模型调用外部工具并返回结构化数据,属于面向 LLM function calling 与 tool use 的实践指南。主要能力:工具定义(含名称、描述、JSON schema 参数)、工具执行循环(持续执行工具调用直至模型给出最终答案)、结构化输出(用 Pydantic 模型配合 parse 获得类型化结果)、LangChain 工具绑定(@tool、bind_tools、with_structured_output)、并行工具调用(parallel_tool_calls 与 asyncio.gather 并发执行)。用法要点:定义工具时写清 1-2 句描述;参数用 Pydantic/Zod 校验;错误作为工具结果返回;循环中把工具结果以 role=tool 消息追加回对话。文档建议 strict 模式需所有属性列入 required、additionalProperties 为 False、不设 default,且 strict 与并行调用可能不兼容,此时应关闭 parallel_tool_calls。关键决策:工具数量控制在 5-15 个,schema 采用 strict: true,输出优先用 Structured Outputs 而非 JSON 模式。常见错误包括工具描述含糊、缺少输入校验、缺少错误处理、工具过多导致模型混淆。关联技能包括 agent-loops、llm-streaming、structured-output。限制:价格、平台支持范围与具体模型可用性暂未提供;示例中提及的 2026 建议属资料原有表述。
function-calling
通用与其它
更新于 10-16 04:32