StoneRen

关于 Claude 03: 批量工具调用

Oct 28, 2025

单工具调用

User: 123*3是多少,再加56是多少
------------------------------
步骤 1 :
💭 Thought:
我来帮您计算这个数学问题。首先计算123乘以3:
🔧 Tool Use:
calculator ({
  "operation": "multiply",
  "a": 123,
  "b": 3
})
 Tool Result: 123 multiply 3 = 369
------------------------------
步骤 2 :
💭 Thought:
123乘以3等于369。接下来计算369加56:
🔧 Tool Use:
calculator ({
  "operation": "add",
  "a": 369,
  "b": 56
})
 Tool Result: 369 add 56 = 425
------------------------------
步骤 3 :
💭 Thought:
所以:
- 123 × 3 = 369
- 369 + 56 = 425
最终结果是425。
============================================================
 Final Answer:
所以:
- 123 × 3 = 369
- 369 + 56 = 425
最终结果是425。

很简单的演示过程。

多任务

以下是官方的一个示例。

============================================================
🤖 React Agent
============================================================

User: 帮我设定一个提醒。在20天后上午时间,我要约一下唐医生,下午3点去高尔夫球场。

------------------------------

步骤 1 :

💭 Thought:

我来帮你设定这两个提醒。让我先计算20天后的日期,然后为你创建提醒。

🔧 Tool Use:
calculate_future_or_past_time ({
  "amount": 20,
  "format": "YYYY-MM-DD",
  "unit": "day"
})

 Tool Result: 2025-11-16

------------------------------

步骤 2 :

💭 Thought:

好的,现在我为你设定这两个提醒:

🔧 Tool Use:
set_reminder ({
  "content": "约唐医生",
  "timestamp": "2025-11-16 10:00:00"
})

🔧 Tool Use:
set_reminder ({
  "content": "下午3点去高尔夫球场",
  "timestamp": "2025-11-16 15:00:00"
})

 Tool Result: 已经设置好提醒,在2025-11-16 10:00:00时间前会提醒你 约唐医生

 Tool Result: 已经设置好提醒,在2025-11-16 15:00:00时间前会提醒你 下午3点去高尔夫球场

------------------------------

步骤 3 :

💭 Thought:

完成!我已经为你设置好了两个提醒:

1. **2025年11月16日上午10点** - 提醒你约唐医生
2. **2025年11月16日下午3点** - 提醒你去高尔夫球场

这两个提醒都设定在20天后(11月16日),一个在上午,一个在下午3点整。届时会准时提醒你。

============================================================

 Final Answer:

完成!我已经为你设置好了两个提醒:

1. **2025年11月16日上午10点** - 提醒你约唐医生
2. **2025年11月16日下午3点** - 提醒你去高尔夫球场

这两个提醒都设定在20天后(11月16日),一个在上午,一个在下午3点整。届时会准时提醒你。

区别

在用国内模型的时候,输出结果一般如下,这里的国内模型是GLM-4.5,DeepSeek 3.2

------------------------------

步骤 1 :

🔧 Tool Use:
calculate_future_or_past_time ({
  "amount": 20,
  "unit": "day",
  "format": "YYYY-MM-DD"
})

 Tool Result: 2025-11-16

------------------------------

步骤 2 :

🔧 Tool Use:
set_reminder ({
  "content": "约唐医生 - 上午时间",
  "timestamp": "2025-11-16 09:00:00"
})

 Tool Result: 已经设置好提醒,在2025-11-16 09:00:00时间前会提醒你 约唐医生 - 上午时间

------------------------------

步骤 3 :

🔧 Tool Use:
set_reminder ({
  "content": "下午3点去高尔夫球场",
  "timestamp": "2025-11-16 15:00:00"
})

 Tool Result: 已经设置好提醒,在2025-11-16 15:00:00时间前会提醒你 下午3点去高尔夫球场

------------------------------

看出区别来了吗。

同样问题,claude v4.5在步骤中同时调用了2个工具并返回结果,但是国内模型是逐一调用的。

在claude中,这种操作叫做批量工具调用

日常工具调用

claude进行了专门的优化。

claude优化

实现

实现比较简单,官方给的代码。

batch_tool_schema = ToolParam({
  "name": "batch_tool",
  "description": "Invoke multiple other tool calls simultaneously",
  "input_schema": {
    "type": "object",
    "properties": {
      "invocations": {
        "type": "array",
        "description": "The tool calls to invoke",
        "items": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "description": "The name of the tool to invoke"
            },
            "arguments": {
              "type": "string",
              "description": "The arguments to the tool, encoded as a JSON string"
            }
          },
          "required": [
            "name",
            "arguments"
          ]
        }
      }
    },
    "required": [
      "invocations"
    ]
  }
})


tools=[
    get_current_time_schema,
    add_duration_to_datetime_schema,
    set_reminder_schema,
    batch_tool_schema,
],
0-PRESENT © StoneRenver:2511011029