3575b391b6
- skills/agent_update.py : check_update (git fetch + log) et do_upgrade (git pull + systemctl restart) - agent1.py : commandes !agentUPDATE <nom>, !agentsUPDATE, !agentUPGRADE <nom>, !agentsUPGRADE - _handle_agent_command retourne (handled, reply) pour gérer le self-upgrade agent1 - !agentUPGRADE agent1 : envoie la réponse XMPP avant systemctl restart - !agentsUPGRADE : met à jour tous les agents puis agent1 en dernier - agents_registry.json : ajout install_path, service_name, git_branch + entrée agent1 - README.md : documentation des nouvelles commandes - TODO.md : tâches marquées comme terminées Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
232 lines
7.3 KiB
Markdown
232 lines
7.3 KiB
Markdown
# Agent1 — Orchestrateur XMPP/MQTT
|
|
|
|
Agent principal du réseau. Il reçoit les instructions de l'utilisateur (via XMPP ou CLI MQTT), les analyse avec un LLM, et délègue les tâches aux agents spécialisés.
|
|
|
|
---
|
|
|
|
## Commandes XMPP (sylvain@xmpp.ovh → agent1)
|
|
|
|
### Contrôle des agents
|
|
|
|
| Commande | Effet |
|
|
|---|---|
|
|
| `!agentsOFF` | Agent1 en veille + pause de tous les agents |
|
|
| `!agentsON` | Agent1 actif + reprise de tous les agents |
|
|
| `!agentOFF <nom>` | Pause d'un agent spécifique (ex: `!agentOFF agent2_debian13`) |
|
|
| `!agentON <nom>` | Reprise d'un agent spécifique |
|
|
| `!agentOFF agent1` | Agent1 en veille uniquement (les autres agents continuent) |
|
|
| `!agentON agent1` | Agent1 sort de veille |
|
|
|
|
> En mode veille, agent1 reste connecté XMPP et répond uniquement aux commandes `!agentON`.
|
|
|
|
### Mises à jour git
|
|
|
|
| Commande | Effet |
|
|
|---|---|
|
|
| `!agentUPDATE <nom>` | Vérifie si une mise à jour est disponible sur le dépôt git de l'agent |
|
|
| `!agentsUPDATE` | Vérifie les dépôts de tous les agents enregistrés |
|
|
| `!agentUPGRADE <nom>` | `git pull` + `systemctl restart` de l'agent |
|
|
| `!agentsUPGRADE` | `git pull` + restart de tous les agents (agent1 en dernier) |
|
|
|
|
> `!agentUPGRADE agent1` redémarre agent1 lui-même via systemd. La réponse XMPP est envoyée avant le redémarrage.
|
|
|
|
### Affichage des configurations
|
|
|
|
| Commande | Effet |
|
|
|---|---|
|
|
| `!reports` | Afficher `reports_schedule.json` (horaires des rapports) |
|
|
| `!tasks` | Afficher `tasks_schedule.json` (tâches planifiées) |
|
|
| `!blackout` | Afficher `blackout_hours.json` (plages d'inactivité) |
|
|
|
|
### Divers
|
|
|
|
| Commande | Effet |
|
|
|---|---|
|
|
| `!reset` | Réinitialiser l'historique de conversation |
|
|
|
|
---
|
|
|
|
## Skills LLM (utilisables en XMPP ou CLI)
|
|
|
|
Ces commandes sont générées par le LLM en réponse à une instruction en langage naturel.
|
|
|
|
### Délégation et planification
|
|
|
|
| Trigger | Syntaxe | Description |
|
|
|---|---|---|
|
|
| `DELEGATE:` | `DELEGATE: <agent> \| <tâche>` | Délègue une tâche à un agent (avec vérif. plage horaire + blackout) |
|
|
| `PLAN:` | `PLAN: <agent>\|<tâche> ;; <agent>\|<tâche>` | Exécute plusieurs tâches en séquence |
|
|
| `SCHEDULE:` | `SCHEDULE: <cron> \| <agent> \| <tâche>` | Planifie une tâche récurrente |
|
|
| `PLAN_LIST:` | `PLAN_LIST:` | Lister les tâches planifiées |
|
|
| `PLAN_CANCEL:` | `PLAN_CANCEL: <id>` | Annuler une planification |
|
|
|
|
**Expressions cron supportées :**
|
|
```
|
|
daily 03:00 → tous les jours à 03h00
|
|
every 6h → toutes les 6 heures
|
|
every 30min → toutes les 30 minutes
|
|
weekly lun 08:00 → chaque lundi à 08h00
|
|
```
|
|
|
|
### Rapports
|
|
|
|
| Trigger | Syntaxe | Description |
|
|
|---|---|---|
|
|
| `REPORT:` | `REPORT: [agent]` | Rapport des 20 dernières exécutions |
|
|
| `REPORT_ERRORS:` | `REPORT_ERRORS: [agent]` | Rapport des 20 dernières erreurs |
|
|
| `DAILY_REPORT:` | `DAILY_REPORT: [agent]` | Rapport journalier compilé (stats de tous les agents) |
|
|
|
|
### Mémoire et recherche
|
|
|
|
| Trigger | Syntaxe | Description |
|
|
|---|---|---|
|
|
| `SEARCH:` | `SEARCH: <requête>` | Recherche DuckDuckGo |
|
|
| `READ:` | `READ: <url>` | Lecture de page web |
|
|
| `REMEMBER:` | `REMEMBER: <clé> \| <valeur>` | Mémoriser une information (SQLite) |
|
|
| `RECALL:` | `RECALL: <clé>` | Récupérer une information mémorisée |
|
|
|
|
### MQTT direct
|
|
|
|
| Trigger | Syntaxe | Description |
|
|
|---|---|---|
|
|
| `MQTT_PUBLISH:` | `MQTT_PUBLISH: <topic> \| <message>` | Publier un message MQTT |
|
|
| `MQTT_SUBSCRIBE:` | `MQTT_SUBSCRIBE: <topic>` | Écouter un topic MQTT |
|
|
|
|
---
|
|
|
|
## CLI (`cli.py`)
|
|
|
|
```bash
|
|
python3 /opt/agent/cli.py # parler à agent1
|
|
python3 /opt/agent/cli.py agent2_debian13 # accès direct à un agent
|
|
python3 /opt/agent/cli.py --plans # voir les planifications
|
|
```
|
|
|
|
**Commandes dans la CLI :**
|
|
|
|
| Commande | Effet |
|
|
|---|---|
|
|
| `/reset` | Réinitialiser la conversation |
|
|
| `/plans` | Lister les tâches planifiées |
|
|
| `/report` | Rapport des dernières exécutions |
|
|
| `/errors` | Rapport des erreurs |
|
|
| `/agent <nom>` | Basculer vers un autre agent |
|
|
| `/quit` | Quitter la CLI |
|
|
|
|
---
|
|
|
|
## Fichiers de configuration
|
|
|
|
| Fichier | Rôle | Modifié par |
|
|
|---|---|---|
|
|
| `config/config.json` | Paramètres XMPP, MQTT, Ollama | Utilisateur |
|
|
| `config/agents_registry.json` | Registre des agents (auto-mis à jour) | Agent1 au démarrage des agents |
|
|
| `config/blackout_hours.json` | Plages horaires d'inactivité totale | **Utilisateur directement** |
|
|
| `config/reports_schedule.json` | Horaires de sollicitation des rapports | Agent1 (avec confirmation) |
|
|
| `config/tasks_schedule.json` | Tâches planifiées par agent | Agent1 (avec confirmation) |
|
|
|
|
### `blackout_hours.json`
|
|
Aucun agent ne travaille pendant ces plages, quelle que soit la planification :
|
|
```json
|
|
[
|
|
{ "start": "02:00", "end": "05:00", "label": "maintenance nuit", "enabled": true }
|
|
]
|
|
```
|
|
|
|
### `reports_schedule.json`
|
|
```json
|
|
{
|
|
"agents": {
|
|
"agent2_debian13": { "report_time": "22:00", "enabled": true },
|
|
"agent2_ansible": { "report_time": "22:05", "enabled": true },
|
|
"agent2_deploy": { "report_time": "22:10", "enabled": true }
|
|
},
|
|
"daily_report_time": "22:30",
|
|
"daily_report_enabled": true
|
|
}
|
|
```
|
|
|
|
### `tasks_schedule.json`
|
|
```json
|
|
{
|
|
"tasks": [
|
|
{
|
|
"agent": "agent2_debian13",
|
|
"task": "apt update && apt upgrade -y",
|
|
"cron": "weekly lun 03:00",
|
|
"enabled": true
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
### `agents_registry.json` — champ `work_hours`
|
|
Plage horaire de travail par agent (vérifiée avant chaque DELEGATE) :
|
|
```json
|
|
"work_hours": {
|
|
"start": "07:00",
|
|
"end": "23:00",
|
|
"days": ["mon","tue","wed","thu","fri","sat","sun"],
|
|
"enabled": true
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Topics MQTT
|
|
|
|
| Topic | Direction | Rôle |
|
|
|---|---|---|
|
|
| `agents/agent1/inbox` | CLI / agents → agent1 | Tâches pour agent1 |
|
|
| `agents/<name>/inbox` | Agent1 → agent2_* | Tâches pour les agents |
|
|
| `agents/<name>/control` | Agent1 → agent2_* | Pause / Resume / Report |
|
|
| `agents/daily_report` | Agent2_* → agent1 | Rapports journaliers |
|
|
| `agents/errors` | Agent2_* → agent1 | Erreurs (notif XMPP) |
|
|
| `agents/register` | Agent2_* → agent1 | Enregistrement au démarrage |
|
|
| `agents/status/<name>` | Agent2_* → agent1 | Statut en ligne / hors ligne (LWT) |
|
|
| `agents/cli/outbox` | Agent1 → CLI | Réponses vers la CLI |
|
|
| `agents/scheduler/notifications` | Scheduler → agent1 | Notifications planificateur |
|
|
|
|
---
|
|
|
|
## Lancer les agents
|
|
|
|
```bash
|
|
# Agent1
|
|
python3 /opt/agent/agent1.py > /tmp/agent1.log 2>&1 &
|
|
|
|
# Agents spécialisés
|
|
python3 /opt/agent2_debian13/agent2_debian13.py > /tmp/agent2_debian13.log 2>&1 &
|
|
python3 /opt/agent2_ansible/agent2_ansible.py > /tmp/agent2_ansible.log 2>&1 &
|
|
python3 /opt/agent2_deploy/agent2_deploy.py > /tmp/agent2_deploy.log 2>&1 &
|
|
|
|
# Via systemd
|
|
systemctl start agent agent2_debian13 agent2_ansible agent2_deploy
|
|
```
|
|
|
|
## Logs
|
|
|
|
```bash
|
|
journalctl -u agent -f
|
|
journalctl -u agent2_debian13 -f
|
|
```
|
|
|
|
---
|
|
|
|
## Déploiement manuel
|
|
|
|
```bash
|
|
apt-get install -y python3 python3-pip python3-venv git mosquitto
|
|
git clone https://git.piaf.im/sylvain/agent1.git /opt/agent
|
|
cd /opt/agent
|
|
python3 -m venv venv
|
|
venv/bin/pip install slixmpp paho-mqtt requests ddgs beautifulsoup4 chromadb apscheduler
|
|
|
|
# Configurer
|
|
cp config/config.json.example config/config.json # adapter les valeurs
|
|
|
|
# Service systemd
|
|
cp agent.service /etc/systemd/system/
|
|
systemctl daemon-reload && systemctl enable agent && systemctl start agent
|
|
```
|