Skip to content
1 change: 1 addition & 0 deletions docs/users/integration-jetbrains.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- **Agent Client Protocol**: Full support for ACP enabling advanced IDE interactions
- **Symbol management**: #-mention files to add them to the conversation context
- **Conversation history**: Access to past conversations within the IDE
- **Reasoning effort**: Choose Default, Low, Medium, High, Extra high, or Max from the agent's session options; each provider maps or clamps the requested tier for the active model

### Requirements

Expand Down
69 changes: 68 additions & 1 deletion integration-tests/cli/acp-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ function setupAcpTest(
}
});

it('supports session/set_config_option for mode and model', async () => {
it('supports session/set_config_option for mode, model, and reasoning effort', async () => {
const rig = new TestRig();
// Inject a deterministic openai provider model so `availableModels` always
// contains a settable openai entry. The previous version relied on the
Expand Down Expand Up @@ -525,9 +525,26 @@ function setupAcpTest(
models: {
availableModels: Array<{ modelId: string }>;
};
configOptions: Array<{
id: string;
category?: string;
currentValue: string;
options: Array<{ value: string; name: string }>;
}>;
};
expect(newSession.sessionId).toBeTruthy();

const initialReasoningOption = newSession.configOptions.find(
(opt) => opt.id === 'reasoning_effort',
);
expect(initialReasoningOption).toMatchObject({
category: 'thought_level',
currentValue: 'default',
});
expect(
initialReasoningOption?.options.map((option) => option.value),
).toEqual(['default', 'low', 'medium', 'high', 'xhigh', 'max']);

// Test: Set mode using set_config_option
const setModeResult = (await sendRequest('session/set_config_option', {
sessionId: newSession.sessionId,
Expand Down Expand Up @@ -590,6 +607,56 @@ function setupAcpTest(
);
expect(updatedModelOption).toBeDefined();
expect(updatedModelOption!.currentValue).toBe(openaiModel!.modelId);
expect(
setModelResult.configOptions.find(
(opt) => opt.id === 'reasoning_effort',
)?.currentValue,
).toBe('default');

const setReasoningResult = (await sendRequest(
'session/set_config_option',
{
sessionId: newSession.sessionId,
configId: 'reasoning_effort',
value: 'xhigh',
},
)) as {
configOptions: Array<{ id: string; currentValue: string }>;
};
expect(
setReasoningResult.configOptions.find(
(opt) => opt.id === 'reasoning_effort',
)?.currentValue,
).toBe('xhigh');

const resetReasoningResult = (await sendRequest(
'session/set_config_option',
{
sessionId: newSession.sessionId,
configId: 'reasoning_effort',
value: 'default',
},
)) as {
configOptions: Array<{ id: string; currentValue: string }>;
};
expect(
resetReasoningResult.configOptions.find(
(opt) => opt.id === 'reasoning_effort',
)?.currentValue,
).toBe('default');

await expect(
sendRequest('session/set_config_option', {
sessionId: newSession.sessionId,
configId: 'reasoning_effort',
value: 'ultra',
}),
).rejects.toMatchObject({
response: {
code: -32602,
message: 'Invalid params: Unknown reasoning effort: ultra',
},
});
} catch (e) {
if (stderr.length) {
console.error('Agent stderr:', stderr.join(''));
Expand Down
113 changes: 113 additions & 0 deletions packages/cli/src/acp-integration/acpAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ vi.mock('@qwen-code/qwen-code-core', async (importOriginal) => ({
})),
APPROVAL_MODE_INFO: {},
APPROVAL_MODES: [],
applyReasoningEffort: (
config: {
setReasoningEffort(effort: string | undefined): void;
getReasoningEffort(): string | undefined;
},
effort: string | undefined,
) => {
config.setReasoningEffort(effort);
return config.getReasoningEffort() === effort;
},
REASONING_EFFORT_TIERS: ['low', 'medium', 'high', 'xhigh', 'max'],
Comment thread
zjunothing marked this conversation as resolved.
Resolved
ApprovalMode: { YOLO: 'yolo' },
isGatedMcpScope: (scope: unknown) =>
scope === 'project' || scope === 'workspace',
Expand Down Expand Up @@ -1854,6 +1865,7 @@ describe('QwenAgent MCP SSE/HTTP support', () => {
type AgentLike = {
initialize: (args: Record<string, unknown>) => Promise<unknown>;
newSession: (args: Record<string, unknown>) => Promise<unknown>;
setSessionConfigOption: (args: Record<string, unknown>) => Promise<unknown>;
beginManagedShutdown: () => {
configs: Config[];
writerShutdown: Promise<void>;
Expand Down Expand Up @@ -3198,6 +3210,8 @@ describe('QwenAgent MCP SSE/HTTP support', () => {
getAvailableModels: vi.fn().mockReturnValue([]),
getModes: vi.fn().mockReturnValue([]),
getApprovalMode: vi.fn().mockReturnValue('default'),
getReasoningEffort: vi.fn().mockReturnValue(undefined),
setReasoningEffort: vi.fn(),
getSessionId: vi.fn().mockReturnValue('test-session-id'),
getAuthType: vi.fn().mockReturnValue('api-key'),
getAllConfiguredModels: vi.fn().mockReturnValue([]),
Expand Down Expand Up @@ -6212,6 +6226,105 @@ describe('QwenAgent MCP SSE/HTTP support', () => {
await agentPromise;
});

it('exposes and applies the ACP reasoning effort selector', async () => {
const sessionId = 'reasoning-effort-session';
const innerConfig = await setupSessionMocks(sessionId);
let currentEffort: string | undefined;
innerConfig.getReasoningEffort = vi.fn(() => currentEffort);
innerConfig.setReasoningEffort = vi.fn((effort: string | undefined) => {
currentEffort = effort;
});

const { agent, agentPromise } = await bootAcpAgent();
try {
const session = (await agent.newSession({
cwd: '/tmp',
mcpServers: [],
})) as {
configOptions: Array<{
id: string;
category?: string;
currentValue: string;
options: Array<{
value: string;
name: string;
description: string;
}>;
}>;
};

expect(
session.configOptions.find(
(option) => option.id === 'reasoning_effort',
),
).toMatchObject({
category: 'thought_level',
currentValue: 'default',
options: [
{ value: 'default', name: 'Default' },
{ value: 'low', name: 'Low', description: expect.any(String) },
{ value: 'medium', name: 'Medium', description: expect.any(String) },
{ value: 'high', name: 'High', description: expect.any(String) },
{
value: 'xhigh',
name: 'Extra high',
description: expect.any(String),
},
{ value: 'max', name: 'Max', description: expect.any(String) },
],
});

const selected = (await agent.setSessionConfigOption({
sessionId,
configId: 'reasoning_effort',
value: 'xhigh',
})) as { configOptions: typeof session.configOptions };
expect(innerConfig.setReasoningEffort).toHaveBeenCalledWith('xhigh');
expect(
selected.configOptions.find(
(option) => option.id === 'reasoning_effort',
)?.currentValue,
).toBe('xhigh');

const reset = (await agent.setSessionConfigOption({
sessionId,
configId: 'reasoning_effort',
value: 'default',
})) as { configOptions: typeof session.configOptions };
expect(innerConfig.setReasoningEffort).toHaveBeenLastCalledWith(
undefined,
);
expect(
reset.configOptions.find((option) => option.id === 'reasoning_effort')
?.currentValue,
).toBe('default');

await expect(
agent.setSessionConfigOption({
sessionId,
configId: 'reasoning_effort',
value: 'ultra',
}),
).rejects.toThrow('Unknown reasoning effort: ultra');
Comment thread
zjunothing marked this conversation as resolved.
Resolved
expect(innerConfig.setReasoningEffort).toHaveBeenCalledTimes(2);

innerConfig.setReasoningEffort.mockImplementation(() => {});
await expect(
agent.setSessionConfigOption({
sessionId,
configId: 'reasoning_effort',
value: 'xhigh',
}),
).rejects.toThrow(
'Reasoning effort cannot be applied while thinking is disabled',
);
expect(innerConfig.setReasoningEffort).toHaveBeenCalledTimes(3);
} finally {
mockConnectionState.resolve();
await agentPromise;
}
});

it.each([
{
description: 'hide discontinued qwen-oauth for other auth types',
Expand Down
55 changes: 54 additions & 1 deletion packages/cli/src/acp-integration/acpAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ import {
normalizeSnapshotPayload,
startEventLoopLagMonitor,
refreshMemoryInstruction,
applyReasoningEffort,
REASONING_EFFORT_TIERS,
extractDaemonTraceContext,
withDaemonSpan,
type AgentParams,
Expand All @@ -109,6 +111,7 @@ import {
type ProviderConfig,
type ProviderModelConfig,
type ProviderSetupInputs,
type ReasoningEffort,
type ResumedSessionData,
type SendSdkMcpMessage,
type SessionArtifactEventRecordPayload,
Expand Down Expand Up @@ -363,6 +366,14 @@ const POSIX_TMP_LOCAL_READ_ROOT = '/tmp';
const BTW_CHILD_TIMEOUT_MS = 55_000;
const MCP_OAUTH_START_TIMEOUT_MS = 30_000;
const SESSION_DRAIN_TIMEOUT_MS = 30_000;
const ACP_REASONING_EFFORT_DEFAULT = 'default';
const ACP_REASONING_EFFORT_NAMES: Record<ReasoningEffort, string> = {
low: 'Low',
medium: 'Medium',
high: 'High',
xhigh: 'Extra high',
max: 'Max',
};

// Must be less than WORKSPACE_MEMORY_REMEMBER_TIMEOUT_MS (300s) in bridge.ts.
const WORKSPACE_MEMORY_REMEMBER_CHILD_TIMEOUT_MS = 295_000;
Expand Down Expand Up @@ -5173,6 +5184,25 @@ class QwenAgent implements Agent {
);
break;
}
case 'reasoning_effort': {
const effort =
value === ACP_REASONING_EFFORT_DEFAULT
? undefined
: REASONING_EFFORT_TIERS.find((tier) => tier === value);
if (value !== ACP_REASONING_EFFORT_DEFAULT && effort === undefined) {
throw RequestError.invalidParams(
undefined,
`Unknown reasoning effort: ${value}`,
);
}
if (!applyReasoningEffort(session.getConfig(), effort)) {
throw RequestError.invalidParams(
undefined,
'Reasoning effort cannot be applied while thinking is disabled',
);
}
break;
}
default:
throw RequestError.invalidParams(
undefined,
Expand Down Expand Up @@ -11973,7 +12003,30 @@ class QwenAgent implements Agent {
options: configModelOptions,
};

return [modeConfigOption, modelConfigOption];
const reasoningEffortConfigOption: SessionConfigOption = {
id: 'reasoning_effort',
name: 'Reasoning effort',
description: 'How hard reasoning-capable models should think',
category: 'thought_level',
type: 'select' as const,
currentValue:
config.getReasoningEffort?.() ?? ACP_REASONING_EFFORT_DEFAULT,
options: [
{
value: ACP_REASONING_EFFORT_DEFAULT,
name: 'Default',
description: 'Use the model or provider default',
},
...REASONING_EFFORT_TIERS.map((effort) => ({
value: effort,
name: ACP_REASONING_EFFORT_NAMES[effort],
description:
'Providers map or clamp the requested tier for the active model',
})),
Comment thread
zjunothing marked this conversation as resolved.
Resolved
],
};

return [modeConfigOption, modelConfigOption, reasoningEffortConfigOption];
Comment thread
zjunothing marked this conversation as resolved.
Resolved
}

private buildSelectableModelOptions(config: Config) {
Expand Down
11 changes: 11 additions & 0 deletions packages/cli/src/acp-integration/acpAgent.worktree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ vi.mock('@qwen-code/qwen-code-core', () => ({
})),
APPROVAL_MODE_INFO: {},
APPROVAL_MODES: [],
applyReasoningEffort: (
config: {
setReasoningEffort(effort: string | undefined): void;
getReasoningEffort(): string | undefined;
},
effort: string | undefined,
) => {
config.setReasoningEffort(effort);
return config.getReasoningEffort() === effort;
},
REASONING_EFFORT_TIERS: ['low', 'medium', 'high', 'xhigh', 'max'],
DEFAULT_STOP_HOOK_BLOCK_CAP: 8,
DEFAULT_MAX_SUBAGENT_DEPTH: 5,
DEFAULT_MAX_TOOL_CALLS_PER_TURN: 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
createDebugLogger,
MCPServerConfig,
AuthProviderType,
applyReasoningEffort,
normalizeReasoningEffort,
loadUsageDashboard,
type MCPOAuthConfig,
Expand Down Expand Up @@ -176,16 +177,14 @@ export class SystemController extends BaseController {
const normalized = normalizeReasoningEffort(payload.effort);
if (normalized) {
try {
this.context.config.setReasoningEffort(normalized);

if (this.context.config.getReasoningEffort() !== normalized) {
debugLogger.warn(
`[SystemController] Effort '${normalized}' was not applied (thinking may be disabled)`,
);
} else {
if (applyReasoningEffort(this.context.config, normalized)) {
debugLogger.info(
`[SystemController] Set reasoning effort to: ${normalized}`,
);
} else {
debugLogger.warn(
`[SystemController] Effort '${normalized}' was not applied (thinking may be disabled)`,
);
}
} catch (error) {
debugLogger.error(
Expand Down Expand Up @@ -533,9 +532,7 @@ export class SystemController extends BaseController {
}

try {
this.context.config.setReasoningEffort(normalized);

const applied = this.context.config.getReasoningEffort() === normalized;
const applied = applyReasoningEffort(this.context.config, normalized);

debugLogger.info(
`[SystemController] Reasoning effort set to: ${normalized} (applied: ${applied})`,
Expand Down
Loading
Loading