Sessions
session.set({ model })
本地 SDK Session 如何显式绑定默认模型实例
session.set({ model })
session.set({ model }) 是本地 SDK 场景里显式绑定模型实例的方式之一。
await session.set({
model: openai.responses("gpt-5"),
});什么时候需要它
适用于这些场景:
- 你在纯 SDK 嵌入模式下使用
@downcity/agent - 你没有在
new Agent({ model })里提供默认模型 - 你想只覆写某一个 session 的模型
什么时候不一定需要它
如果你已经这样写了:
const agent = new Agent({
id: "repo-helper",
path: "/path/to/project",
model: openai.responses("gpt-5"),
});那么新建 session 时会自动应用这个默认模型,通常不需要再额外 set 一次。
为什么会这样设计
因为本地 SDK 更像一个嵌入式执行壳:
- agent 负责路径、工具、plugin、会话落盘
- 具体用哪个运行中的模型实例,由调用方决定
这让本地 SDK 更灵活,但也把“模型是否准备好”的责任明确交给了调用方。
如果不设置会怎样
如果本地 session 既没有:
new Agent({ model })
也没有:
session.set({ model })
那么执行时会报错,因为 session 没有默认模型。
远程 session 呢
远程 session 当前不支持直接这样设置模型。
Downcity Agent 项目呢
如果你是在正常的 Downcity Agent 项目里工作,模型通常应该来自:
downcity.json.execution.modelId- 已连接的
City AIService
这时不应把 session.set({ model }) 当成默认用法。