🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(agents): handle Devin ACP thinking model variants (#19954)
AmAzing-378703e1b3c4
diff --git a/packages/heterogeneous-agents/src/spawn/devinAcpSession.test.ts b/packages/heterogeneous-agents/src/spawn/devinAcpSession.test.tsindex acbf2294f89..fe0631321b7 100644--- a/packages/heterogeneous-agents/src/spawn/devinAcpSession.test.ts+++ b/packages/heterogeneous-agents/src/spawn/devinAcpSession.test.ts@@ -31,10 +31,16 @@ interface RpcMessage {}const createAcpProcess = ({+ configOptions,+ configOptionsByModel,+ configUpdateOnPrompt,initializeResult,loadError,permissionRequest = false,}: {+ configOptions?: Record<string, unknown>[];+ configOptionsByModel?: Record<string, Record<string, unknown>[]>;+ configUpdateOnPrompt?: Record<string, unknown>[];initializeResult?: Record<string, unknown>;loadError?: { code: number; data?: unknown; message: string };permissionRequest?: boolean;@@ -85,7 +91,7 @@ const createAcpProcess = ({send({id: message.id,result: {- configOptions: [+ configOptions: configOptions ?? [{category: 'model',currentValue: currentModel,@@ -105,18 +111,25 @@ const createAcpProcess = ({}case 'session/load': {send(- loadError ? { error: loadError, id: message.id } : { id: message.id, result: {} },+ loadError+ ? { error: loadError, id: message.id }+ : { id: message.id, result: { configOptions } },);return;}case 'session/set_config_option': {const params = message.params as { configId?: string; value?: string } | undefined;+ if (params?.configId === 'model' && params.value) {+ configOptions = configOptionsByModel?.[params.value] ?? configOptions;+ }+ const config = configOptions?.find(({ id }) => id === params?.configId);+ if (config) config.currentValue = params?.value;if (params?.configId === 'mode' && params.value) currentMode = params.value;if (params?.configId === 'model' && params.value) currentModel = params.value;send({id: message.id,result: {- configOptions: [+ configOptions: configOptions ?? [{category: 'mode',currentValue: currentMode,@@ -136,6 +149,17 @@ const createAcpProcess = ({}case 'session/prompt': {promptRequest = message;+ if (configUpdateOnPrompt) {+ send({+ method: 'session/update',+ params: {+ update: {+ configOptions: configUpdateOnPrompt,+ sessionUpdate: 'config_option_update',+ },+ },+ });+ }send({method: 'session/update',params: {@@ -615,4 +639,117 @@ describe('DevinAcpSession', () => {});expect(options.onModel).toHaveBeenCalledWith('glm-5-2');});++ it.each([+ ['swe-2-high', 'max', 'swe-2-max', undefined, []],+ ['claude-opus-5-5-medium', 'max', 'claude-opus-5-5-max', undefined, []],+ ['swe-2-high', 'max', 'swe-2-high', undefined, [['thought_level', 'high']]],+ ['swe-2-high', 'high', 'swe-2-max', 'saved-session', [['thought_level', 'max']]],+ [+ 'swe-2-high',+ 'high',+ 'claude-opus-5-5-max',+ 'saved-session',+ [+ ['model', 'claude-opus-5-5-medium'],+ ['thought_level', 'max'],+ ],+ ],+ ] as const)(+ 'preserves the requested variant %s/%s → %s (resume: %s)',+ async (currentModel, thoughtLevel, initialModel, resumeSessionId, expectedChanges) => {+ // Devin 3000.11.3 advertises a family representative in `model` even+ // when --model has already selected a different thinking variant.+ const fake = createAcpProcess({+ configOptions: [+ {+ currentValue: currentModel,+ id: 'model',+ options: [+ { name: 'SWE-2', value: 'swe-2-high' },+ { name: 'Claude Opus 5.5', value: 'claude-opus-5-5-medium' },+ ],+ type: 'select',+ },+ {+ currentValue: thoughtLevel,+ id: 'thought_level',+ options: ['medium', 'high', 'max'].map((value) => ({ name: value, value })),+ type: 'select',+ },+ ],+ });+ spawnMock.mockReturnValue(fake.child);+ vi.spyOn(process, 'kill').mockImplementation(() => true);+ const options = createSessionOptions({ initialModel, resumeSessionId });++ await new DevinAcpSession(options).run();++ expect(+ fake.requests+ .filter(({ method }) => method === 'session/set_config_option')+ .map(({ params }) => [params?.configId, params?.value]),+ ).toEqual(expectedChanges);+ expect(options.onModel).toHaveBeenLastCalledWith(initialModel);+ expect(fake.requests.at(-1)?.method).toBe('session/prompt');+ },+ );++ it('validates thinking against the new family and tracks later config updates', async () => {+ const modelConfig = {+ currentValue: 'swe-2-high',+ id: 'model',+ options: [{ value: 'swe-2-high' }, { value: 'claude-opus-5-5-medium' }],+ };+ const targetConfig = [+ { ...modelConfig, currentValue: 'claude-opus-5-5-medium' },+ { currentValue: 'medium', id: 'thought_level', options: [{ value: 'low' }] },+ ];+ const fake = createAcpProcess({+ configOptions: [+ modelConfig,+ { currentValue: 'high', id: 'thought_level', options: [{ value: 'high' }] },+ ],+ configOptionsByModel: { 'claude-opus-5-5-medium': targetConfig },+ configUpdateOnPrompt: [+ { ...modelConfig, currentValue: 'claude-opus-5-5-medium' },+ { currentValue: 'max', id: 'thought_level', options: [{ value: 'max' }] },+ ],+ });+ spawnMock.mockReturnValue(fake.child);+ vi.spyOn(process, 'kill').mockImplementation(() => true);+ const options = createSessionOptions({ initialModel: 'claude-opus-5-5-low' });++ await new DevinAcpSession(options).run();++ expect(options.onModel).toHaveBeenNthCalledWith(1, 'claude-opus-5-5-low');+ expect(options.onModel).toHaveBeenLastCalledWith('claude-opus-5-5-max');+ expect(targetConfig[1].currentValue).toBe('low');+ });++ it.each([+ ['unknown-max', [{ value: 'max' }]],+ ['swe-2-max', [{ value: 'medium' }]],+ ['swe-2-max', undefined],+ ['fusion-opus-max-sidekick-swe-2-high', [{ value: 'max' }]],+ ])('rejects unavailable variants without sending a prompt: %s', async (initialModel, levels) => {+ const fake = createAcpProcess({+ configOptions: [+ {+ currentValue: 'swe-2-high',+ id: 'model',+ options: [{ value: 'swe-2-high' }, { value: 'fusion-opus-medium-sidekick-swe-2-high' }],+ },+ ...(levels ? [{ currentValue: 'high', id: 'thought_level', options: levels }] : []),+ ],+ });+ spawnMock.mockReturnValue(fake.child);+ vi.spyOn(process, 'kill').mockImplementation(() => true);++ await expect(new DevinAcpSession(createSessionOptions({ initialModel })).run()).rejects.toThrow(+ /Devin ACP (model|thinking level) is unavailable/,+ );++ expect(fake.requests.some(({ method }) => method === 'session/prompt')).toBe(false);+ });});diff --git a/packages/heterogeneous-agents/src/spawn/devinAcpSession.ts b/packages/heterogeneous-agents/src/spawn/devinAcpSession.tsindex 79062ecc235..c01865c75b1 100644--- a/packages/heterogeneous-agents/src/spawn/devinAcpSession.ts+++ b/packages/heterogeneous-agents/src/spawn/devinAcpSession.ts@@ -16,6 +16,19 @@ import { buildTraeAcpPrompt, parseTraeAcpModelCatalog } from './traeAcpSession';const TRANSPORT = 'devin-acp' as const;+// Devin's CLI exposes thinking variants, while ACP exposes one representative+// model per family plus `thought_level`. Fusion IDs also contain a sidekick's+// effort, so they must not be interpreted as a single-model thinking variant.+const splitThinkingModel = (model: string) => {+ const match = /^(?!fusion-)(.+)-(none|minimal|low|medium|high|xhigh|max)$/i.exec(model);+ return match ? { family: match[1], thoughtLevel: match[2].toLowerCase() } : undefined;+};++const getThinkingConfig = (configOptions: unknown) =>+ Array.isArray(configOptions)+ ? configOptions.filter(isRecord).find((option) => option.id === 'thought_level')+ : undefined;+export type DevinAcpTextPromptBlock = TraeAcpTextPromptBlock;export type DevinAcpImagePromptBlock = TraeAcpImagePromptBlock;export type DevinAcpPromptBlock = TraeAcpPromptBlock;@@ -264,7 +277,12 @@ export class DevinAcpSession extends AcpAgentSession<}private resolveCurrentModel(configOptions: unknown): string | undefined {- return parseTraeAcpModelCatalog({ configOptions })?.currentModelId;+ const model = parseTraeAcpModelCatalog({ configOptions })?.currentModelId;+ const thinkingModel = model ? splitThinkingModel(model) : undefined;+ const thoughtLevel = getThinkingConfig(configOptions)?.currentValue;+ return thinkingModel && typeof thoughtLevel === 'string'+ ? `${thinkingModel.family}-${thoughtLevel}`+ : model;}private async applyInitialModel(@@ -289,18 +307,70 @@ export class DevinAcpSession extends AcpAgentSession<return this.setModelOption(sessionId, requestedModel);}- const selected = catalog.models.find((model) =>+ const requestedThinking = splitThinkingModel(requestedModel);+ const exactMatch = catalog.models.find((model) =>[model.id, model.label].some((candidate) =>typeof candidate === 'string' &&this.normalizeModelId(candidate) === this.normalizeModelId(requestedModel),),);+ const selected =+ exactMatch ??+ (requestedThinking &&+ catalog.models.find((model) => {+ const thinkingModel = splitThinkingModel(model.id);+ return (+ thinkingModel &&+ this.normalizeModelId(thinkingModel.family) ===+ this.normalizeModelId(requestedThinking.family)+ );+ }));if (!selected) {throw new Error(`Devin ACP model is unavailable: ${requestedModel}`);}+ const selectedThinking = splitThinkingModel(selected.id);+ if (requestedThinking && selectedThinking) {+ // Switching families can change the supported thinking levels. Validate+ // against the response for the selected family, not the previous one.+ let result =+ catalog.currentModelId === selected.id+ ? sessionResult+ : await this.client.request<DevinAcpSetConfigOptionResult>('session/set_config_option', {+ configId: 'model',+ sessionId,+ value: selected.id,+ });+ const thinking = getThinkingConfig(result.configOptions);+ if (thinking) {+ if (+ !Array.isArray(thinking.options) ||+ !thinking.options.some(+ (option: unknown) =>+ isRecord(option) && option.value === requestedThinking.thoughtLevel,+ )+ ) {+ throw new Error(`Devin ACP thinking level is unavailable: ${requestedModel}`);+ }+ if (thinking.currentValue !== requestedThinking.thoughtLevel) {+ result = await this.client.request<DevinAcpSetConfigOptionResult>(+ 'session/set_config_option',+ {+ configId: thinking.id,+ sessionId,+ value: requestedThinking.thoughtLevel,+ },+ );+ }+ return this.resolveCurrentModel(result.configOptions) ?? requestedModel;+ }+ // Older Devin versions may advertise each variant as a model directly.+ if (exactMatch) return this.resolveCurrentModel(result.configOptions) ?? selected.id;+ throw new Error(`Devin ACP model is unavailable: ${requestedModel}`);+ }+return this.setModelOption(sessionId, selected.id);}