把 Foundation Models session 設計成 可切換、可裁切、可評估的 agent workflow
這場 session 用一個 craft app 拆解新的 DynamicProfile、DynamicInstructions 與 Foundation Models framework utilities:同一個 LanguageModelSession 可以在不同任務階段切換模型、工具、指令與 transcript 策略。
Apple 給 agentic app 的不是單一「代理人」抽象,而是一組低階控制點:profile 決定模型與工具,history transform 決定上下文,tool calling mode 決定何時必須行動。
這支影片在拆 agentic app 的四個工程問題
一個 session,按階段換 profile
craft app 先 brainstorm、再 planning、再 reviewing。每個階段可以有不同 instructions、tools、temperature、reasoning level 與模型來源。
transcript 不是只能一路 append
不同模型有不同 context window 與隱私特性。historyTransform 可在 prompt 前裁切、摘要或移除 tool calls,且不永久改掉 session transcript。
handoff 與 consultation 要分開看
baton-pass 讓下一個 profile 接手完整歷史並產生最終回答;phone-a-friend 則建立短命 child session,回傳 tool output 後由 parent 收尾。
required tool calling 必須有出口
allowed、disallowed、required 可以控制工具呼叫行為;若要求模型只能 call tools,就要設計 exit condition,否則會變成無限工具迴圈。
導入 DynamicProfile 的實作順序
先把 app 體驗拆成 mode
不要先想「一個 agent 解所有事」。把使用者旅程切成 brainstorming、planning、reviewing 這類 mode,讓每段有清楚目標。
用 DynamicInstructions 封裝可重用知識
將 domain instructions 與 tools 包成元件,例如 origami expert。需要時再條件式加入 profile,避免每個 prompt 都塞滿所有背景。
在 DynamicProfile 裡設定模型與 generation options
創意 brainstorm 可用 PCC 與較高 temperature;複雜 planning 可用 deep reasoning;低成本 reviewing 可回到 on-device system model。
用 history transform 管理跨模型上下文
切到較小或較私密性不同的模型時,先移除無關 entries、tool calls 或敏感內容;同時保留原始 transcript,避免後續階段失去上下文。
用 evaluation 驗證 context engineering
重寫歷史、加入工具或改 instructions 都可能影響 KV cache、latency 與 accuracy。影片明確提醒要用 Evaluations framework 量化效果。
實務啟發:agent 架構要先設計「誰看得到什麼」
baton-pass 與 phone-a-friend 最大差異不是命名,而是 transcript visibility 與 final answer ownership。前者讓接棒 profile 看完整歷史並完成回答;後者把子任務隔離在 child session,parent 只收工具輸出。
LanguageModelSession.DynamicProfile、DynamicInstructions、Foundation Models framework utilities、historyTransform、custom modifiers、toolCallingMode、transcriptErrorHandlingPolicy。風險與測試清單
第一,required tool calling 要有終止條件,例如狀態變數或 final answer tool。第二,修改 transcript 會影響 KV cache,可能拉高 time-to-first-token。第三,新增工具或更動歷史可能讓模型困惑,出現「以前不用工具,現在也不用」的錯誤學習。
建議把不同 profile、不同 history transform、不同 tool calling mode 放進 eval set 比較,不要只靠 demo prompt 判斷。這類 agentic app 的品質通常壞在邊界條件,而不是 happy path。
- 01
DynamicProfile讓同一個 Foundation Models session 可依 app mode 切換模型、工具、instructions 與 generation options。 - 02agent orchestration 要區分 baton-pass 與 phone-a-friend,因為兩者的 transcript isolation 與 final answer ownership 不同。
- 03transcript management 是效能、隱私與準確度問題;改歷史前要量測 KV cache、latency 與 eval 結果。