Skip to content

Commit 3e87d7b

Browse files
feat(spec): an agent's model name becomes optional — absent means the environment's default model (#37697)
<!-- claude-projects-attribution: {"github_login":"hotlong"} --> _Requested by **Jack** · [project thread](https://claude.ai/code/project/chan_01EF41AQooqveF2DGD8nqPzS?thread=cmsg_01EF41AQooqveF2DGD8nqPzS4Qk9xEo3NPMmxK8sJfyTfe)_ Fixes #37686 Clause-②: yes (widening) Metadata-protocol: semantic Skills-docs: follow-up #37711 ## 维护者速读 - 写 agent 元数据的人和 AI:模型块里可以不写模型名,只写温度等参数;不写就用部署的默认模型,写了照旧。没写供应商时也不再自动当成 openai。 - 属于「AI 模型档位」专题第一阶段,按你在决策卡上选的「框架允许省略 model」落地。 - 只放宽不收紧,旧 agent 全部照常解析,运行时行为不变;出问题可直接撤回这个 PR。 - 无。 ## What changes - `packages/spec/src/ai/agent.zod.ts`: `AIModelConfigSchema.model` goes from a required `z.string()` to `z.string().optional()`. Its description now says that an absent model name means the host's default model for the environment. The block stays strict (unknown keys refused); `temperature` still defaults to `0.7`. No sentinel value, no tier key (phase 2 of objectstack-ai/cloud#5055). - Same file, contract review S1 (seat amendment of the order's step 4): `provider` loses `.default('openai')` and becomes `.optional()`; key and enum unchanged. A block that names no model no longer parses to `provider: 'openai'`, which asserted a provider for a model the host picks. The default move is declared in `DEFAULT_CHANGES_BY_MAJOR` under `19` (`packages/spec/scripts/lib/default-changes.ts`) with its consumer-facing reason, and `authorable-defaults/ai.json` drops the line. No runtime reads an agent's `model.provider`, so no deployed agent changes behaviour. Not retired: enforce-or-remove for `provider` is #37712. - `packages/spec/src/ai/agent.test.ts`: six new cases (temperature-only block parses with `model` undefined; an explicit name is carried as written; an unknown key is still refused as `unrecognized_keys`; a non-string name is still refused; a whole agent with `model: { temperature: 0.2 }` parses; a block with no `provider` parses without one, a written one is carried, an off-enum one is refused), and the minimal-config case now expects no `provider`. - `ui/packages/app-shell/src/views/metadata-admin/previews/AgentPreview.tsx` (contract review S2, file surface widened by the seat): the model pill showed only when `model.provider` was set, so a block naming a model and no provider lost the model name once the default was gone. It now shows when a model or a provider is written and reads `PROVIDER · MODEL`, `MODEL` or `PROVIDER`; a block that names neither shows no pill, so the environment default is not given a name. Two new cases in `AgentPreview.test.tsx`. - Generated: `content/docs/references/ai/agent.mdx` (`gen:docs`) and `packages/spec/authorable-defaults/ai.json` (written by the build). authorable-surface, api-surface, the JSON-schema manifest and the metadata-form translations needed no change: the key set is unchanged, and the translations carry only the `model.model` label. - `.changeset/37686-agent-model-name-optional.md`: `@objectstack/spec` minor and `@object-ui/app-shell` patch, with the three declaration lines; `semantic` because a default moved (it outranks `added`). Read first (by risk): `packages/spec/src/ai/agent.zod.ts` (the two contract hunks), `packages/spec/scripts/lib/default-changes.ts` (the declared default move), then the changeset. ## Tests All at head `b3238ea8`, run through `scripts/pm/os-verify-lock.sh` on a shared container. The spec readings were taken at `db5f0e7d`; the only later commit touches `ui/` and the changeset prose. - `pnpm --filter @objectstack/spec exec vitest run --maxWorkers=2 src/ai/agent.test.ts` → Test Files 1 passed, Tests 70 passed. - `pnpm --dir ui exec vitest run packages/app-shell/src/views/metadata-admin/previews/AgentPreview.test.tsx packages/app-shell/src/views/metadata-admin/previews/AgentPreview.emptyCollection-8520.test.tsx` → Test Files 2 passed, Tests 24 passed. - Ablations (each fix committed first, the mutation made on disk, then restored from HEAD): without `model`'s `.optional()`, Tests 2 failed / 67 passed; with `provider`'s `.default('openai')` restored, Tests 3 failed / 67 passed; with the preview pill keyed on `provider` again, Tests 1 failed / 17 passed (the name-only case). The other new cases pin behaviour that holds either way. - `pnpm --filter @objectstack/spec test` → Test Files 903 passed (903), Tests 28557 passed, 1 todo. - `pnpm --filter @objectstack/spec typecheck` → exit 0 (includes `check:test-typecheck`, 52 files held in the ledger, unchanged). - `pnpm --filter @objectstack/spec build && pnpm --filter @objectstack/spec check:generated` → exit 0 after `gen:docs`; the build's default ratchet accepts the declared `ai/AIModelConfig:provider` move. - `@object-ui/app-shell` has no `typecheck` script; its types are `Type Check UI`'s, read from this PR's check-runs. <details><summary>Local gate families: 117 derived, 117 run, all exit 0</summary> `node scripts/pm/dispatch-gates.mjs --commands` derived 117 families for this change set at `b3238ea8` (the three new ones read `ui/`: `check-sdui-manifest` and its self-test, and `vitest run scripts/` under `ui/`); each was run and its exit code captured before any pipe, all 0. `--ran` reconciliation: "117 derived famil(ies) accounted for — 117 run, 0 NOT-MEASURED (a DERIVED zero — all 117 recorded an exit code and none of them is 3)". Families outside the derivation (repo-wide lint, UI lanes, Test Core's repo project) are CI's. </details> ## Acceptance notes - Premise re-checked on `origin/main` 6d106a1: the card's `Re-check:` grep answers 1 hit at `agent.zod.ts:38`. - Readers of an agent's `model.model` in this repo: `packages/spec/src/system/metadata-list-registry.ts` (list column; `valueAtPath` answers `undefined`, so the cell is empty for an agent with no model, which is the card's "empty/default" outcome); `AgentPreview.tsx` (its model pill, reworked here for S2, renders only what is written); tests only otherwise. None breaks on `undefined`. In cloud (read-only, `origin/main` 63427ae), `packages/service-ai/src/agent-runtime.ts:1028` assigns `options.model = agent.model.model`, so an absent name leaves `options.model` undefined there; how cloud resolves that to its default is the cloud card's (objectstack-ai/cloud#5055) after a pin move. - `provider`: declared, not enforced. No runtime in this repo reads an agent's `model.provider`, and in cloud `origin/main` 63427ae `agent-runtime.ts` reads only `model`, `temperature` and `maxTokens` from the agent's block (the `model.provider` read in `vercel-adapter.ts:391` is the AI SDK model object, not the agent config). Its default is dropped here (S1); keep-or-retire is #37712. - Display (S2): the preview reads the raw draft, so a draft that wrote a model and no provider showed no pill even before this PR; the S2 fix shows its name either way. A parsed or stored block no longer carries an invented `openai`. - Skills docs: `skills/objectstack-ai/SKILL.md` "Model Configuration" still teaches `model` as a required free string with `provider` default `openai`, and cites `agent.zod.ts:36-40`; the `skills-tools-knowledge` eval expects "a free-string `model`". Follow-up #37711. - Overlap: #37676 also opens a `19` bucket in `default-changes.ts` (and touches `authorable-defaults/ai.json`); `main` merges cleanly here, the two PRs conflict textually there, and whichever lands second keeps both entries. ## Verification Two-minute check: `pnpm --filter @objectstack/spec exec vitest run src/ai/agent.test.ts` → 70 passed; revert the `model` `.optional()` and two of the new cases go red; restore the `provider` default and three go red. --- _Generated by [Claude Code](https://claude.ai/code/session_01Q4EjjQgJ62YaG4EAxNLuqP)_ <!-- signed: epic:#5055#1 · hotlong · session_01Q4EjjQgJ62YaG4EAxNLuqP --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ce4d8c7 commit 3e87d7b

8 files changed

Lines changed: 104 additions & 10 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@object-ui/app-shell': patch
4+
---
5+
6+
feat(spec): an agent's model name is optional — absent means the host's default model for the environment; `provider` no longer defaults to `openai`
7+
8+
Clause-②: yes (widening)
9+
Metadata-protocol: semantic
10+
Skills-docs: follow-up #37711
11+
12+
`AIModelConfigSchema.model` (the `model` key inside an agent's `model` block) is now optional. An agent that only tunes sampling can write `model: { temperature: 0.2 }` without naming a model; the host then runs it on its default model for the environment. Before, the block refused a missing `model`, so such an agent had to invent a model name it did not mean.
13+
14+
`AIModelConfigSchema.provider` loses its `openai` default. A block that names no model also names no provider, so the parse no longer stamps `provider: 'openai'` onto it — that would assert a provider for a model the host picks. The key and its enum are unchanged, and a written `provider` is carried as written. No runtime reads an agent's `model.provider`, so no deployed agent changes behaviour; what changes is the parsed value.
15+
16+
Unchanged: an explicit `model: { model: 'gpt-4o' }` parses and is carried as written; the block is still strict, so an unknown key is refused; `temperature` still defaults to `0.7`. There is no sentinel value and no tier key.
17+
18+
`@object-ui/app-shell`: the agent preview's model pill appears when the block names a model or a provider, and reads `PROVIDER · MODEL`, `MODEL` or `PROVIDER` from what is written. Before, it keyed on `provider` alone, so a block that named only a model showed no model at all.
19+
20+
What to do: nothing for existing agents. Code that reads `agent.model.model` gets `string | undefined` from the `Agent` type and treats `undefined` as "use the host's default model". Code that read `model.provider` from a parsed agent and relied on `openai` when the author wrote none now reads `undefined`; to keep `openai`, write `provider: 'openai'` in the agent.

‎content/docs/references/ai/agent.mdx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ const result = AIModelConfigSchema.parse(data);
2828

2929
| Property | Type | Required | Description |
3030
| :--- | :--- | :--- | :--- |
31-
| **provider** | `Enum<'openai' \| 'azure_openai' \| 'anthropic' \| 'local'>` | optional (default: `"openai"`) | |
32-
| **model** | `string` | ✅ | Model name (e.g. gpt-4, claude-3-opus) |
31+
| **provider** | `Enum<'openai' \| 'azure_openai' \| 'anthropic' \| 'local'>` | optional | |
32+
| **model** | `string` | optional | Model name (e.g. gpt-4, claude-3-opus). Optional: when absent, the agent runs on the host's default model for this environment, so an agent that only tunes sampling (e.g. `temperature`) need not name a model. |
3333
| **temperature** | `number` | optional (default: `0.7`) | |
3434
| **maxTokens** | `number` | optional | |
3535
| **topP** | `number` | optional | |
@@ -48,7 +48,7 @@ const result = AIModelConfigSchema.parse(data);
4848
| **avatar** | `string` | optional | |
4949
| **role** | `string` | ✅ | The persona/role (e.g. "Senior Support Engineer") |
5050
| **instructions** | `string` | ✅ | System Prompt / Prime Directives |
51-
| **model** | `{ provider?: Enum<'openai' \| 'azure_openai' \| 'anthropic' \| 'local'>; model: string; temperature?: number; maxTokens?: number; … }` | optional | |
51+
| **model** | `{ provider?: Enum<'openai' \| 'azure_openai' \| 'anthropic' \| 'local'>; model?: string; temperature?: number; maxTokens?: number; … }` | optional | |
5252
| **lifecycle** | `never` | optional | [REMOVED] `agent.lifecycle` was removed in @objectstack/spec 17.7.0 (ADR-0049 enforce-or-remove) — no runtime ever read it: no agent moved through a declared state and no transition was ever refused. Delete the key. A phase of a conversation is a skill with its own `instructions` and `tools`, selected by its `triggerConditions` (ADR-0064); multi-step process orchestration is a Flow (ADR-0019); a record's status transitions are a `state_machine` validation rule on the object (ADR-0020). Run `os migrate meta --from 17` to list the mechanical edits for existing sources; `--write` applies the ones it can prove, and you apply the rest by hand. |
5353
| **surface** | `Enum<'ask' \| 'build'>` | optional (default: `"ask"`) | Product surface this agent binds ('ask' \| 'build') — ADR-0063 §1 |
5454
| **skills** | `string[]` | optional | Skill names to attach (Agent→Skill→Tool architecture) |
@@ -72,8 +72,8 @@ const result = AIModelConfigSchema.parse(data);
7272

7373
| Property | Type | Required | Description |
7474
| :--- | :--- | :--- | :--- |
75-
| **provider** | `Enum<'openai' \| 'azure_openai' \| 'anthropic' \| 'local'>` | optional (default: `"openai"`) | |
76-
| **model** | `string` | ✅ | Model name (e.g. gpt-4, claude-3-opus) |
75+
| **provider** | `Enum<'openai' \| 'azure_openai' \| 'anthropic' \| 'local'>` | optional | |
76+
| **model** | `string` | optional | Model name (e.g. gpt-4, claude-3-opus). Optional: when absent, the agent runs on the host's default model for this environment, so an agent that only tunes sampling (e.g. `temperature`) need not name a model. |
7777
| **temperature** | `number` | optional (default: `0.7`) | |
7878
| **maxTokens** | `number` | optional | |
7979
| **topP** | `number` | optional | |

‎packages/spec/authorable-defaults/ai.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"description": "Ratchet of the DEFAULT VALUE of every authorable key in one category that has one (#4666) — what a metadata author gets when they omit the key, which for AI-authored metadata is most of the time. Sharded by category like authorable-surface/; the gate reads the whole authorable-defaults/ directory as ONE set. Each line is \"<def>:<key> = <canonical JSON>\". Additions (a NEW key that ships with a default) are auto-recorded — commit the change. CHANGING, ADDING or REMOVING the default of a key that already existed is NOT auto-recorded: it silently alters the behaviour of already-deployed metadata, so it fails check:authorable-surface until it is declared in DEFAULT_CHANGES_BY_MAJOR (scripts/lib/default-changes.ts). Constraints are deliberately NOT recorded here — a tightened bound REJECTS a document loudly, which is a different and self-announcing class (maintainer ruling on #4666, direction B). See #4666, #4661.",
33
"category": "ai",
44
"defaults": [
5-
"ai/AIModelConfig:provider = \"openai\"",
65
"ai/AIModelConfig:temperature = 0.7",
76
"ai/Agent:active = true",
87
"ai/Agent:surface = \"ask\"",

‎packages/spec/scripts/lib/default-changes.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,4 +798,20 @@ export const DEFAULT_CHANGES_BY_MAJOR: Readonly<Record<number, readonly Declared
798798
+ SEED_MODE_CREATE_ONLY_REASON,
799799
},
800800
],
801+
19: [
802+
{
803+
key: 'ai/AIModelConfig:provider',
804+
from: '"openai"',
805+
to: '(none)',
806+
reason:
807+
'An agent\'s `model` block may now omit the model name, and an absent name means the host\'s '
808+
+ 'default model for the environment. A block that names no model also names no provider, so '
809+
+ 'the parse no longer stamps `provider: \'openai\'` onto it: that would assert a provider for a '
810+
+ 'model the host picks. No runtime reads an agent\'s `model.provider` (the AI service reads '
811+
+ 'the name, `temperature` and `maxTokens` only), so no deployed agent changes behaviour; what '
812+
+ 'changes is the parsed value. Reading `AgentParsed[\'model\'][\'provider\']` now yields the '
813+
+ 'enum or `undefined` where it yielded the enum, and a display that showed `openai` for a '
814+
+ 'block that never wrote it shows nothing. To keep `openai`, write `provider: \'openai\'`.',
815+
},
816+
],
801817
};

‎packages/spec/src/ai/agent.test.ts‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ describe('AIModelConfigSchema', () => {
2020
};
2121

2222
const result = AIModelConfigSchema.parse(config);
23-
expect(result.provider).toBe('openai');
23+
expect(result.provider).toBeUndefined();
2424
expect(result.temperature).toBe(0.7);
2525
});
2626

