Adicionar delegação automática entre agentes coordenadores
This commit is contained in:
@@ -852,6 +852,16 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="agent-delegate-to">Delegar para (auto)</label>
|
||||
<select class="select" id="agent-delegate-to" name="delegateTo">
|
||||
<option value="">Nenhum</option>
|
||||
</select>
|
||||
<p class="form-hint">Ao concluir, delega automaticamente o resultado para este agente.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Retry em caso de falha</label>
|
||||
|
||||
@@ -192,6 +192,8 @@ const AgentsUI = {
|
||||
const retryMax = document.getElementById('agent-retry-max');
|
||||
if (retryMax) retryMax.value = '3';
|
||||
|
||||
AgentsUI._populateDelegateSelect('');
|
||||
|
||||
const secretsSection = document.getElementById('agent-secrets-section');
|
||||
if (secretsSection) secretsSection.hidden = true;
|
||||
|
||||
@@ -250,6 +252,8 @@ const AgentsUI = {
|
||||
const retryMax = document.getElementById('agent-retry-max');
|
||||
if (retryMax) retryMax.value = (agent.config && agent.config.maxRetries) || '3';
|
||||
|
||||
AgentsUI._populateDelegateSelect(agent.config?.delegateTo || '', agent.id);
|
||||
|
||||
const secretsSection = document.getElementById('agent-secrets-section');
|
||||
if (secretsSection) secretsSection.hidden = false;
|
||||
|
||||
@@ -296,6 +300,7 @@ const AgentsUI = {
|
||||
permissionMode: document.getElementById('agent-permission-mode')?.value || '',
|
||||
retryOnFailure: !!document.getElementById('agent-retry-toggle')?.checked,
|
||||
maxRetries: parseInt(document.getElementById('agent-retry-max')?.value) || 3,
|
||||
delegateTo: document.getElementById('agent-delegate-to')?.value || '',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -468,6 +473,14 @@ const AgentsUI = {
|
||||
});
|
||||
},
|
||||
|
||||
_populateDelegateSelect(currentValue, excludeId) {
|
||||
const select = document.getElementById('agent-delegate-to');
|
||||
if (!select) return;
|
||||
const activeAgents = AgentsUI.agents.filter(a => a.status === 'active' && a.id !== excludeId);
|
||||
select.innerHTML = '<option value="">Nenhum</option>' +
|
||||
activeAgents.map(a => `<option value="${a.id}" ${a.id === currentValue ? 'selected' : ''}>${Utils.escapeHtml(a.agent_name || a.name)}</option>`).join('');
|
||||
},
|
||||
|
||||
_setupModalListeners() {
|
||||
const retryToggle = document.getElementById('agent-retry-toggle');
|
||||
const retryMaxGroup = document.getElementById('agent-retry-max-group');
|
||||
|
||||
@@ -172,9 +172,17 @@ export function executeTask(agentId, task, instructions, wsCallback, metadata =
|
||||
|
||||
const agentSecrets = loadAgentSecrets(agentId);
|
||||
|
||||
let effectiveInstructions = instructions || '';
|
||||
const tags = agent.tags || [];
|
||||
if (tags.includes('coordinator')) {
|
||||
const allAgents = agentsStore.getAll().filter(a => a.id !== agentId && a.status === 'active');
|
||||
const agentList = allAgents.map(a => `- **${a.agent_name}**: ${a.description || 'Sem descrição'}`).join('\n');
|
||||
effectiveInstructions += `\n\n<agentes_disponiveis>\n${agentList}\n</agentes_disponiveis>`;
|
||||
}
|
||||
|
||||
const executionId = executor.execute(
|
||||
agent.config,
|
||||
{ description: task, instructions },
|
||||
{ description: task, instructions: effectiveInstructions },
|
||||
{
|
||||
onData: (parsed, execId) => {
|
||||
if (cb) cb({ type: 'execution_output', executionId: execId, agentId, data: parsed });
|
||||
@@ -234,6 +242,32 @@ export function executeTask(agentId, task, instructions, wsCallback, metadata =
|
||||
}
|
||||
} catch (e) { console.error('[manager] Erro ao gerar relatório:', e.message); }
|
||||
if (cb) cb({ type: 'execution_complete', executionId: execId, agentId, data: result });
|
||||
|
||||
const isPipelineStep = !!metadata.pipelineExecutionId;
|
||||
const delegateTo = agent.config?.delegateTo;
|
||||
if (!isPipelineStep && delegateTo && result.result) {
|
||||
const delegateAgent = agentsStore.getById(delegateTo);
|
||||
if (delegateAgent && delegateAgent.status === 'active') {
|
||||
console.log(`[manager] Auto-delegando de "${agent.agent_name}" para "${delegateAgent.agent_name}"`);
|
||||
if (cb) cb({
|
||||
type: 'execution_output',
|
||||
executionId: execId,
|
||||
agentId,
|
||||
data: { type: 'system', content: `Delegando para ${delegateAgent.agent_name}...` },
|
||||
});
|
||||
setTimeout(() => {
|
||||
try {
|
||||
executeTask(delegateTo, result.result, null, wsCallback, {
|
||||
delegatedFrom: agent.agent_name,
|
||||
originalTask: taskText,
|
||||
});
|
||||
} catch (delegateErr) {
|
||||
console.error(`[manager] Erro ao delegar para "${delegateAgent.agent_name}":`, delegateErr.message);
|
||||
if (cb) cb({ type: 'execution_error', executionId: execId, agentId: delegateTo, data: { error: delegateErr.message } });
|
||||
}
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
agentSecrets
|
||||
|
||||
Reference in New Issue
Block a user