tools = [{
"name": "get_weather",
"description": "查询城市天气",
"input_schema": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}]
resp = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024, tools=tools,
messages=[{"role": "user", "content": "北京天气?"}]
)
if resp.stop_reason == "tool_use":
print(f"调用工具:{resp.content[1].input}")
tools = [{name: "calculator"}]
tools = [{name: "calculator"}]
if stop_reason == "tool_use"
if stop_reason == "tool_use"