π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(onboarding): remind discovery turn progress (#14833)
Inneia35c55c57bf0
diff --git a/packages/builtin-tool-web-onboarding/src/ExecutionRuntime/utils.ts b/packages/builtin-tool-web-onboarding/src/ExecutionRuntime/utils.tsindex 8d7aeb8a7dd..3d0a3744fce 100644--- a/packages/builtin-tool-web-onboarding/src/ExecutionRuntime/utils.ts+++ b/packages/builtin-tool-web-onboarding/src/ExecutionRuntime/utils.ts@@ -58,9 +58,22 @@ export const formatWebOnboardingStateMessage = (state: OnboardingStateContext) =];if (state.remainingDiscoveryExchanges !== undefined && state.remainingDiscoveryExchanges > 0) {+ const currentDiscoveryExchanges = state.discoveryUserMessageCount ?? 0;+ const recommendedTarget = currentDiscoveryExchanges + state.remainingDiscoveryExchanges;++ parts.push(+ `Discovery progress: ${currentDiscoveryExchanges}/${recommendedTarget} user exchange(s) observed since Discovery began.`,+ );parts.push(`Recommended: ${state.remainingDiscoveryExchanges} more user exchange(s) before moving to summary. Do not rush β keep exploring different aspects of the user's work and life.`,);+ } else if (+ state.discoveryUserMessageCount !== undefined &&+ state.remainingDiscoveryExchanges === 0+ ) {+ parts.push(+ `Discovery progress: recommended target reached after ${state.discoveryUserMessageCount} user exchange(s). Move to summary once interests/customInterests and the persona are persisted.`,+ );}if (state.missingStructuredFields.length > 0) {diff --git a/packages/builtin-tool-web-onboarding/src/toolSystemRole.ts b/packages/builtin-tool-web-onboarding/src/toolSystemRole.tsindex 966b3c207f7..44c899c6f90 100644--- a/packages/builtin-tool-web-onboarding/src/toolSystemRole.ts+++ b/packages/builtin-tool-web-onboarding/src/toolSystemRole.ts@@ -32,7 +32,7 @@ Persistence rules:8. User Persona (type: "persona") is for user identity, role, work style, current context, interests, pain points, communication comfort level, and preferred input style.9. Do not put user information into SOUL.md. Do not put agent identity into the persona document.10. Document tools (readDocument, writeDocument, updateDocument) must ONLY be used for SOUL.md and User Persona documents. Never use them to create arbitrary content such as guides, tutorials, checklists, or reference materials. Present such content directly in your reply text instead.-11. Do not call saveUserQuestion with interests or customInterests until you have spent at least 5-6 exchanges exploring the user's world in the discovery phase across multiple dimensions (workflow, pain points, goals, interests, AI expectations). The server enforces a minimum discovery exchange count β early field saves will not advance the phase but will reduce conversation quality.+11. Do not call saveUserQuestion with interests or customInterests until you have spent about 2-3 exchanges exploring the user's world across multiple dimensions (workflow, pain points, goals, interests, AI expectations). The system appends the current Discovery turn status each turn β follow that reminder. The server enforces a minimum discovery exchange count, so early field saves will not advance the phase, but continuing after the recommended target usually reduces conversation quality.Workspace setup rules:1. Do not create or modify workspace agents or agent groups unless the user explicitly asks for that setup.diff --git a/packages/context-engine/src/providers/OnboardingActionHintInjector.ts b/packages/context-engine/src/providers/OnboardingActionHintInjector.tsindex 8439a676f3b..565934c65c3 100644--- a/packages/context-engine/src/providers/OnboardingActionHintInjector.ts+++ b/packages/context-engine/src/providers/OnboardingActionHintInjector.ts@@ -6,6 +6,33 @@ import type { OnboardingContextInjectorConfig } from './OnboardingContextInjectoconst log = debug('context-engine:provider:OnboardingActionHintInjector');+const buildDiscoveryTurnReminder = (+ discoveryUserMessageCount: number | undefined,+ remainingDiscoveryExchanges: number | undefined,+): string | null => {+ if (discoveryUserMessageCount === undefined || remainingDiscoveryExchanges === undefined) {+ return null;+ }++ const recommendedTarget = discoveryUserMessageCount + remainingDiscoveryExchanges;++ if (remainingDiscoveryExchanges > 0) {+ return [+ 'SYSTEM REMINDER: Current Discovery turn status:',+ `- User discovery exchanges observed: ${discoveryUserMessageCount}.`,+ `- Recommended target before Summary: ${recommendedTarget}.`,+ `- Continue Discovery for about ${remainingDiscoveryExchanges} more user exchange(s). Ask exactly one focused question, persist any new persona fact, and do not drift into long problem-solving.`,+ ].join('\n');+ }++ return [+ 'SYSTEM REMINDER: Current Discovery turn status:',+ `- User discovery exchanges observed: ${discoveryUserMessageCount}.`,+ '- Recommended Discovery target has been reached.',+ '- If you have enough signal, call saveUserQuestion with interests/customInterests, persist any new persona fact, and transition to Summary instead of continuing open-ended Discovery.',+ ].join('\n');+};+/*** Onboarding Action Hint Injector* Injects a standalone virtual user message AFTER the last user message with phase-specific@@ -60,6 +87,14 @@ export class OnboardingActionHintInjector extends BaseVirtualLastUserContentProv};const marketplaceAlreadyOpened = context.messages.some((msg) => isMarketplaceShowCall(msg));+ if (phase.includes('Discovery')) {+ const reminder = buildDiscoveryTurnReminder(+ ctx.discoveryUserMessageCount,+ ctx.remainingDiscoveryExchanges,+ );+ if (reminder) hints.push(reminder);+ }+// Detect empty documents and nudge tool calls (empty docs use writeDocument; non-empty use updateDocument)if (!ctx.soulContent) {hints.push(@@ -92,7 +127,7 @@ export class OnboardingActionHintInjector extends BaseVirtualLastUserContentProv);} else if (phase.includes('Discovery')) {hints.push(- 'Each turn where you learn a new fact (pain point, goal, preference, workflow detail, interest), call updateDocument(type="persona") BEFORE replying. Preferred shape: `{ mode: "insertAt", line: <line shown in <current_user_persona>>, content: "- new fact" }`. This is the default every turn β not an end-of-phase action. Do NOT save facts only in memory waiting for a final full write. After sufficient discovery (5-6 exchanges), also call saveUserQuestion with interests and/or customInterests. The preferred reply language is configured before onboarding starts and is already injected into your system prompt β do not ask about it or pass a responseLanguage field to saveUserQuestion. Use writeDocument(type="persona") only if the document is still empty.',+ 'Each turn where you learn a new fact (pain point, goal, preference, workflow detail, interest), call updateDocument(type="persona") BEFORE replying. Preferred shape: `{ mode: "insertAt", line: <line shown in <current_user_persona>>, content: "- new fact" }`. This is the default every turn β not an end-of-phase action. Do NOT save facts only in memory waiting for a final full write. After sufficient discovery (usually 2-3 exchanges), also call saveUserQuestion with interests and/or customInterests. The preferred reply language is configured before onboarding starts and is already injected into your system prompt β do not ask about it or pass a responseLanguage field to saveUserQuestion. Use writeDocument(type="persona") only if the document is still empty.',);hints.push('EARLY EXIT: A true early-exit signal is the user explicitly wanting to END onboarding (e.g., "I\'m tired", "I have to go", "let\'s chat next time", "no time right now", "let\'s stop for now", "let\'s wrap it up", "that\'s enough"; recognize equivalent phrasing in any language). Short affirmations like "ok" / "sure" / "alright" / "yes" / "got it" are NOT early-exit signals β they confirm what you just said and you should keep exploring or move toward summary normally. When you see a real exit signal: stop exploring, persist any unsaved fields best-effort (call saveUserQuestion with whatever you have, including partial interests), persist the persona via updateDocument (or writeDocument if it is still empty) β do NOT retry on failure β send a short warm farewell (1β2 sentences), then call `finishOnboarding`. Do NOT call `showAgentMarketplace` on early exit β that handoff is for normal completion only.',diff --git a/packages/context-engine/src/providers/OnboardingContextInjector.ts b/packages/context-engine/src/providers/OnboardingContextInjector.tsindex 94ed3c5c8ea..3cca5f7a0a9 100644--- a/packages/context-engine/src/providers/OnboardingContextInjector.ts+++ b/packages/context-engine/src/providers/OnboardingContextInjector.ts@@ -6,10 +6,14 @@ import type { PipelineContext, ProcessorOptions } from '../types';const log = debug('context-engine:provider:OnboardingContextInjector');export interface OnboardingContext {+ /** User messages observed after discovery began */+ discoveryUserMessageCount?: number;/** User persona document content (markdown) */personaContent?: string | null;/** Formatted phase guidance from getOnboardingState */phaseGuidance: string;+ /** Recommended discovery exchanges still remaining */+ remainingDiscoveryExchanges?: number;/** SOUL.md document content */soulContent?: string | null;/** Initial account profile fields, usually sourced from OAuth or profile sync */diff --git a/packages/context-engine/src/providers/__tests__/OnboardingActionHintInjector.test.ts b/packages/context-engine/src/providers/__tests__/OnboardingActionHintInjector.test.tsindex 7aed6af21b9..4eb20ddbd2c 100644--- a/packages/context-engine/src/providers/__tests__/OnboardingActionHintInjector.test.ts+++ b/packages/context-engine/src/providers/__tests__/OnboardingActionHintInjector.test.ts@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';import type { PipelineContext } from '../../types';import { OnboardingActionHintInjector } from '../OnboardingActionHintInjector';+import type { OnboardingContext } from '../OnboardingContextInjector';const createContext = (messages: any[]): PipelineContext => ({initialState: { messages: [] },@@ -10,10 +11,11 @@ const createContext = (messages: any[]): PipelineContext => ({metadata: {},});-const buildProvider = (phaseGuidance: string) =>+const buildProvider = (phaseGuidance: string, context?: Partial<OnboardingContext>) =>new OnboardingActionHintInjector({enabled: true,onboardingContext: {+ ...context,personaContent: '# Persona',phaseGuidance,soulContent: '# SOUL',@@ -21,6 +23,46 @@ const buildProvider = (phaseGuidance: string) =>});describe('OnboardingActionHintInjector', () => {+ describe('discovery turn reminder', () => {+ const phaseGuidance = 'Phase: Discovery. Explore the user world.';++ it('injects current discovery progress when more discovery turns are recommended', async () => {+ const provider = buildProvider(phaseGuidance, {+ discoveryUserMessageCount: 1,+ remainingDiscoveryExchanges: 2,+ });+ const result = await provider.process(+ createContext([+ { content: 'sys', role: 'system' },+ { content: 'I mostly write docs', role: 'user' },+ ]),+ );++ const last = result.messages.at(-1);+ expect(last?.content).toContain('SYSTEM REMINDER: Current Discovery turn status');+ expect(last?.content).toContain('User discovery exchanges observed: 1');+ expect(last?.content).toContain('Recommended target before Summary: 3');+ expect(last?.content).toContain('Continue Discovery for about 2 more user exchange(s)');+ });++ it('reminds the model to move toward summary after the recommended target is reached', async () => {+ const provider = buildProvider(phaseGuidance, {+ discoveryUserMessageCount: 3,+ remainingDiscoveryExchanges: 0,+ });+ const result = await provider.process(+ createContext([+ { content: 'sys', role: 'system' },+ { content: 'I need help with planning and writing', role: 'user' },+ ]),+ );++ const last = result.messages.at(-1);+ expect(last?.content).toContain('Recommended Discovery target has been reached');+ expect(last?.content).toContain('transition to Summary');+ });+ });+describe('marketplace detection (Summary phase)', () => {const phaseGuidance = 'Phase: Summary. Wrap-up.';diff --git a/src/server/modules/AgentRuntime/RuntimeExecutors.ts b/src/server/modules/AgentRuntime/RuntimeExecutors.tsindex 415877f5157..feae2b82df3 100644--- a/src/server/modules/AgentRuntime/RuntimeExecutors.ts+++ b/src/server/modules/AgentRuntime/RuntimeExecutors.ts@@ -484,8 +484,10 @@ export const createRuntimeExecutors = (]);onboardingContext = {+ discoveryUserMessageCount: onboardingState.discoveryUserMessageCount,personaContent: persona?.persona ?? null,phaseGuidance: formatWebOnboardingStateMessage(onboardingState),+ remainingDiscoveryExchanges: onboardingState.remainingDiscoveryExchanges,soulContent: soulDoc?.content ?? null,userInfo,};diff --git a/src/server/routers/lambda/user.ts b/src/server/routers/lambda/user.tsindex d790ebcf2ce..57f988b11e5 100644--- a/src/server/routers/lambda/user.ts+++ b/src/server/routers/lambda/user.ts@@ -272,8 +272,10 @@ export const userRouter = router({]);return {+ discoveryUserMessageCount: state.discoveryUserMessageCount,personaContent: persona?.persona || null,phaseGuidance: formatWebOnboardingStateMessage(state),+ remainingDiscoveryExchanges: state.remainingDiscoveryExchanges,soulContent: soulDoc?.content || null,userInfo,};diff --git a/src/utils/webOnboardingToolResult.test.ts b/src/utils/webOnboardingToolResult.test.tsindex 820bb4be692..f795d2abc4a 100644--- a/src/utils/webOnboardingToolResult.test.ts+++ b/src/utils/webOnboardingToolResult.test.ts@@ -48,11 +48,12 @@ describe('web onboarding tool result helpers', () => {version: 1,});+ expect(message).toContain('Discovery progress: 1/4 user exchange(s) observed');expect(message).toContain('Recommended: 3 more user exchange(s) before moving to summary.');expect(message).toContain('Phase: Discovery');});- it('omits pacing hint when remaining discovery exchanges is 0', () => {+ it('formats target-reached discovery progress when remaining discovery exchanges is 0', () => {const message = formatWebOnboardingStateMessage({discoveryUserMessageCount: 4,finished: false,@@ -64,5 +65,8 @@ describe('web onboarding tool result helpers', () => {});expect(message).not.toContain('more user exchange(s) before moving to summary');+ expect(message).toContain(+ 'Discovery progress: recommended target reached after 4 user exchange(s).',+ );});});