Claude Tool Use 实战
2026-05-09
·
Anthropic
## Claude Tool Use 实战
### 什么是Tool Use
Anthropic的工具调用机制,与OpenAI Function Calling类似但有独特设计。
### 基本用法
```python
from anthropic import Anthropic
client = Anthropic()
tools = [{
"name": "get_weather",
"description": "获取城市天气",
"input_schema": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "城市名称"}
},
"required": ["city"]
}
}]
response = client.messages.create(
model="claude-3-7-sonnet-20250219",
max_tokens=1024,
messages=[{"role": "user", "content": "北京天气?"}],
tools=tools
)
```
评论区