Apple Developer onepage/WWDC26
#WWDC26#MLX#AgenticAI#macOS2026-06-08 · 13:37

用 MLX 把 agentic AI 留在 Mac 本機跑

這場 session 示範如何用 MLX-LM Server、OpenCode 與 Xcode 27,把 coding agent 的模型推論、工具呼叫與修錯迴圈都放在 Apple silicon 上完成。

// 一句話結論

Apple 給出的路線不是把 agent 全部送上雲,而是把「模型、工具、檔案、build」串成本機迴圈:程式碼與資料留在 Mac,只有你明確呼叫的外部工具才碰網路。

Apple Developer · WWDC26 · Video ID: wykPErJ8M-8Apple Developer 官方頁
Content map

這支影片在回答三個本機 agent 問題

Agent loop

chat 不是 agent,工具迴圈才是 agent

傳統聊天只回文字;agent 會讓模型決定下一步、呼叫工具、觀察結果,再回到模型。影片把這個 user → agent → model → tools 的循環視為整套架構的核心。

Local stack

MLX stack 對齊 OpenAI-compatible 工作流

底層是 MLX,往上是 MLX-LM、MLX-LM Server,再接 OpenCode、Xcode 或其他 agent。關鍵是 server 暴露 OpenAI-compatible HTTP API,讓既有工具不用為 MLX 重寫。

Performance

agent 需要長 context 與併發服務

agent 會反覆塞入檔案、diff、tool results。MLX 用 Apple silicon、Neural Accelerators、continuous batching 與分散式推論,降低長 prompt 與多 subagent 的等待。

Workflow

Xcode 也能接本機模型

Xcode 27 的 Intelligence 設定可加入 Locally Hosted provider,指到 MLX-LM Server。這讓修 bug、讀 build error、改檔案可以留在本機開發環境內。

Implementation flow

從零到本機 coding agent 的導入路徑

1

安裝 MLX-LM 並選 tool-calling model

影片 sample code 用 pip install mlx-lm,再以 mlx_lm.server 啟動 Qwen 3.5 4B 8-bit 這類可工具呼叫的模型。

2

啟動 OpenAI-compatible local endpoint

MLX-LM Server 預設可被 agent 當成 /v1/chat/completions endpoint 使用,常見 base URL 是 http://127.0.0.1:8080/v1。

3

把 agent provider 指到本機

OpenCode 範例把 provider 設成 @ai-sdk/openai-compatible,model 指到 mlx/default_model;Xcode 則在 Intelligence 加入 Locally Hosted provider。

4

先測小型任務,再測專案修改

影片先用 GitHub CLI 摘要 PR,再示範從空 Xcode 專案生成 SwiftUI drawing app、build、修錯與再迭代。

5

用 continuous batching / distributed inference 擴展

多 subagent 或大模型時,continuous batching 避免請求排隊;更大模型可透過 Thunderbolt / Ethernet 分散到多台 Mac。

Official chapter map
0:00
Introduction
0:32
The chat and agentic loop
2:42
Local agentic AI stack
4:36
Setting up your own agent
5:39
Making agents fast
6:53
Concurrency and distributed inference
9:20
More examples
13:01
Next steps

重點 1:本機 agent 的價值是隱私、延遲、離線與成本

影片一開始就把邊界講清楚:模型推論在自己的 Mac 上跑,不需要 cloud API key,也沒有每次 token 成本。對 coding agent 來說,這代表 repo、diff、build log、使用者 prompt 可以留在本機;只有 agent 明確呼叫的外部工具,例如 GitHub CLI,才會碰到網路。

這不是說本機 agent 天然安全。它仍然能呼叫 shell、讀檔、打 API;真正的安全性來自工具權限、工作目錄邊界、secret 管理與審核流程。

重點 2:四層 stack 把 MLX 接到現有 agent 生態

MLXApple silicon 專用的 open-source array framework,是模型運算與硬體最佳化的底層。
MLX-LM負責載入、量化、fine-tune 與 serving 語言模型,讓開發者不用直接處理底層張量細節。
MLX-LM Server提供 OpenAI-compatible HTTP server,讓 OpenCode、Xcode、curl 或其他 agent 可以直接接上。
Agent layerOpenCode、Xcode agentic coding、或其他工具透過相同 endpoint 跑 tool calling loop。

重點 3:效能瓶頸不是單次回覆,而是 agent loop 的吞吐

agentic workload 會反覆處理長 context:讀檔、讀 diff、看 build error、回寫 code、再 build。影片指出三個挑戰:大量 context、多個 subagent / concurrent requests,以及單機記憶體放不下的大模型。

01
M5 Neural Accelerators 加速 prompt processing
影片把長 context 處理列為第一個瓶頸,並強調 Neural Accelerators 能提升 prompt processing speed。
02
Continuous batching 讓 subagents 不排隊
當多個 subagent 同時送 request,server 可把它們合併服務,避免每個請求等上一個完整結束。
03
Distributed inference 用多台 Mac 撐大模型
影片提到 DeepSeek 1.6T 參數模型需要超過 800GB 記憶體;MLX 可把模型 shard 到多台 Mac,並從 macOS 26.2 起支援 Thunderbolt RDMA。

風險與導入注意事項

本機不等於無權限風險agent 可讀寫檔案與執行命令;需要明確的 sandbox、approval、repo 範圍與 secret policy。
小模型可能不適合高風險自動修改先用 summary、lint fix、測試產生等低風險任務驗證,再放大到跨模組改動。
工具呼叫仍可能碰網路影片 PR demo 中模型本機跑,但 git commands 會連外;這類邊界要在團隊 policy 中寫清楚。
分散式推論增加操作複雜度多機 hostfile、連線方式、模型 sharding 與效能測試都需要進 CI / lab setup,不是開箱即穩。

對開發團隊的實作啟發

01
把本機 agent 先定位成開發輔助,而非 autonomous committer
讓它負責讀 log、生成 patch、修小 bug,再由人 review 與跑測試。
02
統一 OpenAI-compatible endpoint 抽象
同一套 agent config 可在 cloud model、本機 MLX server 與 Xcode locally hosted provider 間切換。
03
把 latency、throughput、修錯成功率一起量
本機模型的價值不只成本,也包含資料邊界;但導入仍要用實際任務量測品質與等待時間。

來源

主要來源為 Apple Developer 官方影片頁、官方 transcript、章節摘要與 sample code;YouTube 影片頁用於 iframe 與發布 metadata。官方頁:Run local agentic AI on the Mac using MLX - WWDC26。YouTube:WWDC26: Run local agentic AI on the Mac using MLX | Apple。

TL;DR