27+
it('adds no provider to a block that names none — the host picks the model and its provider', () => {
28+
const result = AIModelConfigSchema.parse({ temperature: 0.2 });
29+
expect('provider' in result).toBe(false);
30+
expect(AIModelConfigSchema.parse({ provider: 'anthropic' }).provider).toBe('anthropic');
31+
expect(AIModelConfigSchema.safeParse({ provider: 'google' }).success).toBe(false);
32+
});
33+
2734
it('should accept all providers', () => {
2835
const providers = ['openai', 'azure_openai', 'anthropic', 'local'] as const;
2936

@@ -48,6 +55,40 @@ describe('AIModelConfigSchema', () => {
4855
expect(() => AIModelConfigSchema.parse(config)).not.toThrow();
4956
});
5057

58+
it('accepts a config that omits the model name — absent means the environment default', () => {
59+
const result = AIModelConfigSchema.parse({ temperature: 0.2 });
60+
expect(result.model).toBeUndefined();
61+
expect(result.temperature).toBe(0.2);
62+
expect(result.provider).toBeUndefined();
63+
expect(AIModelConfigSchema.parse({}).model).toBeUndefined();
64+
});
65+
66+
it('keeps an explicit model name exactly as written', () => {
67+
expect(AIModelConfigSchema.parse({ model: 'x' }).model).toBe('x');
68+
});
69+
70+
it('still refuses an unknown key in a config without a model name', () => {
71+
const result = AIModelConfigSchema.safeParse({ temperature: 0.2, tier: 'fast' });
72+
expect(result.success).toBe(false);
73+
expect(result.error?.issues.some((i) => i.code === 'unrecognized_keys')).toBe(true);
74+
});
75+
76+
it('still refuses a non-string model name', () => {
77+
expect(AIModelConfigSchema.safeParse({ model: 4 }).success).toBe(false);
78+
});
79+
80+
it('an agent whose model block only sets temperature parses', () => {
81+
const agent = AgentSchema.parse({
82+
name: 'ask_helper',
83+
label: 'Ask Helper',
84+
role: 'Helper',
85+
instructions: 'Answer questions.',
86+
model: { temperature: 0.2 },
87+
});
88+
expect(agent.model?.model).toBeUndefined();
89+
expect(agent.model?.temperature).toBe(0.2);
90+
});
91+
5192
it('should enforce temperature constraints', () => {
5293
expect(() => AIModelConfigSchema.parse({
5394
model: 'gpt-4',

‎packages/spec/src/ai/agent.zod.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ export const AIModelConfigSchema = lazySchema(() => strictObject({
3434
top_p: 'topP', nucleus: 'topP',
3535
},
3636
}, {
37-
provider: z.enum(['openai', 'azure_openai', 'anthropic', 'local']).default('openai'),
38-
model: z.string().describe('Model name (e.g. gpt-4, claude-3-opus)'),
37+
provider: z.enum(['openai', 'azure_openai', 'anthropic', 'local']).optional(),
38+
model: z.string().optional().describe(
39+
'Model name (e.g. gpt-4, claude-3-opus). Optional: when absent, the agent runs on the '
40+
+ 'host\'s default model for this environment, so an agent that only tunes sampling '
41+
+ '(e.g. `temperature`) need not name a model.',
42+
),
3943
temperature: z.number().min(0).max(2).default(0.7),
4044
maxTokens: z.number().optional(),
4145
topP: z.number().optional(),

‎ui/packages/app-shell/src/views/metadata-admin/previews/AgentPreview.test.tsx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ describe('AgentPreview renders what a spec-valid agent declares', () => {
7575
expect(screen.getByText('You are a helpful sales assistant.')).toBeTruthy();
7676
});
7777

78+
it('shows the model name when the block names no provider', () => {
79+
renderPreview({ ...VALID_DRAFT, model: { model: 'gpt-4o' } });
80+
expect(screen.getByText('gpt-4o')).toBeTruthy();
81+
expect(screen.queryByText(/openai/)).toBeNull();
82+
});
83+
84+
it('shows no model pill for a block that names neither, so the environment default is not given a name', () => {
85+
renderPreview({ ...VALID_DRAFT, model: { temperature: 0.2 } });
86+
expect(screen.queryByText('gpt-4o')).toBeNull();
87+
expect(screen.queryByText(/openai/)).toBeNull();
88+
});
89+
7890
it('says where tools come from, so the missing TOOLS block is not read as a gap', () => {
7991
renderPreview(VALID_DRAFT);
8092
expect(screen.getByText(/tools come from the attached skills/i)).toBeTruthy();

‎ui/packages/app-shell/src/views/metadata-admin/previews/AgentPreview.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ export function AgentPreview({ name, draft, locale }: MetadataPreviewProps) {
153153
label={tr(active ? 'engine.agentPreview.active' : 'engine.agentPreview.disabled', locale)}
154154
tone={active ? 'green' : 'gray'}
155155
/>
156-
{model.provider && <Pill icon={Sparkles} label={`${model.provider}${model.model ? ` · ${model.model}` : ''}`} mono />}
156+
{(model.provider || model.model) && (
157+
<Pill icon={Sparkles} label={[model.provider, model.model].filter(Boolean).join(' · ')} mono />
158+
)}
157159
{model.temperature != null && (
158160
<Pill icon={Gauge} label={tFormat('engine.agentPreview.temperature', locale, { value: String(model.temperature) })} />
159161
)}

0 commit comments

Comments
 (0)