Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

chore: update Agent Config with fallback parameters for max tokens and reasoning effort (#1127)

harshil-2096af832dc6d090
diff --git a/.changeset/agent-model-param-fallbacks.md b/.changeset/agent-model-param-fallbacks.md
new file mode 100644
index 000000000..ae54161b5
--- /dev/null
+++ b/.changeset/agent-model-param-fallbacks.md
@@ -0,0 +1,5 @@
+---
+'@truefoundry/trueforge-ui': patch
+---
+
+Always show max tokens and reasoning effort in Agent Config, with playground fallbacks when the model does not advertise them.
diff --git a/packages/trueforge-ui/src/atoms/draft/AgentModelSettingsContent.tsx b/packages/trueforge-ui/src/atoms/draft/AgentModelSettingsContent.tsx
index e930498d3..632a4aea6 100644
--- a/packages/trueforge-ui/src/atoms/draft/AgentModelSettingsContent.tsx
+++ b/packages/trueforge-ui/src/atoms/draft/AgentModelSettingsContent.tsx
@@ -7,7 +7,13 @@ import { useSlot } from '../../theme/SlotsProvider.js';
import { auiButtonClass } from '../lib/buttonClasses.js';
import { cn } from '../lib/cn.js';
import { auiInputClass } from '../lib/inputClasses.js';
-import { resolveReasoningEffort } from './reasoningEffort.js';
+import {
+ hasReasoningEfforts,
+ maxTokenControl,
+ reasoningEffortOptions,
+ reasoningEffortSeed,
+ UNSUPPORTED_MODEL_PARAM_WARNING,
+} from './reasoningEffort.js';
export type AgentModelSettingsContentProps = {
spec: AgentSpec;
@@ -117,51 +123,33 @@ export function AgentModelSettingsContent({ spec, model, onChange }: AgentModelS
};
const maxOutputTokens = model?.properties.maxOutputTokens;
- const reasoningEfforts = model?.properties.reasoningEfforts ?? [];
- const defaultReasoningEffort = resolveReasoningEffort(reasoningEfforts, undefined);
+ const maxTokens = maxTokenControl(maxOutputTokens);
+ const maxTokensValue = params.maxTokens ?? maxTokens.seed;
+
+ const catalogEfforts = model?.properties.reasoningEfforts;
+ const reasoningOptions = reasoningEffortOptions(catalogEfforts, params.reasoningEffort);
+ const reasoningSeed = reasoningEffortSeed(catalogEfforts);
const rows: Array<{
label: string;
enabled: boolean;
+ unsupported: boolean;
control: ReactNode;
onToggle: (enabled: boolean) => void;
- }> = [];
-
- if (defaultReasoningEffort !== undefined) {
- rows.push({
- label: 'Reasoning Effort',
- enabled: params.reasoningEffort !== undefined,
- onToggle: enabled =>
- enabled ? setParam('reasoningEffort', defaultReasoningEffort) : removeParam('reasoningEffort'),
- control: (
- <select
- value={params.reasoningEffort ?? ''}
- aria-label="Reasoning effort value"
- className={auiInputClass('h-8 cursor-pointer py-1.5')}
- onChange={event => setParam('reasoningEffort', event.target.value)}
- >
- {reasoningEfforts.map(effort => (
- <option key={effort} value={effort}>
- {effort}
- </option>
- ))}
- </select>
- ),
- });
- }
-
- if (maxOutputTokens !== undefined) {
- rows.push({
+ }> = [
+ {
label: 'Maximum Tokens',
enabled: params.maxTokens !== undefined,
- onToggle: enabled => (enabled ? setParam('maxTokens', maxOutputTokens) : removeParam('maxTokens')),
+ unsupported: maxOutputTokens === undefined,
+ onToggle: enabled => (enabled ? setParam('maxTokens', maxTokens.seed) : removeParam('maxTokens')),
control: (
<div className="flex items-center gap-3">
<input
type="range"
- min={1}
- max={maxOutputTokens}
- value={params.maxTokens ?? maxOutputTokens}
+ min={maxTokens.min}
+ max={maxTokens.max}
+ step={maxTokens.step}
+ value={maxTokensValue}
aria-label="Maximum tokens slider"
className="min-w-0 flex-1 accent-primary-button-bg"
onChange={event => {
@@ -171,20 +159,44 @@ export function AgentModelSettingsContent({ spec, model, onChange }: AgentModelS
/>
<input
type="number"
- min={1}
- max={maxOutputTokens}
- value={params.maxTokens ?? maxOutputTokens}
+ min={maxTokens.min}
+ max={maxTokens.max}
+ step={maxTokens.step}
+ value={maxTokensValue}
aria-label="Maximum tokens value"
className={auiInputClass('h-8 w-24')}
onChange={event => {
const value = finiteNumber(event.target.value);
- if (value !== null) setParam('maxTokens', Math.max(1, Math.min(maxOutputTokens, value)));
+ if (value !== null) setParam('maxTokens', Math.min(maxTokens.max, value));
+ }}
+ onBlur={() => {
+ if (maxTokensValue < maxTokens.min) setParam('maxTokens', maxTokens.min);
}}
/>
</div>
),
- });
- }
+ },
+ {
+ label: 'Reasoning Effort',
+ enabled: params.reasoningEffort !== undefined,
+ unsupported: !hasReasoningEfforts(catalogEfforts),
+ onToggle: enabled => (enabled ? setParam('reasoningEffort', reasoningSeed) : removeParam('reasoningEffort')),
+ control: (
+ <select
+ value={params.reasoningEffort ?? ''}
+ aria-label="Reasoning effort value"
+ className={auiInputClass('h-8 cursor-pointer py-1.5')}
+ onChange={event => setParam('reasoningEffort', event.target.value)}
+ >
+ {reasoningOptions.map(effort => (
+ <option key={effort} value={effort}>
+ {effort}
+ </option>
+ ))}
+ </select>
+ ),
+ },
+ ];
return (
<div className="w-full">
@@ -227,7 +239,16 @@ export function AgentModelSettingsContent({ spec, model, onChange }: AgentModelS
{row.enabled ? 'On' : 'Off'}
</button>
</div>
- {row.enabled ? <div className="mt-2">{row.control}</div> : null}
+ {row.enabled ? (
+ <div className="mt-2">
+ {row.control}
+ {row.unsupported ? (
+ <p className="text-failure-bg mt-2 text-xs font-medium" role="status">
+ {UNSUPPORTED_MODEL_PARAM_WARNING}
+ </p>
+ ) : null}
+ </div>
+ ) : null}
</div>
))}
diff --git a/packages/trueforge-ui/src/atoms/draft/DraftReasoningEffortSelector.tsx b/packages/trueforge-ui/src/atoms/draft/DraftReasoningEffortSelector.tsx
index 2c254b508..c03f0011f 100644
--- a/packages/trueforge-ui/src/atoms/draft/DraftReasoningEffortSelector.tsx
+++ b/packages/trueforge-ui/src/atoms/draft/DraftReasoningEffortSelector.tsx
@@ -23,7 +23,7 @@ export function DraftReasoningEffortSelector({ disabled, isRunning }: DraftReaso
const updateAgentSpec = useTrueForgeUpdateAgentSpec();
const [open, setOpen] = useState(false);
const containerRef = useRef<HTMLDivElement>(null);
- const clearedStickyEffortForModelRef = useRef<string | null>(null);
+ const previousModelNameRef = useRef<string | null>(null);
const menuId = useId();
const isMobile = useIsMobile();
const compactLayout = useCompactLayout();
@@ -51,16 +51,14 @@ export function DraftReasoningEffortSelector({ disabled, isRunning }: DraftReaso
return () => document.removeEventListener('mousedown', handler);
}, [open]);
- // Heal sticky effort left by mergeAgentSpec when the selected model has none.
+ // Clear a sticky effort only when the selection changes onto a model with no efforts.
+ // An effort set while staying on the current model is explicit.
useEffect(() => {
if (!updateAgentSpec || selected === undefined) return;
- if (hasReasoningEfforts(efforts)) {
- clearedStickyEffortForModelRef.current = null;
- return;
- }
- if (currentEffort === undefined) return;
- if (clearedStickyEffortForModelRef.current === selected.name) return;
- clearedStickyEffortForModelRef.current = selected.name;
+ const previousName = previousModelNameRef.current;
+ previousModelNameRef.current = selected.name;
+ if (previousName === null || previousName === selected.name) return;
+ if (hasReasoningEfforts(efforts) || currentEffort === undefined) return;
updateAgentSpec({
model: modelPatchWithReasoningEffort(selected.name, agentSpec?.model?.params, undefined),
});
diff --git a/packages/trueforge-ui/src/atoms/draft/reasoningEffort.ts b/packages/trueforge-ui/src/atoms/draft/reasoningEffort.ts
index 43f2733bc..08f06dbe7 100644
--- a/packages/trueforge-ui/src/atoms/draft/reasoningEffort.ts
+++ b/packages/trueforge-ui/src/atoms/draft/reasoningEffort.ts
@@ -2,6 +2,45 @@ import type { Model, ModelParams, ModelSelection } from '../../server/types.js';
type ReasoningEfforts = ModelSelection['properties']['reasoningEfforts'];
+/** Playground max-token catalog, except min is 100 (not 50) so the 25000 default sits on the step grid. */
+const FALLBACK_MAX_TOKENS = 25000;
+const FALLBACK_MAX_TOKENS_MIN = 100;
+const FALLBACK_MAX_TOKENS_MAX = 128_000;
+const FALLBACK_MAX_TOKENS_STEP = 100;
+const FALLBACK_REASONING_EFFORTS = ['none', 'minimal', 'low', 'medium', 'high'] as const;
+
+export const UNSUPPORTED_MODEL_PARAM_WARNING = 'May not be supported by this Model';
+
+export function maxTokenControl(maxOutputTokens: number | undefined): {
+ min: number;
+ max: number;
+ step: number;
+ seed: number;
+} {
+ if (maxOutputTokens === undefined) {
+ return {
+ min: FALLBACK_MAX_TOKENS_MIN,
+ max: FALLBACK_MAX_TOKENS_MAX,
+ step: FALLBACK_MAX_TOKENS_STEP,
+ seed: FALLBACK_MAX_TOKENS,
+ };
+ }
+ return { min: 1, max: maxOutputTokens, step: 1, seed: maxOutputTokens };
+}
+
+export function reasoningEffortOptions(catalog: ReasoningEfforts, current: string | undefined): string[] {
+ if (hasReasoningEfforts(catalog)) return catalog;
+ if (current !== undefined && !FALLBACK_REASONING_EFFORTS.some(effort => effort === current)) {
+ return [current, ...FALLBACK_REASONING_EFFORTS];
+ }
+ return [...FALLBACK_REASONING_EFFORTS];
+}
+
+export function reasoningEffortSeed(catalog: ReasoningEfforts): string {
+ const fallback = resolveReasoningEffort([...FALLBACK_REASONING_EFFORTS], undefined) ?? 'minimal';
+ return resolveReasoningEffort(catalog, undefined) ?? fallback;
+}
+
export function hasReasoningEfforts(efforts: ReasoningEfforts): efforts is string[] {
return Array.isArray(efforts) && efforts.length > 0;
}
diff --git a/packages/trueforge-ui/test/atoms/draft/AgentConfigEditors.test.tsx b/packages/trueforge-ui/test/atoms/draft/AgentConfigEditors.test.tsx
index 70b7a3926..01828fb0f 100644
--- a/packages/trueforge-ui/test/atoms/draft/AgentConfigEditors.test.tsx
+++ b/packages/trueforge-ui/test/atoms/draft/AgentConfigEditors.test.tsx
@@ -261,6 +261,80 @@ describe('AgentConfigEditors', () => {
params: { maxTokens: undefined, temperature: 0.4 },
},
});
+ expect(screen.getByRole('slider', { name: 'Maximum tokens slider' })).toHaveAttribute('max', '8192');
+ expect(screen.queryByText('May not be supported by this Model')).not.toBeInTheDocument();
+ });
+
+ it('shows playground fallbacks and a support warning when the model omits parameters', () => {
+ const spec: AgentSpec = {
+ model: { name: 'openai/gpt', params: { maxTokens: 25000, reasoningEffort: 'xhigh' } },
+ };
+ const onChange = vi.fn();
+ const { rerender } = render(
+ <SlotsProvider>
+ <AgentConfigEditors
+ editor="model-settings"
+ spec={{ model: { name: 'openai/gpt' } }}
+ models={[
+ {
+ id: 'openai/gpt',
+ name: 'openai/gpt',
+ provider: { name: 'OpenAI' },
+ properties: {},
+ },
+ ]}
+ connectors={[]}
+ skills={[]}
+ loading={false}
+ error={null}
+ onChange={onChange}
+ onClose={vi.fn()}
+ />
+ </SlotsProvider>,
+ );
+
+ expect(screen.getByRole('button', { name: 'Turn Maximum Tokens on' })).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'Turn Reasoning Effort on' })).toBeInTheDocument();
+ expect(screen.queryByText('May not be supported by this Model')).not.toBeInTheDocument();
+
+ fireEvent.click(screen.getByRole('button', { name: 'Turn Maximum Tokens on' }));
+ fireEvent.click(screen.getByRole('button', { name: 'Turn Reasoning Effort on' }));
+ expect(onChange).toHaveBeenNthCalledWith(1, {
+ model: { name: 'openai/gpt', params: { maxTokens: 25000 } },
+ });
+ expect(onChange).toHaveBeenNthCalledWith(2, {
+ model: { name: 'openai/gpt', params: { reasoningEffort: 'medium' } },
+ });
+
+ rerender(
+ <SlotsProvider>
+ <AgentConfigEditors
+ editor="model-settings"
+ spec={spec}
+ models={[
+ {
+ id: 'openai/gpt',
+ name: 'openai/gpt',
+ provider: { name: 'OpenAI' },
+ properties: {},
+ },
+ ]}
+ connectors={[]}
+ skills={[]}
+ loading={false}
+ error={null}
+ onChange={onChange}
+ onClose={vi.fn()}
+ />
+ </SlotsProvider>,
+ );
+
+ expect(screen.getByRole('slider', { name: 'Maximum tokens slider' })).toHaveAttribute('min', '100');
+ expect(screen.getByRole('slider', { name: 'Maximum tokens slider' })).toHaveAttribute('max', '128000');
+ expect(screen.getByRole('slider', { name: 'Maximum tokens slider' })).toHaveAttribute('step', '100');
+ expect(screen.getByRole('option', { name: 'xhigh' })).toBeInTheDocument();
+ expect(screen.getByRole('option', { name: 'minimal' })).toBeInTheDocument();
+ expect(screen.getAllByText('May not be supported by this Model')).toHaveLength(2);
});
it('edits the complete parameter object in JSON view and rejects invalid JSON', () => {
diff --git a/packages/trueforge-ui/test/atoms/draft/DraftComposerSections.test.tsx b/packages/trueforge-ui/test/atoms/draft/DraftComposerSections.test.tsx
index 4a150dbe3..a2e1c4d03 100644
--- a/packages/trueforge-ui/test/atoms/draft/DraftComposerSections.test.tsx
+++ b/packages/trueforge-ui/test/atoms/draft/DraftComposerSections.test.tsx
@@ -1,5 +1,5 @@
// @vitest-environment jsdom
-import { fireEvent, render, screen } from '@testing-library/react';
+import { act, fireEvent, render, screen } from '@testing-library/react';
import { useLayoutEffect, type ReactNode } from 'react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -8,7 +8,7 @@ import { DraftComposerLeftSection, DraftComposerRightSection } from '@/atoms/dra
import { CompactLayoutProvider } from '@/atoms/lib/CompactLayoutContext.js';
import { ServerProvider } from '@/server/ServerContext.js';
import { ShellModeProvider, useShellMode } from '@/server/ShellModeContext.js';
-import type { AgentSpec } from '@/server/types.js';
+import type { AgentSpec, ModelSelection } from '@/server/types.js';
import { createMockAgentUIServer } from '../../server/mockServer.js';
let agentSpec: AgentSpec;
@@ -143,6 +143,44 @@ describe('draft composer sections', () => {
expect(screen.getByText('Config open')).toBeInTheDocument();
});
+ it('keeps an explicit reasoning effort when the model lists none', async () => {
+ agentSpec = { model: { name: 'openai/plain', params: { reasoningEffort: 'minimal' } } };
+ let resolveModels: (models: ModelSelection[]) => void = () => {};
+ const modelsReady = new Promise<ModelSelection[]>(resolve => {
+ resolveModels = resolve;
+ });
+ const server = createMockAgentUIServer({
+ getModels: () => modelsReady,
+ });
+
+ render(
+ <ShellModeProvider agentConfig={{ mode: 'AgentComposer' }}>
+ <BuilderMode>
+ <ServerProvider server={server}>
+ <DraftCatalogProvider>
+ <DraftComposerRightSection disabled={false} isRunning={false} />
+ </DraftCatalogProvider>
+ </ServerProvider>
+ </BuilderMode>
+ </ShellModeProvider>,
+ );
+
+ await act(async () => {
+ resolveModels([
+ {
+ id: 'plain',
+ name: 'openai/plain',
+ provider: { name: 'OpenAI' },
+ properties: {},
+ },
+ ]);
+ await modelsReady;
+ });
+
+ expect(updateAgentSpec).not.toHaveBeenCalled();
+ expect(screen.queryByTitle('Select reasoning effort')).not.toBeInTheDocument();
+ });
+
it('propagates disabled and running state to composed controls', async () => {
const { rerender } = render(<DraftSections disabled />);
diff --git a/packages/trueforge-ui/test/atoms/draft/reasoningEffort.test.ts b/packages/trueforge-ui/test/atoms/draft/reasoningEffort.test.ts
index 5ed8b6e1e..cbde0fa6f 100644
--- a/packages/trueforge-ui/test/atoms/draft/reasoningEffort.test.ts
+++ b/packages/trueforge-ui/test/atoms/draft/reasoningEffort.test.ts
@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';
import {
hasReasoningEfforts,
modelPatchWithReasoningEffort,
+ reasoningEffortSeed,
resolveReasoningEffort,
} from '@/atoms/draft/reasoningEffort.js';
@@ -55,6 +56,21 @@ describe('resolveReasoningEffort', () => {
});
});
+describe('reasoningEffortSeed', () => {
+ it('defaults to medium when the catalog or playground fallback offers it', () => {
+ expect(reasoningEffortSeed(['none', 'low', 'medium', 'high'])).toBe('medium');
+ expect(reasoningEffortSeed(undefined)).toBe('medium');
+ });
+
+ it('prefers high over low when medium is absent', () => {
+ expect(reasoningEffortSeed(['none', 'low', 'high'])).toBe('high');
+ });
+
+ it('uses the lowest non-none effort when no preferred effort is listed', () => {
+ expect(reasoningEffortSeed(['none', 'minimal'])).toBe('minimal');
+ });
+});
+
describe('modelPatchWithReasoningEffort', () => {
it('sets effort and preserves other params', () => {
expect(modelPatchWithReasoningEffort('m', { maxTokens: 100, reasoningEffort: 'high' }, ['low', 'high'])).toEqual({