diff --git a/.changeset/37686-agent-model-name-optional.md b/.changeset/37686-agent-model-name-optional.md new file mode 100644 index 00000000000..026c9727966 --- /dev/null +++ b/.changeset/37686-agent-model-name-optional.md @@ -0,0 +1,20 @@ +--- +'@objectstack/spec': minor +'@object-ui/app-shell': patch +--- + +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` + +Clause-②: yes (widening) +Metadata-protocol: semantic +Skills-docs: follow-up #37711 + +`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. + +`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. + +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. + +`@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. + +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. diff --git a/content/docs/references/ai/agent.mdx b/content/docs/references/ai/agent.mdx index 05ef096cfd5..76be187cd41 100644 --- a/content/docs/references/ai/agent.mdx +++ b/content/docs/references/ai/agent.mdx @@ -28,8 +28,8 @@ const result = AIModelConfigSchema.parse(data); | Property | Type | Required | Description | | :--- | :--- | :--- | :--- | -| **provider** | `Enum<'openai' \| 'azure_openai' \| 'anthropic' \| 'local'>` | optional (default: `"openai"`) | | -| **model** | `string` | ✅ | Model name (e.g. gpt-4, claude-3-opus) | +| **provider** | `Enum<'openai' \| 'azure_openai' \| 'anthropic' \| 'local'>` | optional | | +| **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. | | **temperature** | `number` | optional (default: `0.7`) | | | **maxTokens** | `number` | optional | | | **topP** | `number` | optional | | @@ -48,7 +48,7 @@ const result = AIModelConfigSchema.parse(data); | **avatar** | `string` | optional | | | **role** | `string` | ✅ | The persona/role (e.g. "Senior Support Engineer") | | **instructions** | `string` | ✅ | System Prompt / Prime Directives | -| **model** | `{ provider?: Enum<'openai' \| 'azure_openai' \| 'anthropic' \| 'local'>; model: string; temperature?: number; maxTokens?: number; … }` | optional | | +| **model** | `{ provider?: Enum<'openai' \| 'azure_openai' \| 'anthropic' \| 'local'>; model?: string; temperature?: number; maxTokens?: number; … }` | optional | | | **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. | | **surface** | `Enum<'ask' \| 'build'>` | optional (default: `"ask"`) | Product surface this agent binds ('ask' \| 'build') — ADR-0063 §1 | | **skills** | `string[]` | optional | Skill names to attach (Agent→Skill→Tool architecture) | @@ -72,8 +72,8 @@ const result = AIModelConfigSchema.parse(data); | Property | Type | Required | Description | | :--- | :--- | :--- | :--- | -| **provider** | `Enum<'openai' \| 'azure_openai' \| 'anthropic' \| 'local'>` | optional (default: `"openai"`) | | -| **model** | `string` | ✅ | Model name (e.g. gpt-4, claude-3-opus) | +| **provider** | `Enum<'openai' \| 'azure_openai' \| 'anthropic' \| 'local'>` | optional | | +| **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. | | **temperature** | `number` | optional (default: `0.7`) | | | **maxTokens** | `number` | optional | | | **topP** | `number` | optional | | diff --git a/packages/spec/authorable-defaults/ai.json b/packages/spec/authorable-defaults/ai.json index b5c8f97d09a..0f02968e0d4 100644 --- a/packages/spec/authorable-defaults/ai.json +++ b/packages/spec/authorable-defaults/ai.json @@ -2,7 +2,6 @@ "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 \": = \". 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.", "category": "ai", "defaults": [ - "ai/AIModelConfig:provider = \"openai\"", "ai/AIModelConfig:temperature = 0.7", "ai/Agent:active = true", "ai/Agent:surface = \"ask\"", diff --git a/packages/spec/scripts/lib/default-changes.ts b/packages/spec/scripts/lib/default-changes.ts index 4aa649575c2..c831504cf0b 100644 --- a/packages/spec/scripts/lib/default-changes.ts +++ b/packages/spec/scripts/lib/default-changes.ts @@ -798,4 +798,20 @@ export const DEFAULT_CHANGES_BY_MAJOR: Readonly { }; const result = AIModelConfigSchema.parse(config); - expect(result.provider).toBe('openai'); + expect(result.provider).toBeUndefined(); expect(result.temperature).toBe(0.7); }); + it('adds no provider to a block that names none — the host picks the model and its provider', () => { + const result = AIModelConfigSchema.parse({ temperature: 0.2 }); + expect('provider' in result).toBe(false); + expect(AIModelConfigSchema.parse({ provider: 'anthropic' }).provider).toBe('anthropic'); + expect(AIModelConfigSchema.safeParse({ provider: 'google' }).success).toBe(false); + }); + it('should accept all providers', () => { const providers = ['openai', 'azure_openai', 'anthropic', 'local'] as const; @@ -48,6 +55,40 @@ describe('AIModelConfigSchema', () => { expect(() => AIModelConfigSchema.parse(config)).not.toThrow(); }); + it('accepts a config that omits the model name — absent means the environment default', () => { + const result = AIModelConfigSchema.parse({ temperature: 0.2 }); + expect(result.model).toBeUndefined(); + expect(result.temperature).toBe(0.2); + expect(result.provider).toBeUndefined(); + expect(AIModelConfigSchema.parse({}).model).toBeUndefined(); + }); + + it('keeps an explicit model name exactly as written', () => { + expect(AIModelConfigSchema.parse({ model: 'x' }).model).toBe('x'); + }); + + it('still refuses an unknown key in a config without a model name', () => { + const result = AIModelConfigSchema.safeParse({ temperature: 0.2, tier: 'fast' }); + expect(result.success).toBe(false); + expect(result.error?.issues.some((i) => i.code === 'unrecognized_keys')).toBe(true); + }); + + it('still refuses a non-string model name', () => { + expect(AIModelConfigSchema.safeParse({ model: 4 }).success).toBe(false); + }); + + it('an agent whose model block only sets temperature parses', () => { + const agent = AgentSchema.parse({ + name: 'ask_helper', + label: 'Ask Helper', + role: 'Helper', + instructions: 'Answer questions.', + model: { temperature: 0.2 }, + }); + expect(agent.model?.model).toBeUndefined(); + expect(agent.model?.temperature).toBe(0.2); + }); + it('should enforce temperature constraints', () => { expect(() => AIModelConfigSchema.parse({ model: 'gpt-4', diff --git a/packages/spec/src/ai/agent.zod.ts b/packages/spec/src/ai/agent.zod.ts index 7c76bf180f6..2c97383f7f3 100644 --- a/packages/spec/src/ai/agent.zod.ts +++ b/packages/spec/src/ai/agent.zod.ts @@ -34,8 +34,12 @@ export const AIModelConfigSchema = lazySchema(() => strictObject({ top_p: 'topP', nucleus: 'topP', }, }, { - provider: z.enum(['openai', 'azure_openai', 'anthropic', 'local']).default('openai'), - model: z.string().describe('Model name (e.g. gpt-4, claude-3-opus)'), + provider: z.enum(['openai', 'azure_openai', 'anthropic', 'local']).optional(), + model: z.string().optional().describe( + '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.', + ), temperature: z.number().min(0).max(2).default(0.7), maxTokens: z.number().optional(), topP: z.number().optional(), diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/AgentPreview.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/previews/AgentPreview.test.tsx index 4693478d631..6407090e94c 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/AgentPreview.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/AgentPreview.test.tsx @@ -75,6 +75,18 @@ describe('AgentPreview renders what a spec-valid agent declares', () => { expect(screen.getByText('You are a helpful sales assistant.')).toBeTruthy(); }); + it('shows the model name when the block names no provider', () => { + renderPreview({ ...VALID_DRAFT, model: { model: 'gpt-4o' } }); + expect(screen.getByText('gpt-4o')).toBeTruthy(); + expect(screen.queryByText(/openai/)).toBeNull(); + }); + + it('shows no model pill for a block that names neither, so the environment default is not given a name', () => { + renderPreview({ ...VALID_DRAFT, model: { temperature: 0.2 } }); + expect(screen.queryByText('gpt-4o')).toBeNull(); + expect(screen.queryByText(/openai/)).toBeNull(); + }); + it('says where tools come from, so the missing TOOLS block is not read as a gap', () => { renderPreview(VALID_DRAFT); expect(screen.getByText(/tools come from the attached skills/i)).toBeTruthy(); diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/AgentPreview.tsx b/ui/packages/app-shell/src/views/metadata-admin/previews/AgentPreview.tsx index 7043f23f2cd..0d68864c886 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/AgentPreview.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/AgentPreview.tsx @@ -153,7 +153,9 @@ export function AgentPreview({ name, draft, locale }: MetadataPreviewProps) { label={tr(active ? 'engine.agentPreview.active' : 'engine.agentPreview.disabled', locale)} tone={active ? 'green' : 'gray'} /> - {model.provider && } + {(model.provider || model.model) && ( + + )} {model.temperature != null && ( )}