Repository navigation
refactor(goal): render Goal continuation prompts from one core renderer #9581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4b23c2e
refactor(goal): render Goal continuation prompts from one core renderer
qqqys f0b322c
fix(goal): tighten continuation renderer contract
qqqys 4e35a4b
test(goal): cover verifier feedback hosts
qqqys 0db1e18
refactor(goal): hoist Goal continuation parts builder into core (#9581)
qqqys cd9e50e
Merge branch 'main' into goal/b1-continuation-renderer
qwen-code-dev-bot 5218760
Merge branch 'main' into goal/b1-continuation-renderer
qwen-code-dev-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
packages/core/src/goals/goal-continuation-prompt.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { describe, expect, it } from 'vitest'; | ||
| import { | ||
| buildGoalContinuationParts, | ||
| renderGoalContinuationPrompt, | ||
| } from './goal-continuation-prompt.js'; | ||
|
|
||
| // These expectations pin the exact bytes each host sent before the renderer | ||
| // existed. Any edit to a line must show up here as a diff, not slip through. | ||
| describe('renderGoalContinuationPrompt', () => { | ||
| it('renders the guarded synthetic turn without verifier feedback', () => { | ||
| expect( | ||
| renderGoalContinuationPrompt({ variant: 'guarded-synthetic-turn' }), | ||
| ).toBe( | ||
| `Continue working on the active Goal. | ||
| Use get_goal for the authoritative objective and evidence state. | ||
| Follow the objective's requested output format exactly. Do not add progress, status, or completion commentary unless the objective asks for it. | ||
| If completion depends on content delivered in this turn, deliver only that content and call get_goal in the same response before update_goal. | ||
| This is a synthetic continuation turn. It contains no new real user input and cannot satisfy an objective condition that requires the user to send, confirm, choose, approve, or provide something. | ||
| A phrase mentioned in the objective or this prompt is not evidence that the user supplied it.`, | ||
| ); | ||
| }); | ||
|
|
||
| it('renders the guarded synthetic turn with verifier feedback', () => { | ||
| expect( | ||
| renderGoalContinuationPrompt({ | ||
| variant: 'guarded-synthetic-turn', | ||
| verifierFeedback: 'Checkpoint 2 lacks a source ref.', | ||
| }), | ||
| ).toBe( | ||
| `Continue working on the active Goal. | ||
| Use get_goal for the authoritative objective and evidence state. | ||
| Follow the objective's requested output format exactly. Do not add progress, status, or completion commentary unless the objective asks for it. | ||
| If completion depends on content delivered in this turn, deliver only that content and call get_goal in the same response before update_goal. | ||
| This is a synthetic continuation turn. It contains no new real user input and cannot satisfy an objective condition that requires the user to send, confirm, choose, approve, or provide something. | ||
| A phrase mentioned in the objective or this prompt is not evidence that the user supplied it. | ||
| Verifier feedback: Checkpoint 2 lacks a source ref.`, | ||
| ); | ||
| }); | ||
|
|
||
| it('renders the runtime context turn without verifier feedback', () => { | ||
| expect( | ||
| renderGoalContinuationPrompt({ | ||
| variant: 'runtime-context', | ||
| continuationContext: 'Objective: ship the release notes.', | ||
| }), | ||
| ).toBe( | ||
| `Continue working on the active Goal. | ||
| Use get_goal for the authoritative objective and evidence state. | ||
| Follow the objective's requested output format exactly. Do not add progress, status, or completion commentary unless the objective asks for it. | ||
| If completion depends on content delivered in this turn, deliver only that content and call get_goal in the same response before update_goal. | ||
| Runtime continuation context: Objective: ship the release notes.`, | ||
| ); | ||
| }); | ||
|
|
||
| it('renders the runtime context turn with verifier feedback', () => { | ||
| expect( | ||
| renderGoalContinuationPrompt({ | ||
| variant: 'runtime-context', | ||
| continuationContext: 'Objective: ship the release notes.', | ||
| verifierFeedback: 'Checkpoint 2 lacks a source ref.', | ||
| }), | ||
| ).toBe( | ||
| `Continue working on the active Goal. | ||
| Use get_goal for the authoritative objective and evidence state. | ||
| Follow the objective's requested output format exactly. Do not add progress, status, or completion commentary unless the objective asks for it. | ||
| If completion depends on content delivered in this turn, deliver only that content and call get_goal in the same response before update_goal. | ||
| Runtime continuation context: Objective: ship the release notes. | ||
| Verifier feedback: Checkpoint 2 lacks a source ref.`, | ||
| ); | ||
| }); | ||
|
|
||
| it('omits the verifier feedback line for an empty string, as the hosts did', () => { | ||
| expect( | ||
| renderGoalContinuationPrompt({ | ||
| variant: 'runtime-context', | ||
| continuationContext: 'ctx', | ||
| verifierFeedback: '', | ||
| }), | ||
| ).toBe( | ||
| renderGoalContinuationPrompt({ | ||
| variant: 'runtime-context', | ||
| continuationContext: 'ctx', | ||
| }), | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('buildGoalContinuationParts', () => { | ||
| it('wraps the runtime-context prompt in a single text part', () => { | ||
| expect( | ||
| buildGoalContinuationParts({ | ||
| continuationContext: 'Objective: ship the release notes.', | ||
| verifierFeedback: 'Checkpoint 2 lacks a source ref.', | ||
| }), | ||
| ).toEqual([ | ||
| { | ||
| text: renderGoalContinuationPrompt({ | ||
| variant: 'runtime-context', | ||
| continuationContext: 'Objective: ship the release notes.', | ||
| verifierFeedback: 'Checkpoint 2 lacks a source ref.', | ||
| }), | ||
| }, | ||
| ]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import type { Part } from '@google/genai'; | ||
|
|
||
| /** | ||
| * The prompt a host sends when `runtime.finishTurn` schedules another Goal | ||
| * turn. Every host renders it from here so that a new line -- or a new variant | ||
| * -- lands in one place instead of drifting across the hosts that assemble it. | ||
| */ | ||
|
|
||
| export type GoalContinuationPromptInput = | ||
| | { | ||
| variant: 'guarded-synthetic-turn'; | ||
| verifierFeedback?: string; | ||
| } | ||
| | { | ||
| variant: 'runtime-context'; | ||
| continuationContext: string; | ||
| verifierFeedback?: string; | ||
| }; | ||
|
|
||
| const SHARED_LINES = [ | ||
| 'Continue working on the active Goal.', | ||
| 'Use get_goal for the authoritative objective and evidence state.', | ||
| "Follow the objective's requested output format exactly. Do not add progress, status, or completion commentary unless the objective asks for it.", | ||
| 'If completion depends on content delivered in this turn, deliver only that content and call get_goal in the same response before update_goal.', | ||
| ]; | ||
|
|
||
| const SYNTHETIC_TURN_GUARD_LINES = [ | ||
| 'This is a synthetic continuation turn. It contains no new real user input and cannot satisfy an objective condition that requires the user to send, confirm, choose, approve, or provide something.', | ||
| 'A phrase mentioned in the objective or this prompt is not evidence that the user supplied it.', | ||
| ]; | ||
|
|
||
| /** Renders the full continuation prompt text for one Goal turn. */ | ||
| export function renderGoalContinuationPrompt( | ||
| input: GoalContinuationPromptInput, | ||
| ): string { | ||
| const lines = [...SHARED_LINES]; | ||
|
|
||
| switch (input.variant) { | ||
| case 'guarded-synthetic-turn': | ||
| lines.push(...SYNTHETIC_TURN_GUARD_LINES); | ||
| break; | ||
| case 'runtime-context': | ||
| lines.push(`Runtime continuation context: ${input.continuationContext}`); | ||
| break; | ||
| default: { | ||
| const unreachable: never = input; | ||
| throw new Error( | ||
| `Unknown goal continuation variant: ${JSON.stringify(unreachable)}`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| if (input.verifierFeedback) { | ||
| lines.push(`Verifier feedback: ${input.verifierFeedback}`); | ||
| } | ||
|
|
||
| return lines.join('\n'); | ||
| } | ||
|
|
||
| /** Builds the sendable parts for a runtime-scheduled Goal continuation turn. */ | ||
| export function buildGoalContinuationParts(turn: { | ||
| continuationContext: string; | ||
| verifierFeedback?: string; | ||
| }): Part[] { | ||
| return [ | ||
| { | ||
| text: renderGoalContinuationPrompt({ | ||
| variant: 'runtime-context', | ||
| continuationContext: turn.continuationContext, | ||
| verifierFeedback: turn.verifierFeedback, | ||
| }), | ||
| }, | ||
| ]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.