Skip to main content
Anthropic API 官方已支持工具调用,因此不再需要此解决方案。请使用 ChatAnthropic 并配合 langchain-anthropic>=0.1.15 使用。
本笔记本展示了如何使用围绕 Anthropic 的实验性包装器,使其具备工具调用和结构化输出能力。它遵循 Anthropic 的工具使用指南。 该包装器可从 langchain-anthropic 包获取,并且它还需要可选依赖 defusedxml 来解析来自 llm 的 XML 输出。 注意:这是一个测试性功能,将被 Anthropic 的正式工具调用实现所取代,但在过渡期间它对测试和实验很有用。

工具绑定

ChatAnthropicTools 提供了一个 bind_tools 方法,允许您将 Pydantic 模型或 BaseTools 传递给 llm。

结构化输出

ChatAnthropicTools 还实现了 with_structured_output 规范 来提取值。注意:这可能不如显式提供工具调用的模型稳定。

官方原文:src/oss/python/integrations/chat/anthropic_functions.mdx · 非官方翻译,译文由 AI 生成,以英文原文为准。
Last modified on November 3, 2026