客戶希望機器人能自動讀取客戶上傳的收據、查詢申報進度資料庫、並用白話回覆同事的提問,而且要給20幾位員工天天使用
LFM2.5-2.6B是Liquid AI推出的一個小型代理式AI模型(agentic AI model)不只回答問題,還會自己規劃步驟、判斷該呼叫哪個工具、一步步把任務完成的AI,只有參數量(parameters)AI內部用來儲存規則與知識的「旋鈕」數量,數字越大通常代表模型讀過、記住的東西越多26億個(2.6B),卻能在多項考驗上打平甚至打贏參數量是它4倍的模型。
之所以能把「小」跟「強」兼顧,關鍵在於推論效率:在蘋果M5 Max筆電上能跑到每秒220個字,在一般AMD Ryzen CPU(不需要顯示卡)上也有每秒113個字,而且全程只佔用不到2.5GB記憶體。也就是說,普通的辦公用筆電,不用額外添購昂貴顯卡,就能把它當成一位隨傳隨到的私人AI員工。
LFM2.5並不是憑空長出這身本事——它先經過預訓練(pretraining)讓AI通讀天量文字資料,打好語言與常識基礎的第一階段(讀過大約34兆個字),接著用知識蒸餾(distillation)讓一個小模型觀摩多位「專家老師模型」的解法,把濃縮出的精華學起來,變成又小又厲害的學生模型和強化學習(reinforcement learning)讓AI實際動手做任務、依照做得好不好給獎勵或懲罰,透過不斷試錯調整行為的訓練方式,在真的代理框架(像OpenClaw、Hermes Agent)裡反覆演練,才練出「懂得該呼叫哪個工具」的判斷力。
| 模型(參數量) | IFBench 指令遵循 | BFCLv4 工具呼叫 | ToolSandbox 工具箱測試 | Multi-IF 多步驟指令 |
|---|---|---|---|---|
| LFM2.5-2.6B(26億) | 59.17 | 56.88 | 77.83 | 80.07 |
| gemma-4-E2B-it(51億) | 34.08 | 36.98 | 52.40 | 69.44 |
| gemma-4-E4B-it(80億) | 39.24 | 46.39 | 65.00 | 77.35 |
| Qwen3.5-4B(47億) | 48.40 | 50.56 | 75.55 | 55.67 |
| Qwen3.5-9B(97億) | 56.47 | 60.13 | 76.44 | 62.55 |
對照本課下載範例 local_agent_demo.py,看LFM2.5-2.6B怎麼判斷「這題該查工具,不是用猜的」。
MODEL_ID = 'LiquidAI/LFM2.5-2.6B'def get_monthly_revenue(month: str) -> str:TOOLS = [{'type': 'function', 'function': {...}}]tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)model = AutoModelForCausalLM.from_pretrained(..., device_map='cpu')prompt = tokenizer.apply_chat_template(messages, tools=TOOLS, ...)output = model.generate(**inputs, max_new_tokens=150, do_sample=False)reply = tokenizer.decode(output[0][inputs['input_ids'].shape[1]:], ...)這是一個真實小專案:下載(或複製)檔案,照步驟在你電腦上跑起來。
transformers>=4.46.0
torch>=2.3.0
accelerate>=0.34.0
# LFM2.5-2.6B 本地代理示範:模擬老闆問「三月營業額」,觀察模型何時決定呼叫工具,而不是憑空亂猜。
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
MODEL_ID = 'LiquidAI/LFM2.5-2.6B' # 若 Hugging Face 上實際名稱略有出入,以 LiquidAI 官方頁面公告為準
def get_monthly_revenue(month: str) -> str:
# 假裝這是連到公司內部資料庫的工具,這裡先用假資料模擬回應
fake_db = {'一月': '82萬', '二月': '76萬', '三月': '95萬'}
return fake_db.get(month, '查無資料')
TOOLS = [
{
'type': 'function',
'function': {
'name': 'get_monthly_revenue',
'description': '查詢指定月份的營業額',
'parameters': {
'type': 'object',
'properties': {
'month': {'type': 'string', 'description': '月份,例如:一月'}
},
'required': ['month'],
},
},
}
]
def main():
print('正在載入 LFM2.5-2.6B(第一次執行會下載模型檔案,約需幾分鐘,請耐心等候)...')
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
MODEL_ID,
trust_remote_code=True,
torch_dtype=torch.bfloat16,
device_map='cpu',
)
messages = [{'role': 'user', 'content': '老闆想知道三月的營業額是多少?'}]
prompt = tokenizer.apply_chat_template(
messages, tools=TOOLS, add_generation_prompt=True, tokenize=False
)
inputs = tokenizer(prompt, return_tensors='pt')
print('模型思考中(純 CPU 約需 10-30 秒,請稍候)...')
output = model.generate(**inputs, max_new_tokens=150, do_sample=False)
reply = tokenizer.decode(
output[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True
)
print('\n=== 模型原始回覆 ===')
print(reply)
print('\n如果回覆內容包含呼叫 get_monthly_revenue 的請求,代表模型判斷這題要查真實資料,不能亂編——')
print('這正是文章說的工具使用能力:知道什麼時候該停下來求助工具,而不是硬掰答案。')
if __name__ == '__main__':
main()