> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# （已弃用）实验性 Anthropic 工具包装器集成

> 集成（已弃用）实验性 Anthropic 工具包装器聊天模型，使用 LangChain Python。

> [!WARNING]
>
> **Anthropic API 官方已支持工具调用，因此不再需要此解决方案。请使用 [ChatAnthropic](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/chat/anthropic.md) 并配合 `langchain-anthropic>=0.1.15` 使用。**

本笔记本展示了如何使用围绕 Anthropic 的实验性包装器，使其具备工具调用和结构化输出能力。它遵循 [Anthropic 的工具使用指南](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview)。

该包装器可从 `langchain-anthropic` 包获取，并且它还需要可选依赖 `defusedxml` 来解析来自 llm 的 XML 输出。

注意：这是一个测试性功能，将被 Anthropic 的正式工具调用实现所取代，但在过渡期间它对测试和实验很有用。

```python theme={null}
pip install -qU langchain-anthropic defusedxml
from langchain_anthropic.experimental import ChatAnthropicTools
```

## 工具绑定

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

```python theme={null}
from pydantic import BaseModel


class Person(BaseModel):
    name: str
    age: int


model = ChatAnthropicTools(model="claude-3-opus-20240229").bind_tools(tools=[Person])
model.invoke("I am a 27 year old named Erick")
```

```text theme={null}
AIMessage(content='', additional_kwargs={'tool_calls': [{'function': {'name': 'Person', 'arguments': '{"name": "Erick", "age": "27"}'}, 'type': 'function'}]})
```

## 结构化输出

`ChatAnthropicTools` 还实现了 [`with_structured_output` 规范](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/structured-output) 来提取值。注意：这可能不如显式提供工具调用的模型稳定。

```python theme={null}
chain = ChatAnthropicTools(model="claude-3-opus-20240229").with_structured_output(
    Person
)
chain.invoke("I am a 27 year old named Erick")
```

```text theme={null}
Person(name='Erick', age=27)
```

***

> 官方原文：[src/oss/python/integrations/chat/anthropic\_functions.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/python/integrations/chat/anthropic_functions.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.