fix: name run_code's required description argument in its model-facing prose

The transport schema requires both `code` and `description`, but the tool
description and both SDK instruction flavors described the call as passing a
program. `description` was reachable only through the parameter schema, so a
model following the prose emitted `{code}` alone and lost the whole written
program to an INVALID_ARGS rejection.

The length and format guidance stays in RUN_CODE_DESCRIPTION_PARAM_DESCRIPTION
alone, so the schema and the prompt cannot drift.

Fixes #2426
This commit is contained in:
Yichen Jiang
2026-08-12 23:30:51 +08:00
parent c4e24071d6
commit 63fecf2534
24 changed files with 77 additions and 48 deletions

View File

@@ -399,6 +399,10 @@ describe('mode-aware wire contribution', () => {
const runCodeSchema = assembly.tools.find(tool => tool.name === RUN_CODE_NAME)
expect(runCodeSchema?.description).toContain('Execute a TypeScript program')
expect(runCodeSchema?.description).toContain('BODY of an')
// Both required arguments are named here, not only in the parameter
// schema: prose that describes the call as "pass the program" is what
// leads a model to emit `{code}` alone and fail INVALID_ARGS.
expect(runCodeSchema?.description).toContain('`description`')
const codeParam = (runCodeSchema?.parameters as { properties: { code: { description: string } } }).properties.code
expect(codeParam.description).toBe('The program: the body of an async TypeScript function.')
})
@@ -410,6 +414,7 @@ describe('mode-aware wire contribution', () => {
const runCodeSchema = assembly.tools.find(tool => tool.name === RUN_CODE_NAME)
expect(runCodeSchema?.description).toContain('Execute a Python program')
expect(runCodeSchema?.description).toContain('`return <value>`')
expect(runCodeSchema?.description).toContain('`description`')
expect(runCodeSchema?.description).not.toContain('TypeScript')
const codeParam = (runCodeSchema?.parameters as { properties: { code: { description: string } } }).properties.code
expect(codeParam.description).toBe('The program: the body of an async Python function.')

View File

@@ -166,6 +166,15 @@ describe('renderToolsSdkPy', () => {
expect(text).toContain('tools: Tools')
})
it('names both required call arguments, not just the program', () => {
// The schema requires `code` AND `description`; instructions that mention
// only the program let a model emit `{code}` alone and fail INVALID_ARGS.
const text = renderToolsSdkPy([bash])
expect(text).toContain('`code`')
expect(text).toContain('`description`')
expect(text).toContain('two required arguments')
})
it('renders required as plain fields and optional as NotRequired, with per-field description comments', () => {
const tool: ToolSdkSchema = {
name: 'search',

View File

@@ -148,6 +148,15 @@ describe('renderToolsSdk', () => {
expect(text).toContain('lossless JSON')
})
it('names both required call arguments, not just the program', () => {
// The schema requires `code` AND `description`; instructions that mention
// only the program let a model emit `{code}` alone and fail INVALID_ARGS.
const text = renderToolsSdk([bash])
expect(text).toContain('`code`')
expect(text).toContain('`description`')
expect(text).toContain('two required arguments')
})
it('is deterministic: same tool set, byte-identical text regardless of input order', () => {
expect(renderToolsSdk([bash, exotic])).toBe(renderToolsSdk([exotic, bash]))
// Equal names sort stably (the comparator's equal arm).