Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(pi): 子代理卡片显示子任务实际模型而不是父会话模型

Zhang Yunjin0034b45a9d4c
diff --git a/packages/maker-core/src/agents/pi/__tests__/cindySubagentForeground.test.ts b/packages/maker-core/src/agents/pi/__tests__/cindySubagentForeground.test.ts
index 486a5249f7..e5fdff0322 100644
--- a/packages/maker-core/src/agents/pi/__tests__/cindySubagentForeground.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/cindySubagentForeground.test.ts
@@ -198,11 +198,12 @@ describe('Cindy PI Subagent foreground durable path', () => {
await extension({ registerTool: (tool) => Object.assign(registered, tool), appendEntry: vi.fn() });
expect(registered.execute).toBeTypeOf('function');
const input = hostInput(f);
+ const progressFrames: Array<{ details?: { model?: unknown } }> = [];
const result = await registered.execute!(
'tool-foreground',
{ agent: 'worker', task: 'write the fixture', model: 'claude-fable-5' },
new AbortController().signal,
- () => undefined,
+ (frame) => { progressFrames.push(frame as { details?: { model?: unknown } }); },
{ ui: { input }, sessionManager: { getBranch: () => [] } },
);
expect(input).toHaveBeenCalledWith('cindy:permission', expect.stringContaining('write'));
@@ -224,6 +225,14 @@ describe('Cindy PI Subagent foreground durable path', () => {
expect(configText).not.toContain('parent-session-token-1234567890abcdef');
expect(configText).not.toContain(expectedRouteToken);
expect(await readFile(f.runtimeFile, 'utf8')).not.toContain('Token');
+ // 前台卡片的模型 chip 只由这些进度帧提供:报父会话模型会让委派给别的模型的子代理
+ // 在卡片上显示成父模型(panel 读状态文件,两边同屏矛盾)。
+ const progressModels = progressFrames
+ .map((frame) => frame.details?.model)
+ .filter((model): model is string => typeof model === 'string');
+ expect(progressModels.length).toBeGreaterThan(0);
+ expect(progressModels).toContain('claude-fable-5');
+ expect(progressModels).not.toContain('fixture-model');
} finally {
for (const key of Object.keys(process.env)) if (!(key in previous)) delete process.env[key];
Object.assign(process.env, previous);
diff --git a/packages/maker-core/src/agents/pi/cindy-subagent-source.ts b/packages/maker-core/src/agents/pi/cindy-subagent-source.ts
index 6de562e330..dc86700f2b 100644
--- a/packages/maker-core/src/agents/pi/cindy-subagent-source.ts
+++ b/packages/maker-core/src/agents/pi/cindy-subagent-source.ts
@@ -376,6 +376,29 @@ function modelProviderMap(runtime) {
return map;
}
+/**
+ * 子任务实际跑的模型(= durable config 里的 displayModel)。与宿主读状态文件时同一
+ * 口径:显式指定的模型 > 解析出的路由模型 > 继承父会话模型。
+ */
+function taskDisplayModel(task, runtime) {
+ return task.model || task.routeModel || runtime.model;
+}
+
+/**
+ * 卡片 chip 的模型:批次里所有子任务跑同一个模型才显示,不一致就不猜 —— 与宿主侧读
+ * 状态文件时的 model:null(多模型批次)同义。
+ */
+function singleTaskDisplayModel(tasks, runtime) {
+ let found;
+ for (const task of tasks) {
+ const model = taskDisplayModel(task, runtime);
+ if (!model) continue;
+ if (found !== undefined && found !== model) return undefined;
+ found = model;
+ }
+ return found;
+}
+
function resolveTaskModelRoutes(tasks, runtime) {
const availableModels = Object.keys(runtime.modelRoutes || {}).sort();
const availableModelHint = availableModels.length > 0
@@ -1042,7 +1065,7 @@ async function launchDurableRun(binary, tasks, runtime, taskId, mode, context, d
profilePrompt: task.profilePrompt,
provider: task.routeProvider || runtime.provider,
model: task.routeModel || runtime.model,
- displayModel: task.model || task.routeModel || runtime.model,
+ displayModel: taskDisplayModel(task, runtime),
sourceProviderId: task.routeSourceProviderId,
proxySessionAuth: task.routeProxySessionAuth === true,
thinking: task.thinking || undefined,
@@ -1618,7 +1641,10 @@ export default async function cindySubagent(pi: any) {
};
details[MARKER] = 1;
if (summary) details.summary = summary;
- if (runtime.model) details.model = runtime.model;
+ // 前台(非 async)卡片的 model 只由这些进度帧喂,所以这里必须报子任务实际模型。
+ // 报 runtime.model 会让指定了别的模型的子代理在卡片上显示成父会话模型。
+ const cardModel = singleTaskDisplayModel(tasks, runtime);
+ if (cardModel) details.model = cardModel;
try {
onUpdate({ content: [{ type: 'text', text: status === 'running' ? 'Running subagent…' : status }], details: details });
} catch (err) {