一、程式碼的問題
原本的:
</>Python
training_example = {
"instruction": "幫我查一下預算表,並在明天下午三點排個審核會。",
"output": '{"tool": "query_database", "params": {"query": "budget_2026"}}\n'
'{"tool": "add_calendar_event", "params": {"title": "預算審核", "start_time": "2026-03-04T15:00"}}'
}
問題有三個
1️⃣ JSON key 不一致
工具定義query_database(query_str)
但訓練資料
{"query": "..."}
應該要一致
{"query_str": "..."}
2️⃣ "明天下午三點" 被硬編碼
訓練資料不應寫死日期。
否則模型會學錯。
3️⃣ LLM 訓練格式不完整
目前主流 instruction tuning 格式通常是
system
user
assistant
而不是只有 instruction。
二、正確的 LLM Tool Calling 訓練格式
建議使用這種:
</>Python
training_data = [
{
"messages": [
{
"role": "system",
"content": """你是一位專業助理。你可以使用以下工具:
1. query_database(query_str): 查詢數據庫
2. add_calendar_event(title, start_time): 新增行事曆
如果需要使用工具,請輸出 JSON:
{"tool": "...", "params": {...}}"""
},
{
"role": "user",
"content": "幫我查一下預算表,並在明天下午三點排個審核會。"
},
{
"role": "assistant",
"content": """{"tool": "query_database", "params": {"query_str": "budget"}}
{"tool": "add_calendar_event", "params": {"title": "預算審核", "start_time": "tomorrow 15:00"}}"""
}
]
}
]
三、如果是訓練 LLaMA / Mistral
常用格式是 Alpaca 格式
</>Python
training_data = [
{
"system": """你是一位專業助理。可以使用工具。""",
"instruction": "幫我查一下預算表,並在明天下午三點排個審核會。",
"output": """{"tool": "query_database", "params": {"query_str": "budget"}}
{"tool": "add_calendar_event", "params": {"title": "預算審核", "start_time": "tomorrow 15:00"}}"""
}
]
四、真正可用的 Tool Calling 訓練資料(專業版本)
推薦格式:
</>Python
{
"instruction": "幫我查一下預算表,並在明天下午三點排個審核會。",
"tools": [
{
"name": "query_database",
"description": "查詢資料庫",
"parameters": {
"type": "object",
"properties": {
"query_str": {"type": "string"}
}
}
},
{
"name": "add_calendar_event",
"description": "新增行事曆",
"parameters": {
"type": "object",
"properties": {
"title": {"type": "string"},
"start_time": {"type": "string"}
}
}
}
],
"output": [
{
"tool": "query_database",
"params": {"query_str": "budget"}
},
{
"tool": "add_calendar_event",
"params": {"title": "預算審核", "start_time": "tomorrow 15:00"}
}
]
}
五、LLM Tool Calling 的完整流程
實際系統會是:
User
↓
LLM
↓
輸出 JSON tool call
↓
Backend 執行 tool
↓
結果回傳 LLM
↓
LLM 回覆 user
例如
User
幫我查預算
LLM
{"tool":"query_database","params":{"query_str":"budget"}}
Backend
查詢 DB
Result
2026 budget = 3M
LLM
2026 預算為 300 萬
六、真正 AI 公司用的資料量
訓練 Tool Calling:
最低
500 examples
正常
5,000 examples
OpenAI / Anthropic
50,000+
七、如果用 4090 自己訓練 Tool LLM
可以跑:
Llama 3 8B
Mistral 7B
Qwen 7B
用 QLoRA
VRAM需求:
約 16GB4090 完全可以。

















