🤯 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(agent-manager): guard createAgent against LLM double-encoded array fields (#15381)
LiJian4d030e9db17b
diff --git a/packages/agent-manager-runtime/src/AgentManagerRuntime.ts b/packages/agent-manager-runtime/src/AgentManagerRuntime.tsindex 3cac0bdc66b..b86aba40df5 100644--- a/packages/agent-manager-runtime/src/AgentManagerRuntime.ts+++ b/packages/agent-manager-runtime/src/AgentManagerRuntime.ts@@ -78,17 +78,30 @@ export class AgentManagerRuntime {*/async createAgent(params: CreateAgentParams): Promise<BuiltinToolResult> {try {+ // Guard against LLM double-encoding: if array fields are JSON strings, parse them.+ // Use `as any` to bypass TS narrowing — at runtime LLMs can send strings for typed array params.+ const parseArrayParam = (v: any): string[] | undefined => {+ if (typeof v === 'string') {+ try {+ return JSON.parse(v);+ } catch {+ return undefined;+ }+ }+ return v;+ };+const config = {avatar: params.avatar,backgroundColor: params.backgroundColor,description: params.description,model: params.model,openingMessage: params.openingMessage,- openingQuestions: params.openingQuestions,- plugins: params.plugins,+ openingQuestions: parseArrayParam(params.openingQuestions),+ plugins: parseArrayParam(params.plugins),provider: params.provider,systemRole: params.systemRole,- tags: params.tags,+ tags: parseArrayParam(params.tags),title: params.title,};diff --git a/src/server/services/toolExecution/serverRuntimes/agentManagement.ts b/src/server/services/toolExecution/serverRuntimes/agentManagement.tsindex 6101282ded3..10d50b6794a 100644--- a/src/server/services/toolExecution/serverRuntimes/agentManagement.ts+++ b/src/server/services/toolExecution/serverRuntimes/agentManagement.ts@@ -61,17 +61,29 @@ export const agentManagementRuntime: ServerRuntimeRegistration = {createAgent: async (params: CreateAgentParams): Promise<ToolExecutionResult> => {try {+ // Guard against LLM double-encoding: if array fields are JSON strings, parse them.+ const parseArrayParam = (v: any): string[] | undefined => {+ if (typeof v === 'string') {+ try {+ return JSON.parse(v);+ } catch {+ return undefined;+ }+ }+ return v;+ };+const agent = await agentModel.create({avatar: params.avatar,backgroundColor: params.backgroundColor,description: params.description,model: params.model,openingMessage: params.openingMessage,- openingQuestions: params.openingQuestions,- plugins: params.plugins,+ openingQuestions: parseArrayParam(params.openingQuestions),+ plugins: parseArrayParam(params.plugins),provider: params.provider,systemRole: params.systemRole,- tags: params.tags,+ tags: parseArrayParam(params.tags),title: params.title,});