Warn about confusing agent tool catalogs
This commit is contained in:
@@ -316,6 +316,17 @@
|
||||
<span class="drawer-section-count" x-text="tfKey('agents.drawer.selected', { count: form.selectedOps.length })"></span>
|
||||
</div>
|
||||
<div class="drawer-section-sub" x-text="operationsSubText()">Select the MCP tools available to this agent.</div>
|
||||
<div class="agents-rec-callout" x-show="agentToolFindings.length > 0" style="display:none; margin-bottom: 12px;">
|
||||
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="8" cy="8" r="7"/><path d="M8 4.5v4M8 11.5v.2"/>
|
||||
</svg>
|
||||
<div>
|
||||
<strong data-i18n="agents.drawer.finding.title">Recommendation</strong>
|
||||
<template x-for="finding in agentToolFindings" :key="finding">
|
||||
<div x-text="finding"></div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ops-picker">
|
||||
<!-- Search -->
|
||||
|
||||
@@ -195,6 +195,35 @@ document.addEventListener('alpine:init', function() {
|
||||
return this.tKey(this.isCommunityBuild ? 'agents.drawer.operations_sub_community' : 'agents.drawer.operations_sub');
|
||||
},
|
||||
|
||||
get selectedOperations() {
|
||||
var selected = this.form.selectedOps;
|
||||
return this.operations.filter(function(operation) {
|
||||
return selected.includes(operation.id);
|
||||
});
|
||||
},
|
||||
|
||||
get agentToolFindings() {
|
||||
var findings = [];
|
||||
var selected = this.selectedOperations;
|
||||
if (selected.length > 8) {
|
||||
findings.push(this.tKey('agents.drawer.finding.too_many_tools'));
|
||||
}
|
||||
|
||||
for (var leftIndex = 0; leftIndex < selected.length; leftIndex += 1) {
|
||||
for (var rightIndex = leftIndex + 1; rightIndex < selected.length; rightIndex += 1) {
|
||||
if (this.operationsLookSimilar(selected[leftIndex], selected[rightIndex])) {
|
||||
findings.push(this.tfKey('agents.drawer.finding.similar_tools', {
|
||||
left: selected[leftIndex].display_name || selected[leftIndex].name,
|
||||
right: selected[rightIndex].display_name || selected[rightIndex].name,
|
||||
}));
|
||||
return findings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return findings;
|
||||
},
|
||||
|
||||
get filteredOps() {
|
||||
var query = this.opSearch.toLowerCase().trim();
|
||||
if (!query) return this.operations;
|
||||
@@ -267,6 +296,28 @@ document.addEventListener('alpine:init', function() {
|
||||
return this.form.selectedOps.includes(operationId);
|
||||
},
|
||||
|
||||
operationsLookSimilar(left, right) {
|
||||
var leftTokens = this.operationTokens(left);
|
||||
var rightTokens = this.operationTokens(right);
|
||||
if (!leftTokens.length || !rightTokens.length) return false;
|
||||
var shared = leftTokens.filter(function(token) { return rightTokens.includes(token); }).length;
|
||||
var smaller = Math.min(leftTokens.length, rightTokens.length);
|
||||
return shared >= 2 && (shared / smaller) >= 0.6;
|
||||
},
|
||||
|
||||
operationTokens(operation) {
|
||||
var text = [
|
||||
operation.name || '',
|
||||
operation.display_name || '',
|
||||
].join(' ').toLowerCase();
|
||||
var tokens = [];
|
||||
text.split(/[^a-z0-9а-яё]+/i).forEach(function(token) {
|
||||
if (token.length < 3 || tokens.includes(token)) return;
|
||||
tokens.push(token);
|
||||
});
|
||||
return tokens;
|
||||
},
|
||||
|
||||
async saveAgent() {
|
||||
var self = this;
|
||||
if (
|
||||
|
||||
@@ -765,6 +765,9 @@ var TRANSLATIONS = {
|
||||
'agents.drawer.selected': '{count} selected',
|
||||
'agents.drawer.operations_sub': 'Select the MCP tools available to this agent.',
|
||||
'agents.drawer.operations_sub_community': 'Select the MCP tools available to this agent.',
|
||||
'agents.drawer.finding.title': 'Recommendation',
|
||||
'agents.drawer.finding.too_many_tools': 'This agent has many tools. Keep only the tools needed for one concrete task.',
|
||||
'agents.drawer.finding.similar_tools': 'Tools “{left}” and “{right}” look similar. Rename them more precisely or keep one of them.',
|
||||
'agents.drawer.filter_ops': 'Filter operations…',
|
||||
'agents.drawer.ops_no_match': 'No operations match "{query}"',
|
||||
'agents.drawer.ops_selected': '{count} operations selected',
|
||||
@@ -1577,6 +1580,9 @@ var TRANSLATIONS = {
|
||||
'agents.drawer.selected': 'Выбрано: {count}',
|
||||
'agents.drawer.operations_sub': 'Выберите MCP инструменты, которые будут доступны для этого агента.',
|
||||
'agents.drawer.operations_sub_community': 'Выберите MCP инструменты, которые будут доступны для этого агента.',
|
||||
'agents.drawer.finding.title': 'Рекомендация',
|
||||
'agents.drawer.finding.too_many_tools': 'У агента выбрано много инструментов. Оставьте только те, которые нужны для одной конкретной задачи.',
|
||||
'agents.drawer.finding.similar_tools': 'Инструменты «{left}» и «{right}» похожи. Переименуйте их точнее или оставьте один вариант.',
|
||||
'agents.drawer.filter_ops': 'Фильтр операций…',
|
||||
'agents.drawer.ops_no_match': 'Нет операций по запросу "{query}"',
|
||||
'agents.drawer.ops_selected': 'Выбрано операций: {count}',
|
||||
|
||||
Reference in New Issue
Block a user