🤯 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): enforce response language in server runtime (#14793)
Innei9fb3038615c8
diff --git a/src/server/services/aiAgent/__tests__/execAgent.builtinRuntime.test.ts b/src/server/services/aiAgent/__tests__/execAgent.builtinRuntime.test.tsindex 71f19343fc9..b06402b0091 100644--- a/src/server/services/aiAgent/__tests__/execAgent.builtinRuntime.test.ts+++ b/src/server/services/aiAgent/__tests__/execAgent.builtinRuntime.test.ts@@ -11,6 +11,7 @@ import { AiAgentService } from '../index';const {mockCreateOperation,mockGetAgentConfig,+ mockGetInfoForAIGeneration,mockIsAgentSignalEnabledForUser,mockMessageCreate,mockMessageQuery,@@ -19,6 +20,7 @@ const {} = vi.hoisted(() => ({mockCreateOperation: vi.fn(),mockGetAgentConfig: vi.fn(),+ mockGetInfoForAIGeneration: vi.fn(),mockIsAgentSignalEnabledForUser: vi.fn(),mockMessageCreate: vi.fn(),mockMessageQuery: vi.fn(),@@ -98,6 +100,12 @@ vi.mock('@/database/models/thread', () => ({})),}));+vi.mock('@/database/models/user', () => ({+ UserModel: {+ getInfoForAIGeneration: mockGetInfoForAIGeneration,+ },+}));+vi.mock('@/database/models/task', () => ({TaskModel: vi.fn().mockImplementation(() => ({resolve: mockResolveTask,@@ -179,6 +187,10 @@ describe('AiAgentService.execAgent - builtin agent runtime config', () => {mockMessageQuery.mockResolvedValue([]);mockIsAgentSignalEnabledForUser.mockResolvedValue(true);mockResolveTask.mockResolvedValue(null);+ mockGetInfoForAIGeneration.mockResolvedValue({+ responseLanguage: 'en-US',+ userName: 'Test User',+ });mockToolsEnv.VISUAL_UNDERSTANDING_MODEL = 'vision-model';mockToolsEnv.VISUAL_UNDERSTANDING_PROVIDER = 'test-provider';mockCreateOperation.mockResolvedValue({@@ -214,6 +226,33 @@ describe('AiAgentService.execAgent - builtin agent runtime config', () => {expect(callArgs.agentConfig.systemRole).toContain('{{model}}');});+ it('should pass user response language into web onboarding runtime systemRole', async () => {+ mockGetInfoForAIGeneration.mockResolvedValue({+ responseLanguage: 'zh-CN',+ userName: 'Test User',+ });+ mockGetAgentConfig.mockResolvedValue({+ chatConfig: {},+ id: 'agent-web-onboarding',+ model: 'gpt-4',+ plugins: [],+ provider: 'openai',+ slug: 'web-onboarding',+ systemRole: '',+ });++ await service.execAgent({+ agentId: 'agent-web-onboarding',+ prompt: '你好',+ });++ const callArgs = mockCreateOperation.mock.calls[0][0];+ expect(callArgs.agentConfig.systemRole).toContain('Preferred reply language: zh-CN');+ expect(callArgs.agentConfig.systemRole).toContain(+ 'Every visible reply, question, and visible choice label must be entirely in zh-CN',+ );+ });+it('should NOT override user-customized systemRole for inbox agent', async () => {const customSystemRole = 'You are a custom assistant.';mockGetAgentConfig.mockResolvedValue({diff --git a/src/server/services/aiAgent/index.ts b/src/server/services/aiAgent/index.tsindex 325350ce83e..88334c95c15 100644--- a/src/server/services/aiAgent/index.ts+++ b/src/server/services/aiAgent/index.ts@@ -406,9 +406,18 @@ export class AiAgentService {const agentSlug = agentConfig.slug;const builtinSlugs = Object.values(BUILTIN_AGENT_SLUGS) as string[];if (agentSlug && builtinSlugs.includes(agentSlug)) {+ let userLocale: string | undefined;+ try {+ const userInfo = await UserModel.getInfoForAIGeneration(this.db, this.userId);+ userLocale = userInfo.responseLanguage;+ } catch (error) {+ log('execAgent: failed to load user locale for builtin runtime config: %O', error);+ }+const runtimeConfig = getAgentRuntimeConfig(agentSlug, {model: agentConfig.model,plugins: agentConfig.plugins ?? [],+ userLocale,});if (runtimeConfig) {// Runtime systemRole takes effect only if DB has no user-customized systemRole