From 3ecc0e75488cfa3a6c59609a20bb4c3046320bb8 Mon Sep 17 00:00:00 2001 From: Govinda Vashishtha <57435703+govindavashishtha@users.noreply.github.com> Date: Tue, 22 Sep 2026 16:55:28 +0530 Subject: [PATCH 1/2] Make compaction threshold an optional runtime override. Default omits trigger so the runtime derives 80% of the model context window; toggling on writes a 50000-token input_tokens trigger and shows the editable input. Co-authored-by: Cursor --- .changeset/compaction-threshold-toggle.md | 5 + .../atoms/draft/AgentRuntimeConfigFields.tsx | 93 +++++++++++-------- .../atoms/draft/AgentConfigEditors.test.tsx | 88 ++++++++++++++++++ 3 files changed, 148 insertions(+), 38 deletions(-) create mode 100644 .changeset/compaction-threshold-toggle.md diff --git a/.changeset/compaction-threshold-toggle.md b/.changeset/compaction-threshold-toggle.md new file mode 100644 index 000000000..1ff5bafbc --- /dev/null +++ b/.changeset/compaction-threshold-toggle.md @@ -0,0 +1,5 @@ +--- +'@truefoundry/trueforge-ui': patch +--- + +Make the compaction threshold an optional override: off by default (no `trigger`, runtime derives the threshold), and toggling on reveals a number input defaulting to 50000. diff --git a/packages/trueforge-ui/src/atoms/draft/AgentRuntimeConfigFields.tsx b/packages/trueforge-ui/src/atoms/draft/AgentRuntimeConfigFields.tsx index e50fd8cdc..0bf20fc63 100644 --- a/packages/trueforge-ui/src/atoms/draft/AgentRuntimeConfigFields.tsx +++ b/packages/trueforge-ui/src/atoms/draft/AgentRuntimeConfigFields.tsx @@ -1,6 +1,6 @@ 'use client'; -import type { AgentRuntimeConfig } from '../../server/types.js'; +import type { AgentCompactionConfig, AgentRuntimeConfig } from '../../server/types.js'; import { cn } from '../lib/cn.js'; import { auiInputClass } from '../lib/inputClasses.js'; import { Switch } from '../primitives/Switch.js'; @@ -30,6 +30,7 @@ function parsePositiveInteger(raw: string): number | null { } const NO_SANDBOX_PROVIDER_HINT = 'No sandbox provider yet, add one in Settings → Sandbox'; +const DEFAULT_COMPACTION_THRESHOLD_TOKENS = 50_000; type RuntimeSwitchField = { label: string; @@ -50,6 +51,16 @@ export function AgentRuntimeConfigFields({ layout = 'compact', onChange, }: AgentRuntimeConfigFieldsProps) { + const withCompaction = (compaction: AgentCompactionConfig): AgentRuntimeConfig => ({ + ...value, + contextManagement: { + ...value.contextManagement, + compaction, + largeToolResponse: value.contextManagement?.largeToolResponse ?? { enabled: true }, + }, + }); + const applyCompaction = (compaction: AgentCompactionConfig) => onChange(withCompaction(compaction)); + const capabilityFields: RuntimeSwitchField[] = [ { label: 'Dynamic sub-agents', @@ -72,6 +83,7 @@ export function AgentRuntimeConfigFields({ ]; const sandboxEnabled = value.sandbox?.enabled ?? false; const compactionEnabled = value.contextManagement?.compaction?.enabled ?? true; + const thresholdOverrideEnabled = value.contextManagement?.compaction?.trigger != null; const webSearchField: RuntimeSwitchField | null = webSearchAvailable ? { label: 'Web search', @@ -104,16 +116,9 @@ export function AgentRuntimeConfigFields({ }; const compactionField: RuntimeSwitchField = { label: 'Context compaction', - description: 'Summarize older turns as the context window fills.', + description: 'Summarize older turns as context fills. Defaults to 80% of the model context window.', checked: compactionEnabled, - update: enabled => ({ - ...value, - contextManagement: { - ...value.contextManagement, - compaction: { ...value.contextManagement?.compaction, enabled }, - largeToolResponse: value.contextManagement?.largeToolResponse ?? { enabled: true }, - }, - }), + update: enabled => withCompaction({ ...value.contextManagement?.compaction, enabled }), }; const largeToolResponseField: RuntimeSwitchField = { label: 'Large tool response offloading', @@ -131,7 +136,8 @@ export function AgentRuntimeConfigFields({ }), }; const runtimeFields = [sandboxField, fileDownloadsField, compactionField, largeToolResponseField]; - const compactionThreshold = value.contextManagement?.compaction?.trigger?.value ?? 50_000; + const compactionThreshold = + value.contextManagement?.compaction?.trigger?.value ?? DEFAULT_COMPACTION_THRESHOLD_TOKENS; const switchField = ({ field, @@ -215,43 +221,54 @@ export function AgentRuntimeConfigFields({
{switchField({ field: compactionField, className: rowClassName })} - + + applyCompaction( + enabled + ? { + enabled: compactionEnabled, + trigger: { type: 'input_tokens', value: DEFAULT_COMPACTION_THRESHOLD_TOKENS }, + } + : { enabled: compactionEnabled }, + ) + } /> - +
{switchField({ field: largeToolResponseField, className: cn('py-4', rowClassName) })} diff --git a/packages/trueforge-ui/test/atoms/draft/AgentConfigEditors.test.tsx b/packages/trueforge-ui/test/atoms/draft/AgentConfigEditors.test.tsx index 85bc53aff..06c9d5c6a 100644 --- a/packages/trueforge-ui/test/atoms/draft/AgentConfigEditors.test.tsx +++ b/packages/trueforge-ui/test/atoms/draft/AgentConfigEditors.test.tsx @@ -482,6 +482,8 @@ describe('AgentConfigEditors', () => { expect(screen.getByRole('switch', { name: 'File downloads' })).toBeDisabled(); expect(screen.getByRole('switch', { name: 'File downloads' })).toHaveAttribute('aria-checked', 'false'); + expect(screen.getByRole('switch', { name: 'Custom compaction threshold' })).toBeDisabled(); + expect(screen.getByRole('switch', { name: 'Custom compaction threshold' })).toHaveAttribute('aria-checked', 'true'); expect(screen.getByRole('spinbutton', { name: /Compaction threshold tokens/ })).toBeDisabled(); expect(screen.getByRole('spinbutton', { name: /Compaction threshold tokens/ })).toHaveValue(42_000); @@ -501,6 +503,92 @@ describe('AgentConfigEditors', () => { }); }); + it('enables a custom compaction threshold with a 50000-token default', () => { + const onChange = vi.fn(); + render( + + + , + ); + + expect(screen.getByRole('switch', { name: 'Custom compaction threshold' })).toHaveAttribute( + 'aria-checked', + 'false', + ); + expect(screen.queryByRole('spinbutton', { name: /Compaction threshold tokens/ })).not.toBeInTheDocument(); + + fireEvent.click(screen.getByRole('switch', { name: 'Custom compaction threshold' })); + expect(onChange).toHaveBeenCalledWith({ + model: { name: 'openai/gpt' }, + config: { + contextManagement: { + compaction: { + enabled: true, + trigger: { type: 'input_tokens', value: 50_000 }, + }, + largeToolResponse: { enabled: true }, + }, + }, + }); + }); + + it('clears the compaction trigger when the custom threshold is turned off', () => { + const spec: AgentSpec = { + model: { name: 'openai/gpt' }, + config: { + contextManagement: { + compaction: { + enabled: true, + trigger: { type: 'input_tokens', value: 42_000 }, + }, + largeToolResponse: { enabled: true }, + }, + }, + }; + const onChange = vi.fn(); + render( + + + , + ); + + expect(screen.getByRole('spinbutton', { name: /Compaction threshold tokens/ })).toHaveValue(42_000); + + fireEvent.click(screen.getByRole('switch', { name: 'Custom compaction threshold' })); + expect(onChange).toHaveBeenCalledWith({ + ...spec, + config: { + ...spec.config, + contextManagement: { + compaction: { enabled: true }, + largeToolResponse: { enabled: true }, + }, + }, + }); + }); + it('selects the first mounted MCP on open, otherwise the first connector', async () => { const loadMcpTools = vi.fn(async (connectorId: string) => [ { id: `${connectorId}.tool`, name: `${connectorId}.tool` }, From f55d7349d21855239d04dec8c0e5316261b54358 Mon Sep 17 00:00:00 2001 From: Govinda Vashishtha <57435703+govindavashishtha@users.noreply.github.com> Date: Tue, 22 Sep 2026 20:42:57 +0530 Subject: [PATCH 2/2] Refactor compaction threshold handling to use an Auto/Custom selector. The default mode is now Auto, which derives the threshold from the model context window, while Custom allows manual input with a default of 50,000 tokens. Update related tests to reflect these changes. --- .changeset/compaction-threshold-toggle.md | 2 +- .../atoms/draft/AgentRuntimeConfigFields.tsx | 66 +++++++++++-------- .../atoms/draft/AgentConfigEditors.test.tsx | 27 ++++---- 3 files changed, 55 insertions(+), 40 deletions(-) diff --git a/.changeset/compaction-threshold-toggle.md b/.changeset/compaction-threshold-toggle.md index 1ff5bafbc..d5233c97e 100644 --- a/.changeset/compaction-threshold-toggle.md +++ b/.changeset/compaction-threshold-toggle.md @@ -2,4 +2,4 @@ '@truefoundry/trueforge-ui': patch --- -Make the compaction threshold an optional override: off by default (no `trigger`, runtime derives the threshold), and toggling on reveals a number input defaulting to 50000. +Make the compaction threshold an Auto/Custom selector: Auto omits `trigger` (runtime derives ~80% of the model context window); Custom reveals a number input defaulting to 50000. diff --git a/packages/trueforge-ui/src/atoms/draft/AgentRuntimeConfigFields.tsx b/packages/trueforge-ui/src/atoms/draft/AgentRuntimeConfigFields.tsx index 0bf20fc63..647345439 100644 --- a/packages/trueforge-ui/src/atoms/draft/AgentRuntimeConfigFields.tsx +++ b/packages/trueforge-ui/src/atoms/draft/AgentRuntimeConfigFields.tsx @@ -3,6 +3,7 @@ import type { AgentCompactionConfig, AgentRuntimeConfig } from '../../server/types.js'; import { cn } from '../lib/cn.js'; import { auiInputClass } from '../lib/inputClasses.js'; +import { PopoverSelect } from '../primitives/PopoverSelect.js'; import { Switch } from '../primitives/Switch.js'; import { Tooltip } from '../primitives/Tooltip.js'; @@ -32,6 +33,13 @@ function parsePositiveInteger(raw: string): number | null { const NO_SANDBOX_PROVIDER_HINT = 'No sandbox provider yet, add one in Settings → Sandbox'; const DEFAULT_COMPACTION_THRESHOLD_TOKENS = 50_000; +const COMPACTION_THRESHOLD_MODE_OPTIONS = [ + { value: 'auto', label: 'Auto' }, + { value: 'custom', label: 'Custom' }, +] as const; + +type CompactionThresholdMode = (typeof COMPACTION_THRESHOLD_MODE_OPTIONS)[number]['value']; + type RuntimeSwitchField = { label: string; description: string; @@ -83,7 +91,8 @@ export function AgentRuntimeConfigFields({ ]; const sandboxEnabled = value.sandbox?.enabled ?? false; const compactionEnabled = value.contextManagement?.compaction?.enabled ?? true; - const thresholdOverrideEnabled = value.contextManagement?.compaction?.trigger != null; + const thresholdMode: CompactionThresholdMode = + value.contextManagement?.compaction?.trigger != null ? 'custom' : 'auto'; const webSearchField: RuntimeSwitchField | null = webSearchAvailable ? { label: 'Web search', @@ -116,7 +125,7 @@ export function AgentRuntimeConfigFields({ }; const compactionField: RuntimeSwitchField = { label: 'Context compaction', - description: 'Summarize older turns as context fills. Defaults to 80% of the model context window.', + description: 'Summarize older turns as context fills.', checked: compactionEnabled, update: enabled => withCompaction({ ...value.contextManagement?.compaction, enabled }), }; @@ -228,20 +237,23 @@ export function AgentRuntimeConfigFields({ compactionEnabled ? '' : 'opacity-50', )} > -