WWDC26: Run Local Agentic AI on Mac using MLX
演讲者:Angeles,MLX 团队工程师 | 平台:WWDC26 | 工具:MLX LLM Server + 本地模型
核心主张
完全本地运行,无云、无 API key,数据永不离开 Mac。
🏗️ 四层技术栈
| 层级 | 组件 | 职责 |
| L4 | Agent | Xcode Intelligence、Pie Agent 等任意 OpenAI Chat Completion Protocol 框架 |
| L3 | MLX LLM Server | OpenAI 兼容 API,支持 structured tool calling + reasoning models |
| L2 | MLX LLM Library | 加载、运行、量化、微调大语言模型 |
| L1 | MLX Core | Apple Silicon 高效计算底层框架 |
生态:Ollama、LM Studio、vLLM 均基于 MLX 构建
⚡ 三大硬件挑战与解决方案
1️⃣ Prompt Processing(提示词处理)
挑战:Agentic session 含数十万 token,每次工具执行后模型都要重新处理全部上下文
MLX 方案:M5 神经加速器矩阵乘法比 M4 快 4x。MLX 专用 attention kernel 直接转化提速。无需代码修改,MLX 自动选择最优 kernel。
2️⃣ Concurrency(并发)
挑战:Agent spawn 多个子 agent 并行(读文档 / 搜代码 / 写测试同时),多请求同时打到本地模型
MLX 方案:Continuous Batching — 动态分组请求批量处理,新请求可加入进行中 batch,子 agent 不会因排队 stall
3️⃣ Model Size(模型体积)
挑战:单 Mac 内存有限(如 DeepSeek 1.6T 参数需 800GB+ 显存)
MLX 方案:分布式推理 — 多 Mac 通过 Thunderbolt/以太网共享模型。
macOS 26.2 新增 Thunderbolt RDMA(低延迟高带宽),4 节点提速最高 3x
📊 关键数据
🎬 三个 Demo
Demo 1: GitHub PR Summary
Agent 自动抓取 PR、总结变更、标记重点(read & report)
Demo 2: 从空白 Xcode 项目构建 iPad 绘图 App
- 从零创建 SwiftUI 绘图 App,2 分钟完成第一版
- Agent:探索目录 → 制定计划 → 写代码 → 编译 → 自动修复错误
- 迭代修改:添加圆角端点(rounded end caps)
- 全程本地:MLX LLM Server +
xcodebuild 验证
Demo 3: Xcode 内直接集成
- Settings → Intelligence → App Chat Provider → 选择本地托管
- Port 设为 8080,Xcode 即可对话本地模型
- 读取项目文件、理解编译错误、精准修复 bug
- 代码永不离开本机
🚀 安装步骤
# 1. 安装
pip install mlx-lm
# 2. 启动 server
mlx_lm.server --model <model_name>
# 3. Agent 端配置指向
http://localhost:8080/v1
⚖️ 本地 vs 云端对比
✅ 本地 MLX
- ✔ 数据完全本地
- ✔ 无需 API Key
- ✔ 无网络延迟
- ✗ 受 Mac 内存限制
☁️ 云端 API
- ✗ 数据需上传
- ✔ 需要 API Key
- ✗ 受网络延迟影响
- ✔ 可用任意大模型