158 lines
5.7 KiB
Markdown
158 lines
5.7 KiB
Markdown
---
|
|
name: delegate
|
|
description: Delegação inteligente de tarefas para sub-agentes especializados. Analisa requisitos e encaminha para o agente adequado com contexto. Usar quando "delegate", "delegar", "subagent", "ajuda especializada", ou análises multi-domínio complexas.
|
|
layer: wiki
|
|
---
|
|
|
|
# /delegate - Delegação com Testes e KB Integrados
|
|
|
|
Delega tarefas de desenvolvimento para outros chats com workflow completo: timer, **auto-consulta Dify KB**, implementação, **testes automáticos**, e report unificado.
|
|
|
|
## Novidade v3.0: Auto-Consulta Dify KB
|
|
|
|
Antes de delegar, a skill consulta automaticamente a knowledge base para enriquecer o contexto do agente delegado.
|
|
|
|
```
|
|
/delegate #1429 /path "Implementar feature"
|
|
│
|
|
▼
|
|
┌─────────────────────────────────────────────────────────┐
|
|
│ PRÉ-DELEGAÇÃO (automático) │
|
|
├─────────────────────────────────────────────────────────┤
|
|
│ 1. Detectar tipo de trabalho (WP, PHP, MCP, etc.) │
|
|
│ 2. Carregar agent-knowledge-config.json │
|
|
│ 3. Verificar consultation_protocol do agente │
|
|
│ 4. Consultar Dify KB com query_template + {task} │
|
|
│ 5. Verificar cache (evitar consultas repetidas) │
|
|
│ 6. Enriquecer template com conhecimento relevante │
|
|
└─────────────────────────────────────────────────────────┘
|
|
│
|
|
▼
|
|
DELEGAÇÃO ENRIQUECIDA
|
|
```
|
|
|
|
## Workflow v2.0
|
|
|
|
```
|
|
/delegate #1429 /path "Implementar feature"
|
|
│
|
|
▼
|
|
┌─────────────────────────────────────────────────────────┐
|
|
│ CHAT DELEGADO (executa tudo automaticamente) │
|
|
├─────────────────────────────────────────────────────────┤
|
|
│ 1. start_timer (AikTop) │
|
|
│ 2. IMPLEMENTAR │
|
|
│ - Desenvolver funcionalidade │
|
|
│ - Actualizar CHANGELOG.md │
|
|
│ - Commits por etapa │
|
|
│ 3. TESTAR ←── NOVO: integrado no fluxo │
|
|
│ - Executar testes funcionais │
|
|
│ - Verificar edge cases │
|
|
│ - Testar regressões │
|
|
│ - Se falhar → corrigir → testar novamente │
|
|
│ 4. FINALIZAR │
|
|
│ - Commit final + push │
|
|
│ - Status → "Em Testes" (3) │
|
|
│ - Comentário com report unificado │
|
|
│ - stop_timer │
|
|
└─────────────────────────────────────────────────────────┘
|
|
│
|
|
▼
|
|
@Emanuel recebe notificação
|
|
```
|
|
|
|
---
|
|
|
|
## Protocolo de Auto-Consulta Dify KB
|
|
|
|
### 1. Mapeamento Agente → Datasets
|
|
|
|
Ficheiro: `~/.claude/agents/agent-knowledge-config.json`
|
|
|
|
| Tipo de Trabalho | Agente | Datasets Prioritários |
|
|
|------------------|--------|----------------------|
|
|
| WordPress | `wordpress-plugin-developer` | Wordpress, Elementor, Crocoblock |
|
|
| PHP/APIs | `php-fullstack-engineer` | APIs, MCP, Backend |
|
|
| MCP | `mcp-protocol-developer` | MCP Servers, Claude Code |
|
|
| Marketing | `marketing-planning-expert` | Marketing Digital, SEO |
|
|
| CRM | `crm-admin-specialist` | Perfex CRM |
|
|
|
|
### 2. Fluxo de Consulta
|
|
|
|
```javascript
|
|
// 1. Detectar agente baseado no path/contexto
|
|
const agent = detectAgent(path, task); // e.g., "wordpress-plugin-developer"
|
|
|
|
// 2. Carregar configuração
|
|
const config = require('~/.claude/agents/agent-knowledge-config.json');
|
|
const protocol = config.agents[agent]?.consultation_protocol;
|
|
|
|
// 3. Se tem protocolo de consulta
|
|
if (protocol?.auto_consult) {
|
|
// 4. Construir query
|
|
const query = protocol.query_template.replace('{task}', task);
|
|
|
|
// 5. Verificar cache primeiro
|
|
const cacheKey = generateHash(query, protocol.priority_datasets);
|
|
const cached = checkCache(cacheKey);
|
|
|
|
if (cached) {
|
|
// Cache hit - usar resultado
|
|
return cached.result;
|
|
}
|
|
|
|
// 6. Consultar Dify KB (paralelo)
|
|
const results = await Promise.all(
|
|
protocol.priority_datasets.map(id =>
|
|
mcp__notebooklm__notebook_query, mcp__dify-kb__dify_kb_retrieve_segments({
|
|
dataset_id: id,
|
|
query: query,
|
|
top_k: protocol.top_k || 3
|
|
})
|
|
)
|
|
);
|
|
|
|
// 7. Gravar em cache
|
|
saveToCache(cacheKey, results);
|
|
|
|
// 8. Retornar conhecimento agregado
|
|
return aggregateResults(results);
|
|
}
|
|
```
|
|
|
|
### 3. Enriquecimento do Template
|
|
|
|
O conhecimento recuperado é adicionado ao template de delegação:
|
|
|
|
```markdown
|
|
### Contexto da Knowledge Base (Auto-Consultado)
|
|
|
|
**Query:** {query_used}
|
|
**Datasets consultados:** {dataset_names}
|
|
**Cache:** HIT/MISS
|
|
|
|
#### Conhecimento Relevante:
|
|
{kb_results_formatted}
|
|
|
|
---
|
|
```
|
|
|
|
### 4. Métricas Automáticas
|
|
|
|
Cada delegação com consulta KB grava:
|
|
```sql
|
|
INSERT INTO tblskill_agent_metrics (
|
|
type, name, duration_ms, status, staff_id,
|
|
kb_consulted, kb_cache_hit, tool_calls
|
|
) VALUES (
|
|
'skill', '/delegate', {ms}, 'completed', 25,
|
|
1, {0_ou_1}, {n}
|
|
);
|
|
```
|
|
|
|
---
|
|
|
|
## Uso
|
|
|
|
```bash
|
|
/delegate <task_i |