@xuda.io/ai_module 1.1.5423 → 1.1.5424

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.mjs +46 -14
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -11259,35 +11259,36 @@ export const get_chat_suggestions = async function (req) {
11259
11259
  };
11260
11260
 
11261
11261
  const get_suggestions = async function () {
11262
+ const availableAgentIds = new Set(agents_docs.map((agent) => agent.agent_id));
11262
11263
  const AgentItemSchema = z.object({
11263
11264
  type: z.literal('agent').describe('Constant identifier, always "agent"'),
11264
11265
  agent_id: z.string().describe('The unique identifier for the agent'),
11265
11266
  short_action: z.string().describe('A brief, 2-4 word call to action'),
11266
11267
  agent_description: z.string().describe("A professional description of the agent's capabilities"),
11268
+ relevance_score: z.number().min(0).max(100).describe('How strongly this agent matches the current conversation state'),
11267
11269
  });
11268
11270
 
11269
- // Define the response format as a fixed-length array of 5
11270
11271
  const AgentResponseSchema = z.object({
11271
11272
  agents: z.array(AgentItemSchema).max(no_of_suggestions),
11272
11273
  });
11273
- //${conversation_item_doc.text}
11274
- // Prompt Category: ${conversation_doc?.category_info?.category}
11275
- // Input: ${conversation_item_doc.prompt || conversation_doc.prompt}
11276
- // Format Compatibility: Analyze the ## Prompt Response. If it contains code, data structures, or specific document types (like HTML), prioritize agents whose agent_instructions or agent_name or agent instructions involve processing, transforming, or styling that specific format.
11277
-
11278
- // Workflow Continuity: Choose agents that represent a logical "next step" in a development or content creation pipeline (e.g., if code was generated, suggest an agent that deploys, converts, or styles it).
11279
- // Input: ${conversation_item_doc.prompt || conversation_doc.prompt}
11280
- // Contextual Relevance: Balance the selection with the ## User Info and ## Prompt Category to ensure the agents match the user's industry and intent.
11281
11274
 
11282
11275
  const prompt = `
11283
11276
 
11284
11277
  Role: You are an expert Routing Assistant specialized in connecting users with the most relevant specialized AI agents.
11285
- Task: Select maximum ${no_of_suggestions} agents from the ## Agent List that are best suited to act upon or refine the current conversation state.
11278
+ Task: Select up to ${no_of_suggestions} agents from the ## Agent List that are genuinely well suited to act upon or refine the current conversation state.
11279
+
11280
+ Important Rules:
11281
+ 1. Return fewer than ${no_of_suggestions} agents when only a few are relevant.
11282
+ 2. Return an empty array when none of the agents are a strong match.
11283
+ 3. Do not fill the list just to reach ${no_of_suggestions}.
11284
+ 4. Only include an agent when its relevance_score is 70 or higher.
11285
+ 5. Never invent agent ids. Use only ids from the ## Agent Source.
11286
11286
 
11287
11287
  Selection Strategy:
11288
11288
  1. Format Compatibility: Analyze the ## ${type} to Process. If it contains structured JSON, component definitions, or raw HTML, prioritize agents capable of transforming these formats (e.g., converting HTML/JSON to functional apps).
11289
11289
  2. Workflow Continuity: Focus on the "Lifecycle" of the project. If a UI or content has been drafted, the logical next step is conversion to a production-ready format, styling, or deployment.
11290
- 3. Contextual Relevance: Match the user's business profile (Digital Marketing & Web Development) with technical agents that automate development tasks.
11290
+ 3. Contextual Relevance: Match the user's business profile and prompt category only when they materially improve the fit.
11291
+ 4. Reject generic or weakly related agents. If the match is ambiguous, leave the agent out.
11291
11292
 
11292
11293
 
11293
11294
  ## ${type}: ${context ? context : 'Use the previous response output as the content to analyze for next agents.'}
@@ -11300,10 +11301,10 @@ export const get_chat_suggestions = async function (req) {
11300
11301
  Agent Source: ${JSON.stringify(agents_docs)}
11301
11302
 
11302
11303
  Output: > Return a JSON array of maximum ${no_of_suggestions} objects following this schema:
11303
- [{ "type":"string","agent_id": "string", "short_action": "string", "agent_description": "string" }]
11304
+ [{ "type":"agent","agent_id": "string", "short_action": "string", "agent_description": "string", "relevance_score": 0 }]
11304
11305
 
11305
11306
  ## output example:
11306
- [{"type":"agent",agent_id:"392_agn_55cb328d2743",short_action:"Create article","agent_description":"create proffessional article..."}]
11307
+ [{"type":"agent","agent_id":"392_agn_55cb328d2743","short_action":"Create article","agent_description":"Creates a polished article from the current draft.","relevance_score":91}]
11307
11308
 
11308
11309
  `;
11309
11310
 
@@ -11323,7 +11324,38 @@ export const get_chat_suggestions = async function (req) {
11323
11324
  const chat_ret = await submit_chat_gpt_prompt(opt);
11324
11325
  try {
11325
11326
  const ret = JSON5.parse(chat_ret.data);
11326
- return ret.agents;
11327
+ if (!Array.isArray(ret?.agents)) {
11328
+ return [];
11329
+ }
11330
+
11331
+ const seen = new Set();
11332
+
11333
+ return ret.agents
11334
+ .filter((agent) => {
11335
+ if (!agent || agent.type !== 'agent') {
11336
+ return false;
11337
+ }
11338
+ if (!availableAgentIds.has(agent.agent_id)) {
11339
+ return false;
11340
+ }
11341
+ if (seen.has(agent.agent_id)) {
11342
+ return false;
11343
+ }
11344
+ if (typeof agent.relevance_score !== 'number' || agent.relevance_score < 70) {
11345
+ return false;
11346
+ }
11347
+ const short_action = agent.short_action?.trim();
11348
+ const agent_description = agent.agent_description?.trim();
11349
+ if (!short_action || !agent_description) {
11350
+ return false;
11351
+ }
11352
+
11353
+ seen.add(agent.agent_id);
11354
+ return true;
11355
+ })
11356
+ .sort((a, b) => b.relevance_score - a.relevance_score)
11357
+ .slice(0, no_of_suggestions)
11358
+ .map(({ relevance_score, ...agent }) => agent);
11327
11359
  } catch (error) {
11328
11360
  return [];
11329
11361
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.5423",
3
+ "version": "1.1.5424",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",