π€― 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
β»οΈ refactor(agent-signal): restore 3 mode-specific self-iteration agent slugs (#15202)
Arvin Xue0ead38c201c
diff --git a/packages/builtin-agents/src/agents/nightly-review/index.ts b/packages/builtin-agents/src/agents/nightly-review/index.tsnew file mode 100644index 00000000000..71b6ea608a0--- /dev/null+++ b/packages/builtin-agents/src/agents/nightly-review/index.ts@@ -0,0 +1,21 @@+import type { BuiltinAgentDefinition } from '../../types';+import { BUILTIN_AGENT_SLUGS } from '../../types';++/**+ * Nightly Review Agent β runs once per user-local day to inspect bounded review+ * evidence (topics, messages, tool calls, agent documents, managed skills) and+ * apply safe resource operations or create approval-gated self-review proposals.+ *+ * Tool surface (`agent-signal-review`) and per-mode adapters (review-specific+ * receipt table, idempotency namespace, brief projection) are registered in a+ * follow-up PR. Until then the agent runs with no tools β invoking it before+ * registration is dormant by design.+ */+export const NIGHTLY_REVIEW: BuiltinAgentDefinition = {+ runtime: {+ plugins: ['agent-signal-review'],+ systemRole:+ 'You are the nightly self-review agent. Inspect bounded review evidence and apply safe resource operations (memory, skill, proposal). Be concise and evidence-driven.',+ },+ slug: BUILTIN_AGENT_SLUGS.nightlyReview,+};diff --git a/packages/builtin-agents/src/agents/self-feedback-intent/index.ts b/packages/builtin-agents/src/agents/self-feedback-intent/index.tsnew file mode 100644index 00000000000..0f4b2ee4936--- /dev/null+++ b/packages/builtin-agents/src/agents/self-feedback-intent/index.ts@@ -0,0 +1,21 @@+import type { BuiltinAgentDefinition } from '../../types';+import { BUILTIN_AGENT_SLUGS } from '../../types';++/**+ * Self-Feedback-Intent Agent β handles explicit self-feedback intents declared+ * by another agent via `declareSelfFeedbackIntent`. Reads the cited evidence+ * and either applies a safe resource write or records the intent for later+ * nightly review.+ *+ * Tool surface (`agent-signal-feedback-intent`) and per-mode adapters+ * (feedback-intent receipt table, idempotency namespace) are registered in a+ * follow-up PR.+ */+export const SELF_FEEDBACK_INTENT: BuiltinAgentDefinition = {+ runtime: {+ plugins: ['agent-signal-feedback-intent'],+ systemRole:+ 'You are the self-feedback-intent agent. Act on an explicit feedback intent declared by another agent: read cited evidence, then either apply a safe write or record a follow-up intent. Be concise and evidence-driven.',+ },+ slug: BUILTIN_AGENT_SLUGS.selfFeedbackIntent,+};diff --git a/packages/builtin-agents/src/agents/self-iteration/index.ts b/packages/builtin-agents/src/agents/self-iteration/index.tsdeleted file mode 100644index c32219e6b8c..00000000000--- a/packages/builtin-agents/src/agents/self-iteration/index.ts+++ /dev/null@@ -1,21 +0,0 @@-import type { BuiltinAgentDefinition } from '../../types';-import { BUILTIN_AGENT_SLUGS } from '../../types';--const SELF_ITERATION_TOOL_IDENTIFIER = 'agent-signal-self-iteration';--/**- * Self-Iteration Agent - shared execAgent target for nightly review, post-turn- * reflection, and declared feedback intents.- *- * All three flows share the same tool surface (`agent-signal-self-iteration`);- * the mode-specific guidance is supplied per-call by the caller's prompt builder,- * so the agent itself stays neutral.- */-export const SELF_ITERATION: BuiltinAgentDefinition = {- runtime: {- plugins: [SELF_ITERATION_TOOL_IDENTIFIER],- systemRole:- 'You are the self-iteration agent. Follow the mode-specific instructions in the user prompt and apply safe resource operations using the provided self-iteration tools. Be concise and evidence-driven.',- },- slug: BUILTIN_AGENT_SLUGS.selfIteration,-};diff --git a/packages/builtin-agents/src/agents/self-reflection/index.ts b/packages/builtin-agents/src/agents/self-reflection/index.tsnew file mode 100644index 00000000000..d9d16e506c1--- /dev/null+++ b/packages/builtin-agents/src/agents/self-reflection/index.ts@@ -0,0 +1,19 @@+import type { BuiltinAgentDefinition } from '../../types';+import { BUILTIN_AGENT_SLUGS } from '../../types';++/**+ * Self-Reflection Agent β runs after a turn or scoped operation to inspect+ * immediate reflection evidence and either record a durable memory / skill+ * write or capture an advisory feedback intent for later nightly review.+ *+ * Tool surface (`agent-signal-reflection`) and per-mode adapters (reflection+ * receipt table, idempotency namespace) are registered in a follow-up PR.+ */+export const SELF_REFLECTION: BuiltinAgentDefinition = {+ runtime: {+ plugins: ['agent-signal-reflection'],+ systemRole:+ 'You are the post-turn self-reflection agent. Inspect bounded reflection evidence and record either a durable memory/skill write or an advisory feedback intent. Be concise and evidence-driven.',+ },+ slug: BUILTIN_AGENT_SLUGS.selfReflection,+};diff --git a/packages/builtin-agents/src/index.ts b/packages/builtin-agents/src/index.tsindex 681cde99b8a..211b30de4f7 100644--- a/packages/builtin-agents/src/index.ts+++ b/packages/builtin-agents/src/index.ts@@ -2,8 +2,10 @@ import { AGENT_BUILDER } from './agents/agent-builder';import { GROUP_AGENT_BUILDER } from './agents/group-agent-builder';import { GROUP_SUPERVISOR } from './agents/group-supervisor';import { INBOX } from './agents/inbox';+import { NIGHTLY_REVIEW } from './agents/nightly-review';import { PAGE_AGENT } from './agents/page-agent';-import { SELF_ITERATION } from './agents/self-iteration';+import { SELF_FEEDBACK_INTENT } from './agents/self-feedback-intent';+import { SELF_REFLECTION } from './agents/self-reflection';import { TASK_AGENT } from './agents/task-agent';import { WEB_ONBOARDING } from './agents/web-onboarding';import type { BuiltinAgentDefinition, BuiltinAgentSlug, RuntimeContext } from './types';@@ -16,8 +18,10 @@ export { AGENT_BUILDER } from './agents/agent-builder';export { GROUP_AGENT_BUILDER } from './agents/group-agent-builder';export { GROUP_SUPERVISOR } from './agents/group-supervisor';export { INBOX } from './agents/inbox';+export { NIGHTLY_REVIEW } from './agents/nightly-review';export { PAGE_AGENT } from './agents/page-agent';-export { SELF_ITERATION } from './agents/self-iteration';+export { SELF_FEEDBACK_INTENT } from './agents/self-feedback-intent';+export { SELF_REFLECTION } from './agents/self-reflection';export { TASK_AGENT } from './agents/task-agent';export { WEB_ONBOARDING } from './agents/web-onboarding';@@ -29,19 +33,25 @@ export const BUILTIN_AGENTS: Record<BuiltinAgentSlug, BuiltinAgentDefinition> =[BUILTIN_AGENT_SLUGS.groupAgentBuilder]: GROUP_AGENT_BUILDER,[BUILTIN_AGENT_SLUGS.groupSupervisor]: GROUP_SUPERVISOR,[BUILTIN_AGENT_SLUGS.inbox]: INBOX,+ [BUILTIN_AGENT_SLUGS.nightlyReview]: NIGHTLY_REVIEW,[BUILTIN_AGENT_SLUGS.pageAgent]: PAGE_AGENT,- [BUILTIN_AGENT_SLUGS.selfIteration]: SELF_ITERATION,+ [BUILTIN_AGENT_SLUGS.selfFeedbackIntent]: SELF_FEEDBACK_INTENT,+ [BUILTIN_AGENT_SLUGS.selfReflection]: SELF_REFLECTION,[BUILTIN_AGENT_SLUGS.taskAgent]: TASK_AGENT,[BUILTIN_AGENT_SLUGS.webOnboarding]: WEB_ONBOARDING,};/**- * Slugs that belong to the self-iteration family.- * Used by AgentSignal to skip re-triggering signal events- * for builtin background runs (suppressSignal behaviour).+ * Slugs that belong to the self-iteration family (nightly review, post-turn+ * reflection, and explicit feedback-intent handlers).+ * Used by AgentSignal to skip re-triggering signal events for builtin+ * background runs (suppressSignal behaviour) and by completion policies to+ * route post-execution side-effects.*/export const SELF_ITERATION_AGENT_SLUGS = new Set<BuiltinAgentSlug>([- BUILTIN_AGENT_SLUGS.selfIteration,+ BUILTIN_AGENT_SLUGS.nightlyReview,+ BUILTIN_AGENT_SLUGS.selfFeedbackIntent,+ BUILTIN_AGENT_SLUGS.selfReflection,]);/**diff --git a/packages/builtin-agents/src/types.ts b/packages/builtin-agents/src/types.tsindex 0e942574594..39f250223e3 100644--- a/packages/builtin-agents/src/types.ts+++ b/packages/builtin-agents/src/types.ts@@ -10,8 +10,10 @@ export const BUILTIN_AGENT_SLUGS = {groupAgentBuilder: 'group-agent-builder',groupSupervisor: 'group-supervisor',inbox: 'inbox',+ nightlyReview: 'nightly-review',pageAgent: 'page-agent',- selfIteration: 'self-iteration',+ selfFeedbackIntent: 'self-feedback-intent',+ selfReflection: 'self-reflection',taskAgent: 'task-agent',webOnboarding: 'web-onboarding',} as const;diff --git a/src/server/services/agentSignal/__tests__/suppressSignal.test.ts b/src/server/services/agentSignal/__tests__/suppressSignal.test.tsindex dfc729ccf08..cf8d4844a64 100644--- a/src/server/services/agentSignal/__tests__/suppressSignal.test.ts+++ b/src/server/services/agentSignal/__tests__/suppressSignal.test.ts@@ -9,8 +9,12 @@ describe('shouldSuppressSignal', () => {expect(shouldSuppressSignal({ appContext: { suppressSignal: true } })).toBe(true);});- it('returns true when slug is in SELF_ITERATION_AGENT_SLUGS', () => {- expect(shouldSuppressSignal({ slug: BUILTIN_AGENT_SLUGS.selfIteration })).toBe(true);+ it.each([+ [BUILTIN_AGENT_SLUGS.nightlyReview],+ [BUILTIN_AGENT_SLUGS.selfReflection],+ [BUILTIN_AGENT_SLUGS.selfFeedbackIntent],+ ])('returns true when slug is %s (member of SELF_ITERATION_AGENT_SLUGS)', (slug) => {+ expect(shouldSuppressSignal({ slug })).toBe(true);});it('returns false for ordinary user-facing slugs', () => {diff --git a/src/server/services/agentSignal/policies/completionPolicy.test.ts b/src/server/services/agentSignal/policies/completionPolicy.test.tsindex 3d3c3c36975..e165a7d2706 100644--- a/src/server/services/agentSignal/policies/completionPolicy.test.ts+++ b/src/server/services/agentSignal/policies/completionPolicy.test.ts@@ -40,7 +40,7 @@ describe('createCompletionPolicy', () => {await expect(handler.handle({payload: {- agentId: BUILTIN_AGENT_SLUGS.selfIteration,+ agentId: BUILTIN_AGENT_SLUGS.nightlyReview,operationId: 'op_1',},}),@@ -58,20 +58,24 @@ describe('createCompletionPolicy', () => {expect(onSelfIterationCompleted).not.toHaveBeenCalled();});- it('invokes the callback for self-iteration runs', async () => {+ it.each([+ [BUILTIN_AGENT_SLUGS.nightlyReview],+ [BUILTIN_AGENT_SLUGS.selfReflection],+ [BUILTIN_AGENT_SLUGS.selfFeedbackIntent],+ ])('invokes the callback for %s runs and forwards the agentId', async (slug) => {const onSelfIterationCompleted = vi.fn().mockResolvedValue(undefined);const [handler] = installAndCapture(createCompletionPolicy({ onSelfIterationCompleted }));await handler.handle({payload: {- agentId: BUILTIN_AGENT_SLUGS.selfIteration,+ agentId: slug,operationId: 'op_3',topicId: 'topic_3',},});expect(onSelfIterationCompleted).toHaveBeenCalledWith({- agentId: BUILTIN_AGENT_SLUGS.selfIteration,+ agentId: slug,operationId: 'op_3',topicId: 'topic_3',});@@ -86,7 +90,7 @@ describe('createCompletionPolicy', () => {await expect(handler.handle({payload: {- agentId: BUILTIN_AGENT_SLUGS.selfIteration,+ agentId: BUILTIN_AGENT_SLUGS.nightlyReview,operationId: 'op_4',},}),@@ -101,7 +105,7 @@ describe('createCompletionPolicy', () => {const [handler] = installAndCapture(createCompletionPolicy({ onSelfIterationCompleted }));await handler.handle({ payload: { operationId: 'op_5' } });- await handler.handle({ payload: { agentId: BUILTIN_AGENT_SLUGS.selfIteration } });+ await handler.handle({ payload: { agentId: BUILTIN_AGENT_SLUGS.nightlyReview } });expect(onSelfIterationCompleted).not.toHaveBeenCalled();});diff --git a/src/server/services/agentSignal/policies/completionPolicy.ts b/src/server/services/agentSignal/policies/completionPolicy.tsindex 5c36b52f7d7..92560ee6b8a 100644--- a/src/server/services/agentSignal/policies/completionPolicy.ts+++ b/src/server/services/agentSignal/policies/completionPolicy.ts@@ -1,17 +1,19 @@import { AGENT_SIGNAL_SOURCE_TYPES } from '@lobechat/agent-signal/source';-import { BUILTIN_AGENT_SLUGS } from '@lobechat/builtin-agents';+import type { BuiltinAgentSlug } from '@lobechat/builtin-agents';+import { SELF_ITERATION_AGENT_SLUGS } from '@lobechat/builtin-agents';import { defineAgentSignalHandlers, defineSourceHandler } from '../runtime/middleware';/*** Handles `agent.execution.completed` source events emitted after every execAgent run- * (including builtin background agents). Routes builtin self-iteration runs to an- * optional caller callback so side-effects (brief writing, receipt projection,+ * (including builtin background agents). Routes builtin self-iteration runs+ * (nightly-review / self-reflection / self-feedback-intent) to an optional+ * caller callback so side-effects (brief writing, receipt projection,* idempotency marker) can happen asynchronously after the agent run finishes.*- * Mode-specific dispatch (review / reflection / feedback) is deferred β the- * caller can demultiplex by looking up the operation row and inspecting the- * stored scope / iteration mode at callback time.+ * Mode is carried by `agentId` itself β each self-iteration mode is a distinct+ * builtin agent slug, so callers can dispatch on `agentId` without needing to+ * read the operation row.** The callback is fire-and-forget from the worker's perspective; failures are* logged but never re-trigger the source pipeline.@@ -21,14 +23,18 @@ import { defineAgentSignalHandlers, defineSourceHandler } from '../runtime/middl* that need userId should look it up via the operations table by `operationId`.*/export interface CompletionCallbackParams {- agentId: string;+ /** Self-iteration agent slug β caller dispatches mode-specific behaviour from this. */+ agentId: BuiltinAgentSlug;operationId: string;/** Optional topic id forwarded from the source payload. */topicId?: string;}export interface CreateCompletionPolicyOptions {- /** Called when a self-iteration run completes (any mode: review / reflection / feedback). */+ /**+ * Called when a self-iteration run completes. `params.agentId` identifies+ * which mode (nightly-review / self-reflection / self-feedback-intent) ran.+ */onSelfIterationCompleted?: (params: CompletionCallbackParams) => Promise<void>;}@@ -41,11 +47,11 @@ export const createCompletionPolicy = (options: CreateCompletionPolicyOptions =const { agentId, operationId, topicId } = source.payload;if (!agentId || !operationId) return;- if (agentId !== BUILTIN_AGENT_SLUGS.selfIteration) return;+ if (!SELF_ITERATION_AGENT_SLUGS.has(agentId as BuiltinAgentSlug)) return;if (!options.onSelfIterationCompleted) return;const params: CompletionCallbackParams = {- agentId,+ agentId: agentId as BuiltinAgentSlug,operationId,...(topicId ? { topicId } : {}),};