@xuda.io/ai_module 1.1.5423 → 1.1.5425
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.
- package/index.mjs +49 -15
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -11191,7 +11191,7 @@ export const get_chat_suggestions = async function (req) {
|
|
|
11191
11191
|
const conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_item_doc.conversation_id);
|
|
11192
11192
|
|
|
11193
11193
|
if (conversation_item_doc.prompt_suggestions) {
|
|
11194
|
-
exclude_agents = conversation_item_doc.prompt_suggestions.map((agent) => agent.agent_id);
|
|
11194
|
+
exclude_agents = [...new Set([...exclude_agents, ...conversation_item_doc.prompt_suggestions.map((agent) => agent.agent_id)])];
|
|
11195
11195
|
}
|
|
11196
11196
|
|
|
11197
11197
|
const get_agents = async function () {
|
|
@@ -11259,35 +11259,37 @@ 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
|
|
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
|
+
6. Never return any agent whose id appears in ## Excluded Agent IDs.
|
|
11286
11287
|
|
|
11287
11288
|
Selection Strategy:
|
|
11288
11289
|
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
11290
|
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
|
|
11291
|
+
3. Contextual Relevance: Match the user's business profile and prompt category only when they materially improve the fit.
|
|
11292
|
+
4. Reject generic or weakly related agents. If the match is ambiguous, leave the agent out.
|
|
11291
11293
|
|
|
11292
11294
|
|
|
11293
11295
|
## ${type}: ${context ? context : 'Use the previous response output as the content to analyze for next agents.'}
|
|
@@ -11296,14 +11298,15 @@ export const get_chat_suggestions = async function (req) {
|
|
|
11296
11298
|
|
|
11297
11299
|
User Profile: ${JSON.stringify(account_doc.account_info)}
|
|
11298
11300
|
Prompt Category: ${conversation_doc?.category_info?.category}
|
|
11301
|
+
Excluded Agent IDs: ${JSON.stringify(exclude_agents)}
|
|
11299
11302
|
|
|
11300
11303
|
Agent Source: ${JSON.stringify(agents_docs)}
|
|
11301
11304
|
|
|
11302
11305
|
Output: > Return a JSON array of maximum ${no_of_suggestions} objects following this schema:
|
|
11303
|
-
[{ "type":"
|
|
11306
|
+
[{ "type":"agent","agent_id": "string", "short_action": "string", "agent_description": "string", "relevance_score": 0 }]
|
|
11304
11307
|
|
|
11305
11308
|
## output example:
|
|
11306
|
-
[{"type":"agent",agent_id:"392_agn_55cb328d2743",short_action:"Create article","agent_description":"
|
|
11309
|
+
[{"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
11310
|
|
|
11308
11311
|
`;
|
|
11309
11312
|
|
|
@@ -11323,7 +11326,38 @@ export const get_chat_suggestions = async function (req) {
|
|
|
11323
11326
|
const chat_ret = await submit_chat_gpt_prompt(opt);
|
|
11324
11327
|
try {
|
|
11325
11328
|
const ret = JSON5.parse(chat_ret.data);
|
|
11326
|
-
|
|
11329
|
+
if (!Array.isArray(ret?.agents)) {
|
|
11330
|
+
return [];
|
|
11331
|
+
}
|
|
11332
|
+
|
|
11333
|
+
const seen = new Set();
|
|
11334
|
+
|
|
11335
|
+
return ret.agents
|
|
11336
|
+
.filter((agent) => {
|
|
11337
|
+
if (!agent || agent.type !== 'agent') {
|
|
11338
|
+
return false;
|
|
11339
|
+
}
|
|
11340
|
+
if (!availableAgentIds.has(agent.agent_id)) {
|
|
11341
|
+
return false;
|
|
11342
|
+
}
|
|
11343
|
+
if (seen.has(agent.agent_id)) {
|
|
11344
|
+
return false;
|
|
11345
|
+
}
|
|
11346
|
+
if (typeof agent.relevance_score !== 'number' || agent.relevance_score < 70) {
|
|
11347
|
+
return false;
|
|
11348
|
+
}
|
|
11349
|
+
const short_action = agent.short_action?.trim();
|
|
11350
|
+
const agent_description = agent.agent_description?.trim();
|
|
11351
|
+
if (!short_action || !agent_description) {
|
|
11352
|
+
return false;
|
|
11353
|
+
}
|
|
11354
|
+
|
|
11355
|
+
seen.add(agent.agent_id);
|
|
11356
|
+
return true;
|
|
11357
|
+
})
|
|
11358
|
+
.sort((a, b) => b.relevance_score - a.relevance_score)
|
|
11359
|
+
.slice(0, no_of_suggestions)
|
|
11360
|
+
.map(({ relevance_score, ...agent }) => agent);
|
|
11327
11361
|
} catch (error) {
|
|
11328
11362
|
return [];
|
|
11329
11363
|
}
|