fix(prompt): end the turn while waiting on subagents
Restore the subagent guidance sentence that #6348 removed: when only a delegated result remains, the model ends its turn instead of sleeping or polling, because a finished subagent wakes the idle parent. A controlled single-request probe (deepseek-v4-flash and deepseek-v4-pro, 150 samples per arm) measured a bash sleep in 0/300 samples with the sentence and 29/300 without it; any waiting tool call in 7/300 versus 120/300. Unit expectations for the rendered guidance follow the restored text.
This commit is contained in:
1 parent
9e6692931c
commit
bc540720ec
2 files changed
+10
-10
No files matched your search
@@ -371,7 +371,7 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
|
||||
.sort()
|
||||
if (visible[0] !== toolName) return ''
|
||||
const names = visible.map(name => `\`${name}\``).join(' or ')
|
||||
return `Start independent delegations with ${names} together in one assistant message and continue useful work while they run.`
|
||||
return `Start independent delegations with ${names} together in one assistant message and continue useful work while they run. When only waiting for their results remains, end your turn instead of sleeping or polling; the next result starts a new turn.`
|
||||
},
|
||||
})
|
||||
runtimeCtx.systemPrompt.context({
|
||||
|
||||
@@ -381,21 +381,21 @@ describe('dsh-tool-subagent', () => {
|
||||
|
||||
const forkProvider = await mock.mountScriptedProvider(ctx, { name: 'fork', inheritsParentContext: true })
|
||||
expect(await delegationGuidance(ctx)).toEqual([
|
||||
'Start independent delegations with `subagent_fork` together in one assistant message and continue useful work while they run.',
|
||||
'Start independent delegations with `subagent_fork` together in one assistant message and continue useful work while they run. When only waiting for their results remains, end your turn instead of sleeping or polling; the next result starts a new turn.',
|
||||
])
|
||||
await mock.mountScriptedProvider(ctx, { name: 'spawn' })
|
||||
expect(await delegationGuidance(ctx)).toEqual([
|
||||
'Start independent delegations with `subagent` or `subagent_fork` together in one assistant message and continue useful work while they run.',
|
||||
'Start independent delegations with `subagent` or `subagent_fork` together in one assistant message and continue useful work while they run. When only waiting for their results remains, end your turn instead of sleeping or polling; the next result starts a new turn.',
|
||||
])
|
||||
|
||||
await forkProvider.dispose()
|
||||
expect(await delegationGuidance(ctx)).toEqual([
|
||||
'Start independent delegations with `subagent` together in one assistant message and continue useful work while they run.',
|
||||
'Start independent delegations with `subagent` together in one assistant message and continue useful work while they run. When only waiting for their results remains, end your turn instead of sleeping or polling; the next result starts a new turn.',
|
||||
])
|
||||
await mock.mountScriptedProvider(ctx, { name: 'fork', inheritsParentContext: true })
|
||||
await spawnTool.dispose()
|
||||
expect(await delegationGuidance(ctx)).toEqual([
|
||||
'Start independent delegations with `subagent_fork` together in one assistant message and continue useful work while they run.',
|
||||
'Start independent delegations with `subagent_fork` together in one assistant message and continue useful work while they run. When only waiting for their results remains, end your turn instead of sleeping or polling; the next result starts a new turn.',
|
||||
])
|
||||
await forkTool.dispose()
|
||||
expect(await delegationGuidance(ctx)).toEqual([])
|
||||
@@ -409,19 +409,19 @@ describe('dsh-tool-subagent', () => {
|
||||
const peer = (await ctx.agents.create({ sessionId: SessionId('guidance-peer') })).agent
|
||||
const showSpawn = parent.ctx.tools.restrict({ deny: ['subagent'] })
|
||||
expect(await delegationGuidance(ctx, parent)).toEqual([
|
||||
'Start independent delegations with `subagent_fork` together in one assistant message and continue useful work while they run.',
|
||||
'Start independent delegations with `subagent_fork` together in one assistant message and continue useful work while they run. When only waiting for their results remains, end your turn instead of sleeping or polling; the next result starts a new turn.',
|
||||
])
|
||||
expect(await delegationGuidance(ctx, peer)).toEqual([
|
||||
'Start independent delegations with `subagent` or `subagent_fork` together in one assistant message and continue useful work while they run.',
|
||||
'Start independent delegations with `subagent` or `subagent_fork` together in one assistant message and continue useful work while they run. When only waiting for their results remains, end your turn instead of sleeping or polling; the next result starts a new turn.',
|
||||
])
|
||||
expect(await delegationGuidance(unrelated)).toEqual([
|
||||
'Start independent delegations with `other_delegate` together in one assistant message and continue useful work while they run.',
|
||||
'Start independent delegations with `other_delegate` together in one assistant message and continue useful work while they run. When only waiting for their results remains, end your turn instead of sleeping or polling; the next result starts a new turn.',
|
||||
])
|
||||
showSpawn()
|
||||
|
||||
const scoped = await parent.ctx.plugin(tool, { provider: 'mock', toolName: 'subagent' })
|
||||
expect(await delegationGuidance(ctx, parent)).toEqual([
|
||||
'Start independent delegations with `subagent` or `subagent_fork` together in one assistant message and continue useful work while they run.',
|
||||
'Start independent delegations with `subagent` or `subagent_fork` together in one assistant message and continue useful work while they run. When only waiting for their results remains, end your turn instead of sleeping or polling; the next result starts a new turn.',
|
||||
])
|
||||
await scoped.dispose()
|
||||
parent.ctx.tools.restrict({ deny: ['subagent', 'subagent_fork'] })
|
||||
@@ -720,7 +720,7 @@ describe('dsh-tool-subagent local activation', () => {
|
||||
expect(properties.run_in_background).toBeUndefined()
|
||||
const assembly = await ctx.systemPrompt.assemble(assembleContextFor(parent))
|
||||
const guidance = assembly.sections.find(section => section.name === 'tool:subagent')
|
||||
expect(guidance?.text).toBe('Start independent delegations with `subagent` together in one assistant message and continue useful work while they run.')
|
||||
expect(guidance?.text).toBe('Start independent delegations with `subagent` together in one assistant message and continue useful work while they run. When only waiting for their results remains, end your turn instead of sleeping or polling; the next result starts a new turn.')
|
||||
|
||||
const started = await callSubagent(
|
||||
ctx,
|
||||
|
||||
Reference in new issue
Block a user