ciscollm-cli 1.1.4 → 1.2.0
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/LICENSE +21 -21
- package/README.md +137 -17
- package/dist/core/agent/AutoHealer.d.ts +27 -0
- package/dist/core/agent/AutoHealer.js +387 -0
- package/dist/core/agent/AutoHealer.js.map +1 -0
- package/dist/core/agent/HierarchicalAgentManager.js +5 -5
- package/dist/core/agent/MultiAgentCoordinator.d.ts +3 -1
- package/dist/core/agent/MultiAgentCoordinator.js +11 -1
- package/dist/core/agent/MultiAgentCoordinator.js.map +1 -1
- package/dist/core/agent/PromptEngine.js +67 -67
- package/dist/core/guardrails/AuditLogger.js +4 -4
- package/dist/core/guardrails/CommandFirewall.d.ts +2 -0
- package/dist/core/guardrails/CommandFirewall.js +99 -8
- package/dist/core/guardrails/CommandFirewall.js.map +1 -1
- package/dist/core/rollback/TransactionManager.js +17 -0
- package/dist/core/rollback/TransactionManager.js.map +1 -1
- package/dist/index.js +142 -0
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/llm/LLMClient.js +0 -1
- package/dist/infrastructure/llm/LLMClient.js.map +1 -1
- package/dist/infrastructure/protocols/BaseSession.d.ts +2 -1
- package/dist/infrastructure/protocols/BaseSession.js +2 -1
- package/dist/infrastructure/protocols/BaseSession.js.map +1 -1
- package/dist/infrastructure/protocols/PlinkSerial.d.ts +1 -0
- package/dist/infrastructure/protocols/PlinkSerial.js +67 -12
- package/dist/infrastructure/protocols/PlinkSerial.js.map +1 -1
- package/dist/server/index.js +8 -8
- package/dist/server/shell-simulator.d.ts +2 -0
- package/dist/server/shell-simulator.js +65 -58
- package/dist/server/shell-simulator.js.map +1 -1
- package/dist/server/ssh.js +31 -20
- package/dist/server/ssh.js.map +1 -1
- package/dist/server/telnet.js +11 -0
- package/dist/server/telnet.js.map +1 -1
- package/package.json +54 -52
- package/dist/infrastructure/llm/LocalLLMClient.d.ts +0 -7
- package/dist/infrastructure/llm/LocalLLMClient.js +0 -39
- package/dist/infrastructure/llm/LocalLLMClient.js.map +0 -1
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.AutoHealer = void 0;
|
|
40
|
+
const TransactionManager_1 = require("../rollback/TransactionManager");
|
|
41
|
+
const ui_1 = require("../../cli/ui/ui");
|
|
42
|
+
const CommandFirewall_1 = require("../guardrails/CommandFirewall");
|
|
43
|
+
const AuditLogger_1 = require("../guardrails/AuditLogger");
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
47
|
+
class AutoHealer {
|
|
48
|
+
llmClient;
|
|
49
|
+
coordinator;
|
|
50
|
+
isRunning = false;
|
|
51
|
+
healingDevices = new Set();
|
|
52
|
+
logFilePath;
|
|
53
|
+
minConfidence;
|
|
54
|
+
nonInteractive;
|
|
55
|
+
firewall = new CommandFirewall_1.CommandFirewall();
|
|
56
|
+
triggerHistory = new Map();
|
|
57
|
+
blockedUntil = new Map();
|
|
58
|
+
constructor(llmClient, coordinator, options = {}) {
|
|
59
|
+
this.llmClient = llmClient;
|
|
60
|
+
this.coordinator = coordinator;
|
|
61
|
+
this.logFilePath = path.resolve(process.cwd(), options.logFile || 'healing-audit.log');
|
|
62
|
+
this.minConfidence = options.minConfidence ?? 0.80;
|
|
63
|
+
this.nonInteractive = options.nonInteractive ?? false;
|
|
64
|
+
if (this.nonInteractive) {
|
|
65
|
+
process.env.CISCOLLM_NON_INTERACTIVE = 'true';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
start() {
|
|
69
|
+
if (this.isRunning)
|
|
70
|
+
return;
|
|
71
|
+
this.isRunning = true;
|
|
72
|
+
ui_1.logger.info(`AutoHealer started. Listening for syslog triggers: %LINK-3-UPDOWN, %LINEPROTO-5-UPDOWN, %OSPF-5-ADJCHG...`);
|
|
73
|
+
this.coordinator.on('notification', (msg, deviceId) => {
|
|
74
|
+
this.handleNotification(msg, deviceId).catch(err => {
|
|
75
|
+
ui_1.logger.error(`Error handling notification for device ${deviceId}: ${err.message}`);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
stop() {
|
|
80
|
+
this.isRunning = false;
|
|
81
|
+
ui_1.logger.info(`AutoHealer stopped.`);
|
|
82
|
+
}
|
|
83
|
+
async handleNotification(msg, deviceId) {
|
|
84
|
+
const isTrigger = /%(LINK-3-UPDOWN|LINEPROTO-5-UPDOWN|OSPF-5-ADJCHG):/.test(msg);
|
|
85
|
+
if (!isTrigger)
|
|
86
|
+
return;
|
|
87
|
+
const now = Date.now();
|
|
88
|
+
const blockTime = this.blockedUntil.get(deviceId);
|
|
89
|
+
if (blockTime && now < blockTime) {
|
|
90
|
+
const minutesLeft = Math.ceil((blockTime - now) / 60000);
|
|
91
|
+
ui_1.logger.warn(`[AutoHealer Cooldown] Healing triggers for ${deviceId} are blocked for another ${minutesLeft} minute(s) due to rapid repetitive alerts.`);
|
|
92
|
+
this.logToAudit(`[BLOCKED-COOLDOWN] Device: ${deviceId} | Cooldown active for another ${minutesLeft} mins`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (this.healingDevices.has(deviceId)) {
|
|
96
|
+
ui_1.logger.info(`[Telemetry Alert] Alert received for ${deviceId} but device is already undergoing healing.`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
let history = this.triggerHistory.get(deviceId) || [];
|
|
100
|
+
history = history.filter(ts => now - ts < 600000);
|
|
101
|
+
history.push(now);
|
|
102
|
+
this.triggerHistory.set(deviceId, history);
|
|
103
|
+
if (history.length > 3) {
|
|
104
|
+
this.blockedUntil.set(deviceId, now + 900000);
|
|
105
|
+
ui_1.logger.error(`[AutoHealer Cooldown] CRITICAL: Device ${deviceId} triggered healing ${history.length} times in less than 10 minutes. Activating 15-minute cooldown to prevent remediation loop.`);
|
|
106
|
+
this.logToAudit(`[ACTIVATED-COOLDOWN] Device: ${deviceId} | Blocked for 15 mins due to repetitive triggers.`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
this.healingDevices.add(deviceId);
|
|
110
|
+
ui_1.logger.heading(`Closed-Loop Healing Event Triggered on ${deviceId}`);
|
|
111
|
+
ui_1.logger.info(`Syslog Received: ${chalk_1.default.yellow(msg)}`);
|
|
112
|
+
this.logToAudit(`[TRIGGERED] Device: ${deviceId} | Syslog: ${msg}`);
|
|
113
|
+
const spinner = (0, ui_1.createSpinner)('OODA Loop: Initiating recovery sequence...').start();
|
|
114
|
+
try {
|
|
115
|
+
spinner.text = 'OODA Loop (Orient): Gathering diagnostic context...';
|
|
116
|
+
const context = await this.gatherContext(deviceId, msg);
|
|
117
|
+
spinner.info(`Diagnostic context gathered (${context.commandsRun.length} commands).`);
|
|
118
|
+
const decideSpinner = (0, ui_1.createSpinner)('OODA Loop (Decide): Querying AI for Root Cause & Remediation...').start();
|
|
119
|
+
const diagnosis = await this.diagnose(deviceId, msg, context.outputs);
|
|
120
|
+
decideSpinner.succeed('Root Cause Analysis completed.');
|
|
121
|
+
ui_1.logger.diamond(`AI Detected Issue: ${chalk_1.default.white.bold(diagnosis.detected_issue)}`);
|
|
122
|
+
ui_1.logger.diamond(`AI Root Cause: ${chalk_1.default.gray.italic(diagnosis.root_cause)}`);
|
|
123
|
+
ui_1.logger.diamond(`AI Confidence: ${chalk_1.default.cyan(diagnosis.confidence)}`);
|
|
124
|
+
ui_1.logger.diamond(`Remediation: ${chalk_1.default.green(diagnosis.remediation_commands.join(', '))}`);
|
|
125
|
+
ui_1.logger.diamond(`Verification: ${chalk_1.default.blue(diagnosis.verification_commands.join(', '))}`);
|
|
126
|
+
if (diagnosis.confidence < this.minConfidence) {
|
|
127
|
+
ui_1.logger.warn(`AI confidence (${diagnosis.confidence}) is below threshold (${this.minConfidence}). Skipping automatic healing.`);
|
|
128
|
+
this.logToAudit(`[SKIPPED] Device: ${deviceId} | Confidence too low: ${diagnosis.confidence}`);
|
|
129
|
+
this.healingDevices.delete(deviceId);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (!this.nonInteractive) {
|
|
133
|
+
ui_1.logger.warn('Interactive Mode: Human verification required to apply remediation.');
|
|
134
|
+
const rl = require('readline').createInterface({
|
|
135
|
+
input: process.stdin,
|
|
136
|
+
output: process.stdout
|
|
137
|
+
});
|
|
138
|
+
const approved = await new Promise((resolve) => {
|
|
139
|
+
rl.question(chalk_1.default.yellow(`Apply remediation? (y/N): `), (answer) => {
|
|
140
|
+
rl.close();
|
|
141
|
+
resolve(answer.trim().toLowerCase() === 'y');
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
if (!approved) {
|
|
145
|
+
ui_1.logger.error('Remediation denied by human administrator.');
|
|
146
|
+
this.logToAudit(`[DENIED] Device: ${deviceId} | Blocked by administrator.`);
|
|
147
|
+
this.healingDevices.delete(deviceId);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const actSpinner = (0, ui_1.createSpinner)('OODA Loop (Act): Applying remediation commands...').start();
|
|
152
|
+
const session = this.coordinator.getSession(deviceId);
|
|
153
|
+
if (!session) {
|
|
154
|
+
throw new Error(`Device connection lost for ${deviceId}`);
|
|
155
|
+
}
|
|
156
|
+
const tx = new TransactionManager_1.TransactionManager();
|
|
157
|
+
await tx.initializeBackup(session);
|
|
158
|
+
let remediationSuccess = true;
|
|
159
|
+
let appliedCommands = [];
|
|
160
|
+
for (const cmd of diagnosis.remediation_commands) {
|
|
161
|
+
try {
|
|
162
|
+
const firewallResult = this.firewall.checkCommand(cmd, null);
|
|
163
|
+
if (firewallResult.dangerous) {
|
|
164
|
+
const approved = await this.firewall.verifyWithHuman(cmd, firewallResult.reason || 'High-risk token');
|
|
165
|
+
if (!approved) {
|
|
166
|
+
AuditLogger_1.AuditLogger.log({
|
|
167
|
+
timestamp: new Date().toISOString(),
|
|
168
|
+
deviceId: deviceId,
|
|
169
|
+
role: 'auto-healer',
|
|
170
|
+
command: cmd,
|
|
171
|
+
status: 'BLOCKED',
|
|
172
|
+
reason: firewallResult.reason || 'Command denied by administrator.'
|
|
173
|
+
});
|
|
174
|
+
throw new Error(`Command "${cmd}" was blocked by CommandFirewall safety policy.`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
actSpinner.text = `OODA Loop (Act): Executing command: "${cmd}"...`;
|
|
178
|
+
tx.trackMutation(cmd);
|
|
179
|
+
const out = await session.execute(cmd);
|
|
180
|
+
const check = require('../guardrails/ErrorAnalyzer').ErrorAnalyzer.checkOutput(out);
|
|
181
|
+
if (check.hasError) {
|
|
182
|
+
throw new Error(`CLI Command error: ${check.errorType} - ${out}`);
|
|
183
|
+
}
|
|
184
|
+
appliedCommands.push(cmd);
|
|
185
|
+
AuditLogger_1.AuditLogger.log({
|
|
186
|
+
timestamp: new Date().toISOString(),
|
|
187
|
+
deviceId: deviceId,
|
|
188
|
+
role: 'auto-healer',
|
|
189
|
+
command: cmd,
|
|
190
|
+
status: 'SUCCESS',
|
|
191
|
+
outputSnippet: out
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
catch (e) {
|
|
195
|
+
remediationSuccess = false;
|
|
196
|
+
actSpinner.fail(`Failed to execute command: "${cmd}". Error: ${e.message}`);
|
|
197
|
+
AuditLogger_1.AuditLogger.log({
|
|
198
|
+
timestamp: new Date().toISOString(),
|
|
199
|
+
deviceId: deviceId,
|
|
200
|
+
role: 'auto-healer',
|
|
201
|
+
command: cmd,
|
|
202
|
+
status: 'FAILED',
|
|
203
|
+
reason: e.message
|
|
204
|
+
});
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (!remediationSuccess) {
|
|
209
|
+
actSpinner.text = 'Automated Rollback: Reverting partial config mutations...';
|
|
210
|
+
const rbLogs = await tx.executeRollback(session);
|
|
211
|
+
actSpinner.fail('Remediation failed. Automated rollback executed.');
|
|
212
|
+
this.logToAudit(`[FAILED-ACT] Device: ${deviceId} | Applied: ${appliedCommands.join(', ')} | Error during act. Rollback executed.`);
|
|
213
|
+
AuditLogger_1.AuditLogger.log({
|
|
214
|
+
timestamp: new Date().toISOString(),
|
|
215
|
+
deviceId: deviceId,
|
|
216
|
+
role: 'auto-healer',
|
|
217
|
+
command: 'automated_rollback',
|
|
218
|
+
status: 'ROLLBACK',
|
|
219
|
+
reason: 'Config recovery due to healing failure'
|
|
220
|
+
});
|
|
221
|
+
this.healingDevices.delete(deviceId);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
actSpinner.succeed('Remediation commands successfully applied.');
|
|
225
|
+
const verifySpinner = (0, ui_1.createSpinner)('OODA Loop (Verify): Executing verification checks...').start();
|
|
226
|
+
let verifyOutputs = '';
|
|
227
|
+
for (const cmd of diagnosis.verification_commands) {
|
|
228
|
+
try {
|
|
229
|
+
verifySpinner.text = `OODA Loop (Verify): Executing verification: "${cmd}"...`;
|
|
230
|
+
const out = await session.execute(cmd);
|
|
231
|
+
verifyOutputs += `Command: "${cmd}"\nOutput:\n${out}\n\n`;
|
|
232
|
+
AuditLogger_1.AuditLogger.log({
|
|
233
|
+
timestamp: new Date().toISOString(),
|
|
234
|
+
deviceId: deviceId,
|
|
235
|
+
role: 'auto-healer',
|
|
236
|
+
command: cmd,
|
|
237
|
+
status: 'SUCCESS',
|
|
238
|
+
outputSnippet: out
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
catch (e) {
|
|
242
|
+
verifyOutputs += `Command: "${cmd}" failed: ${e.message}\n\n`;
|
|
243
|
+
AuditLogger_1.AuditLogger.log({
|
|
244
|
+
timestamp: new Date().toISOString(),
|
|
245
|
+
deviceId: deviceId,
|
|
246
|
+
role: 'auto-healer',
|
|
247
|
+
command: cmd,
|
|
248
|
+
status: 'FAILED',
|
|
249
|
+
reason: e.message
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const isHealed = await this.verifyFixWithLLM(deviceId, msg, diagnosis.detected_issue, verifyOutputs);
|
|
254
|
+
if (isHealed) {
|
|
255
|
+
verifySpinner.succeed('Verification PASSED: Device recovered successfully.');
|
|
256
|
+
this.logToAudit(`[SUCCESS] Device: ${deviceId} | Issue: ${diagnosis.detected_issue} | Remediation: ${appliedCommands.join(', ')}`);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
verifySpinner.fail('Verification FAILED: The issue is not fully resolved. Triggering rollback...');
|
|
260
|
+
const rbLogs = await tx.executeRollback(session);
|
|
261
|
+
verifySpinner.fail(`Rollback completed successfully.`);
|
|
262
|
+
this.logToAudit(`[FAILED-VERIFY] Device: ${deviceId} | Issue: ${diagnosis.detected_issue} | Verification failed. Rollback executed.`);
|
|
263
|
+
AuditLogger_1.AuditLogger.log({
|
|
264
|
+
timestamp: new Date().toISOString(),
|
|
265
|
+
deviceId: deviceId,
|
|
266
|
+
role: 'auto-healer',
|
|
267
|
+
command: 'automated_rollback',
|
|
268
|
+
status: 'ROLLBACK',
|
|
269
|
+
reason: 'Config recovery due to verification failure'
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
catch (e) {
|
|
274
|
+
spinner.fail(`Healing sequence failed: ${e.message}`);
|
|
275
|
+
this.logToAudit(`[ERROR] Device: ${deviceId} | Sequence failed: ${e.message}`);
|
|
276
|
+
}
|
|
277
|
+
finally {
|
|
278
|
+
this.healingDevices.delete(deviceId);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
async gatherContext(deviceId, msg) {
|
|
282
|
+
const session = this.coordinator.getSession(deviceId);
|
|
283
|
+
if (!session) {
|
|
284
|
+
return { commandsRun: [], outputs: 'Connection not available.' };
|
|
285
|
+
}
|
|
286
|
+
const commands = [];
|
|
287
|
+
const ifMatch = /Interface\s+(\S+?)(?:,|\s+changed|$)/i.exec(msg);
|
|
288
|
+
const ifName = ifMatch ? ifMatch[1] : null;
|
|
289
|
+
commands.push('show ip interface brief');
|
|
290
|
+
if (ifName) {
|
|
291
|
+
commands.push(`show interface ${ifName}`);
|
|
292
|
+
commands.push(`show running-config interface ${ifName}`);
|
|
293
|
+
}
|
|
294
|
+
if (msg.includes('OSPF')) {
|
|
295
|
+
commands.push('show ip ospf neighbor');
|
|
296
|
+
commands.push('show ip ospf interface');
|
|
297
|
+
}
|
|
298
|
+
commands.push('show ip route');
|
|
299
|
+
let outputs = '';
|
|
300
|
+
for (const cmd of commands) {
|
|
301
|
+
try {
|
|
302
|
+
const res = await session.execute(cmd);
|
|
303
|
+
outputs += `========================================\nCOMMAND: ${cmd}\n========================================\n${res}\n\n`;
|
|
304
|
+
}
|
|
305
|
+
catch (err) {
|
|
306
|
+
outputs += `========================================\nCOMMAND: ${cmd}\n========================================\nFailed to run: ${err.message}\n\n`;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return { commandsRun: commands, outputs };
|
|
310
|
+
}
|
|
311
|
+
async diagnose(deviceId, syslog, context) {
|
|
312
|
+
const systemPrompt = `You are an expert Cisco network diagnostic AI agent operating in an AIOps closed-loop healing framework.
|
|
313
|
+
Your task is to analyze the triggering syslog alert and the current state output of the device to:
|
|
314
|
+
1. Identify the detected issue.
|
|
315
|
+
2. Determine the root cause.
|
|
316
|
+
3. Formulate the precise list of Cisco IOS configuration commands to remediate the issue (e.g. going into interface configuration mode if necessary, applying changes, ensuring no shutdown is run if the port was disabled).
|
|
317
|
+
4. Formulate verification commands to check if the remediation succeeded.
|
|
318
|
+
|
|
319
|
+
You MUST think step-by-step (Chain of Thought).
|
|
320
|
+
Your response MUST end with a single, valid JSON block matching this schema:
|
|
321
|
+
{
|
|
322
|
+
"detected_issue": "short description of issue",
|
|
323
|
+
"root_cause": "root cause description",
|
|
324
|
+
"confidence": 0.0 to 1.0,
|
|
325
|
+
"remediation_commands": ["list", "of", "commands"],
|
|
326
|
+
"verification_commands": ["list", "of", "commands"]
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
Ensure the configuration commands are completely accurate for Cisco IOS syntax. For instance, to modify an interface, you must include the "interface GigabitEthernet0/1" command first.`;
|
|
330
|
+
const userMsg = `Syslog Alert: "${syslog}"\n\nCollected Device Context:\n${context}`;
|
|
331
|
+
const messages = [
|
|
332
|
+
{ role: 'system', content: systemPrompt },
|
|
333
|
+
{ role: 'user', content: userMsg }
|
|
334
|
+
];
|
|
335
|
+
const res = await this.llmClient.generateCompletion(messages);
|
|
336
|
+
const rawText = res.content || '';
|
|
337
|
+
const jsonMatch = /\{[\s\S]*\}/.exec(rawText);
|
|
338
|
+
if (!jsonMatch) {
|
|
339
|
+
throw new Error(`Failed to parse JSON from AI response: ${rawText}`);
|
|
340
|
+
}
|
|
341
|
+
try {
|
|
342
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
343
|
+
if (!parsed.remediation_commands || !parsed.verification_commands) {
|
|
344
|
+
throw new Error(`Parsed JSON lacks required fields: ${jsonMatch[0]}`);
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
detected_issue: parsed.detected_issue || 'Unknown',
|
|
348
|
+
root_cause: parsed.root_cause || 'Unknown',
|
|
349
|
+
confidence: typeof parsed.confidence === 'number' ? parsed.confidence : 0.5,
|
|
350
|
+
remediation_commands: parsed.remediation_commands || [],
|
|
351
|
+
verification_commands: parsed.verification_commands || []
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
catch (err) {
|
|
355
|
+
throw new Error(`JSON parse error of AI response: ${err.message}. Original block: ${jsonMatch[0]}`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
async verifyFixWithLLM(deviceId, syslog, issue, outputs) {
|
|
359
|
+
const systemPrompt = `You are a network verification validator. Analyze:
|
|
360
|
+
1. The original syslog alert.
|
|
361
|
+
2. The detected issue.
|
|
362
|
+
3. The post-remediation verification command outputs.
|
|
363
|
+
|
|
364
|
+
Determine if the issue has been successfully resolved (e.g. the line protocol changed to up/up, or routing neighbor state is now FULL).
|
|
365
|
+
Your response MUST end with either "SUCCESS" or "FAILED". Do not output any other text after.`;
|
|
366
|
+
const userMsg = `Syslog Alert: "${syslog}"\nDetected Issue: "${issue}"\n\nPost-Remediation Verification Outputs:\n${outputs}`;
|
|
367
|
+
const messages = [
|
|
368
|
+
{ role: 'system', content: systemPrompt },
|
|
369
|
+
{ role: 'user', content: userMsg }
|
|
370
|
+
];
|
|
371
|
+
const res = await this.llmClient.generateCompletion(messages);
|
|
372
|
+
const result = (res.content || '').trim().toUpperCase();
|
|
373
|
+
return result.includes('SUCCESS');
|
|
374
|
+
}
|
|
375
|
+
logToAudit(message) {
|
|
376
|
+
const timestamp = new Date().toISOString();
|
|
377
|
+
const formatted = `[${timestamp}] ${message}\n`;
|
|
378
|
+
try {
|
|
379
|
+
fs.appendFileSync(this.logFilePath, formatted, 'utf8');
|
|
380
|
+
}
|
|
381
|
+
catch (e) {
|
|
382
|
+
console.error(`Failed to write to healing audit log:`, e);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
exports.AutoHealer = AutoHealer;
|
|
387
|
+
//# sourceMappingURL=AutoHealer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoHealer.js","sourceRoot":"","sources":["../../../src/core/agent/AutoHealer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,uEAAoE;AACpE,wCAAwD;AAExD,mEAAgE;AAChE,2DAAwD;AACxD,uCAAyB;AACzB,2CAA6B;AAC7B,kDAA0B;AAQ1B,MAAa,UAAU;IAWP;IACA;IAXJ,SAAS,GAAY,KAAK,CAAC;IAC3B,cAAc,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,WAAW,CAAS;IACpB,aAAa,CAAS;IACtB,cAAc,CAAU;IACxB,QAAQ,GAAG,IAAI,iCAAe,EAAE,CAAC;IACjC,cAAc,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC7C,YAAY,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEjD,YACY,SAAoB,E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Q,EAAE,OAAO,EAAE,YAAY,EAAE;YACzC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE;SACrC,CAAC;QAEF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QAC9D,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACxD,OAAO,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;IAEO,UAAU,CAAC,OAAe;QAC9B,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC3C,MAAM,SAAS,GAAG,IAAI,SAAS,KAAK,OAAO,IAAI,CAAC;QAChD,IAAI,CAAC;YACD,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAC3D,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,CAAC,CAAC,CAAC;QAC9D,CAAC;IACL,CAAC;CACJ;AA5XD,gCA4XC"}
|
|
@@ -58,11 +58,11 @@ class HierarchicalAgentManager {
|
|
|
58
58
|
return 'ACCESS';
|
|
59
59
|
}
|
|
60
60
|
static getHierarchicalAgentPrompt() {
|
|
61
|
-
return `You are operating as a Hierarchical Network Swarm. Tasks are segregated into three agent layers:
|
|
62
|
-
- CORE AGENT (Core Routing, OSPF, BGP, Static Routes)
|
|
63
|
-
- DISTRIBUTION AGENT (VLANs, ACLs, Security policies, NAT)
|
|
64
|
-
- ACCESS AGENT (User ports, Interfaces, Speed/Duplex, IP Assignment)
|
|
65
|
-
|
|
61
|
+
return `You are operating as a Hierarchical Network Swarm. Tasks are segregated into three agent layers:
|
|
62
|
+
- CORE AGENT (Core Routing, OSPF, BGP, Static Routes)
|
|
63
|
+
- DISTRIBUTION AGENT (VLANs, ACLs, Security policies, NAT)
|
|
64
|
+
- ACCESS AGENT (User ports, Interfaces, Speed/Duplex, IP Assignment)
|
|
65
|
+
|
|
66
66
|
Always specify in your thoughts which agent layer is executing the command (e.g. "[AccessAgent] Modifying interface GigabitEthernet0/1").`;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { BaseSession } from '../../infrastructure/protocols/BaseSession';
|
|
2
2
|
import { NetworkTopology, SessionState } from '../../shared/types';
|
|
3
|
-
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
|
+
export declare class MultiAgentCoordinator extends EventEmitter {
|
|
4
5
|
private sessions;
|
|
5
6
|
private topology;
|
|
7
|
+
constructor();
|
|
6
8
|
registerSession(deviceId: string, session: BaseSession): void;
|
|
7
9
|
connectAll(): Promise<void>;
|
|
8
10
|
executeCommand(deviceId: string, command: string): Promise<string>;
|
|
@@ -6,15 +6,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.MultiAgentCoordinator = void 0;
|
|
7
7
|
const TopologyDiscovery_1 = require("../topology/TopologyDiscovery");
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
-
|
|
9
|
+
const events_1 = require("events");
|
|
10
|
+
class MultiAgentCoordinator extends events_1.EventEmitter {
|
|
10
11
|
sessions = new Map();
|
|
11
12
|
topology = {
|
|
12
13
|
discoveredAt: new Date(0).toISOString(),
|
|
13
14
|
nodes: [],
|
|
14
15
|
links: []
|
|
15
16
|
};
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
}
|
|
16
20
|
registerSession(deviceId, session) {
|
|
21
|
+
session.deviceId = deviceId;
|
|
17
22
|
this.sessions.set(deviceId, session);
|
|
23
|
+
if (typeof session.onNotification === 'function') {
|
|
24
|
+
session.onNotification((msg, devId) => {
|
|
25
|
+
this.emit('notification', msg, devId);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
18
28
|
}
|
|
19
29
|
async connectAll() {
|
|
20
30
|
console.log(chalk_1.default.cyan(`❯ Establishing parallel connections to ${this.sessions.size} target device(s)...`));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiAgentCoordinator.js","sourceRoot":"","sources":["../../../src/core/agent/MultiAgentCoordinator.ts"],"names":[],"mappings":";;;;;;AAEA,qEAAkE;AAClE,kDAA0B;
|
|
1
|
+
{"version":3,"file":"MultiAgentCoordinator.js","sourceRoot":"","sources":["../../../src/core/agent/MultiAgentCoordinator.ts"],"names":[],"mappings":";;;;;;AAEA,qEAAkE;AAClE,kDAA0B;AAC1B,mCAAsC;AAEtC,MAAa,qBAAsB,SAAQ,qBAAY;IAC3C,QAAQ,GAA6B,IAAI,GAAG,EAAE,CAAC;IAC/C,QAAQ,GAAoB;QAChC,YAAY,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;QACvC,KAAK,EAAE,EAAE;QACT,KAAK,EAAE,EAAE;KACZ,CAAC;IAEF;QACI,KAAK,EAAE,CAAC;IACZ,CAAC;IAEM,eAAe,CAAC,QAAgB,EAAE,OAAoB;QACzD,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAC5B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACrC,IAAI,OAAO,OAAO,CAAC,cAAc,KAAK,UAAU,EAAE,CAAC;YAC/C,OAAO,CAAC,cAAc,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;gBAClC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,UAAU;QACnB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,0CAA0C,IAAI,CAAC,QAAQ,CAAC,IAAI,sBAAsB,C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gBAC3B,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,eAAe,EAAE,yBAAyB,CAAC,CAAC,CAAC;YACzE,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAChB,OAAO,CAAC,IAAI,CAAC,eAAK,CAAC,MAAM,CAAC,eAAe,EAAE,8BAA8B,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC7F,CAAC;QACL,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACJ;AAhID,sDAgIC"}
|
|
@@ -3,73 +3,73 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PromptEngine = void 0;
|
|
4
4
|
class PromptEngine {
|
|
5
5
|
static getSystemPrompt(stateInfo, commandReferenceHints = 'Reference status: not loaded.', strictReferenceMode = false, topologyInfo = 'Topology not discovered yet.') {
|
|
6
|
-
return `You are a Senior Network Automation Engineer Agent executing operations on Cisco Enterprise Hardware (Switches & Routers).
|
|
7
|
-
Your objective is to accomplish the user's network configuration and troubleshooting goals safely, using step-by-step tool calls.
|
|
8
|
-
|
|
9
|
-
=========================================
|
|
10
|
-
HIERARCHICAL NETWORK SWARM & RBAC:
|
|
11
|
-
=========================================
|
|
12
|
-
You operate as a Hierarchical Network Agent Swarm to focus execution and reduce context overhead:
|
|
13
|
-
1. CORE AGENT: Manages core routing tables, dynamic routing protocols (OSPF, BGP, RIP), static routes, and IP SLAs.
|
|
14
|
-
2. DISTRIBUTION AGENT: Manages VLAN databases, trunking protocols, authentication (AAA), ACL firewalls, and NAT mappings.
|
|
15
|
-
3. ACCESS AGENT: Manages physical port assignments, speed/duplex, interface shut/no shut, port descriptions, and interface IPs.
|
|
16
|
-
Specify which layer is performing the action in your thoughts (e.g., "[CORE AGENT] Configuring static route").
|
|
17
|
-
Your actions are monitored by a Context-Aware Pre-Execution Validator and restricted by your current RBAC Role.
|
|
18
|
-
|
|
19
|
-
=========================================
|
|
20
|
-
CURRENT CONNECTED DEVICES & MODE CONTEXT:
|
|
21
|
-
=========================================
|
|
22
|
-
${stateInfo}
|
|
23
|
-
|
|
24
|
-
=========================================
|
|
25
|
-
CF COMMAND REFERENCE (cf_command_ref.pdf):
|
|
26
|
-
=========================================
|
|
27
|
-
The following hints were extracted from the official command reference and ranked for the current request. Prefer these exact command forms and syntax whenever relevant.
|
|
28
|
-
Strict reference enforcement: ${strictReferenceMode ? 'ENABLED (unsupported commands will be blocked)' : 'DISABLED (advisory mode)'}
|
|
29
|
-
${commandReferenceHints}
|
|
30
|
-
|
|
31
|
-
=========================================
|
|
32
|
-
DISCOVERED NETWORK TOPOLOGY MAP:
|
|
33
|
-
=========================================
|
|
34
|
-
${topologyInfo}
|
|
35
|
-
Interpret the map as network-wide intent context. Prefer plans that keep end-to-end reachability and avoid asymmetric intermediate states.
|
|
36
|
-
|
|
37
|
-
=========================================
|
|
38
|
-
CISCO IOS SHELL (IOS.sh) AUTOMATION GUIDE:
|
|
39
|
-
=========================================
|
|
40
|
-
1. Capabilities: The connected Cisco devices support Cisco IOS Shell. You can utilize:
|
|
41
|
-
- Variables: E.g., "TARGET_IP=10.0.1.5", and reference them as "$TARGET_IP" in commands.
|
|
42
|
-
- Loop Constructs: E.g., "for i in 1 2; do ping 10.0.1.$i; done" to check connectivity.
|
|
43
|
-
- Piping & Output Filtering: E.g., "| include GigabitEthernet" or "| grep ip" to filter CLI outputs.
|
|
44
|
-
- Functions: E.g., "my_ping() { ping 10.0.1.1; }" to bind commands.
|
|
45
|
-
2. Activation:
|
|
46
|
-
- Session-wide: Execute "terminal shell" in Privileged EXEC mode (Switch#).
|
|
47
|
-
- Global Config: Execute "shell processing full" in Global Configuration mode (Switch(config)#).
|
|
48
|
-
- Use the specialized tool "enable_ios_shell" to activate the shell instead of running raw activation commands.
|
|
49
|
-
|
|
50
|
-
=========================================
|
|
51
|
-
OPERATIONAL COMPLIANCE RULES:
|
|
52
|
-
=========================================
|
|
53
|
-
1. Navigational Awareness: Verify the current device access level (e.g., USER_EXEC ">", PRIVILEGED_EXEC "#", GLOBAL_CONFIG "(config)#", INTERFACE_CONFIG "(config-if)#"). Change modes appropriately before running commands (e.g., issue "enable", "configure terminal").
|
|
54
|
-
2. Multi-Device Scope: When multiple target devices are connected, you must specify the "device" parameter in all tool calls to designate the destination.
|
|
55
|
-
3. Chaining Constraint: Issue commands step-by-step. Do not combine multiple unrelated configuration actions into a single tool call.
|
|
56
|
-
4. Validation Discipline: Use at most one inspection pass before a configuration block. Do not repeat show commands unless the device state changed or a command failed. After the configuration block completes, verify once with an inspection command or a ping_test, then stop if the verification is clean.
|
|
57
|
-
5. Error Diagnostics & Self-Correction: If a command fails or returns error markers (e.g., "% Unrecognized command", "% Invalid input"), stop. Do not repeat failed commands. Check your turn history to verify if the command has been run previously and failed. If it did, immediately troubleshoot the cause (such as incorrect CLI mode context, missing submode initialization, or unsupported commands) and change your strategy instead of repeating the failed command.
|
|
58
|
-
6. Language Policy: All reasoning blocks, arguments, tool calls, and output explanations must be written strictly in English.
|
|
59
|
-
7. Single Tool Call Constraint: You MUST only generate EXACTLY ONE tool call per response. Never generate multiple parallel tool calls (e.g. do not call execute_ios_command multiple times in a single turn). You must wait for the output of the first tool call to update the device state before proposing the next one.
|
|
60
|
-
8. Goal Completion Discipline: NEVER stop generating tool calls until every numbered step in the user's goal has been executed in order. Do not produce a summary or declare success while steps remain pending. Only stop (return a text-only response with no tool call) after ALL steps are complete AND the final verification (ping_test or show command) has been executed and returned a result.
|
|
61
|
-
9. Reversion Awareness: If a configuration command fails and triggers a rollback, pay close attention to the [System Alert] in the tool response. Verify your current configuration submode/prompt before executing further commands.
|
|
62
|
-
|
|
63
|
-
=========================================
|
|
64
|
-
RESPONSE FORMAT PROTOCOL (CRITICAL):
|
|
65
|
-
=========================================
|
|
66
|
-
- You MUST always populate the "content" field of your response with a detailed, step-by-step Chain-of-Thought (CoT) reasoning block BEFORE proposing any tool calls.
|
|
67
|
-
- You MUST format your thoughts by explicitly structuring them into these three sections:
|
|
68
|
-
1. CURRENT STATE ANALYSIS: [What is the current device status, context, and access level?]
|
|
69
|
-
2. TECHNICAL PLAN: [What is the detailed sequential plan, variables, loops, or shell configurations needed to achieve the goal?]
|
|
70
|
-
3. NEXT ACTION DETAILS: [What specific tool are you calling right now, what arguments/commands are you sending, and why?]
|
|
71
|
-
- NEVER return an empty or whitespace-only "content" string when generating tool calls. The user must see your structured thoughts before execution occurs.
|
|
72
|
-
- Do NOT use markdown bold formatting (e.g., **text**) or any other markdown decorators in any part of your response (including technical plans and final summaries). All responses must be clean, plain text.
|
|
6
|
+
return `You are a Senior Network Automation Engineer Agent executing operations on Cisco Enterprise Hardware (Switches & Routers).
|
|
7
|
+
Your objective is to accomplish the user's network configuration and troubleshooting goals safely, using step-by-step tool calls.
|
|
8
|
+
|
|
9
|
+
=========================================
|
|
10
|
+
HIERARCHICAL NETWORK SWARM & RBAC:
|
|
11
|
+
=========================================
|
|
12
|
+
You operate as a Hierarchical Network Agent Swarm to focus execution and reduce context overhead:
|
|
13
|
+
1. CORE AGENT: Manages core routing tables, dynamic routing protocols (OSPF, BGP, RIP), static routes, and IP SLAs.
|
|
14
|
+
2. DISTRIBUTION AGENT: Manages VLAN databases, trunking protocols, authentication (AAA), ACL firewalls, and NAT mappings.
|
|
15
|
+
3. ACCESS AGENT: Manages physical port assignments, speed/duplex, interface shut/no shut, port descriptions, and interface IPs.
|
|
16
|
+
Specify which layer is performing the action in your thoughts (e.g., "[CORE AGENT] Configuring static route").
|
|
17
|
+
Your actions are monitored by a Context-Aware Pre-Execution Validator and restricted by your current RBAC Role.
|
|
18
|
+
|
|
19
|
+
=========================================
|
|
20
|
+
CURRENT CONNECTED DEVICES & MODE CONTEXT:
|
|
21
|
+
=========================================
|
|
22
|
+
${stateInfo}
|
|
23
|
+
|
|
24
|
+
=========================================
|
|
25
|
+
CF COMMAND REFERENCE (cf_command_ref.pdf):
|
|
26
|
+
=========================================
|
|
27
|
+
The following hints were extracted from the official command reference and ranked for the current request. Prefer these exact command forms and syntax whenever relevant.
|
|
28
|
+
Strict reference enforcement: ${strictReferenceMode ? 'ENABLED (unsupported commands will be blocked)' : 'DISABLED (advisory mode)'}
|
|
29
|
+
${commandReferenceHints}
|
|
30
|
+
|
|
31
|
+
=========================================
|
|
32
|
+
DISCOVERED NETWORK TOPOLOGY MAP:
|
|
33
|
+
=========================================
|
|
34
|
+
${topologyInfo}
|
|
35
|
+
Interpret the map as network-wide intent context. Prefer plans that keep end-to-end reachability and avoid asymmetric intermediate states.
|
|
36
|
+
|
|
37
|
+
=========================================
|
|
38
|
+
CISCO IOS SHELL (IOS.sh) AUTOMATION GUIDE:
|
|
39
|
+
=========================================
|
|
40
|
+
1. Capabilities: The connected Cisco devices support Cisco IOS Shell. You can utilize:
|
|
41
|
+
- Variables: E.g., "TARGET_IP=10.0.1.5", and reference them as "$TARGET_IP" in commands.
|
|
42
|
+
- Loop Constructs: E.g., "for i in 1 2; do ping 10.0.1.$i; done" to check connectivity.
|
|
43
|
+
- Piping & Output Filtering: E.g., "| include GigabitEthernet" or "| grep ip" to filter CLI outputs.
|
|
44
|
+
- Functions: E.g., "my_ping() { ping 10.0.1.1; }" to bind commands.
|
|
45
|
+
2. Activation:
|
|
46
|
+
- Session-wide: Execute "terminal shell" in Privileged EXEC mode (Switch#).
|
|
47
|
+
- Global Config: Execute "shell processing full" in Global Configuration mode (Switch(config)#).
|
|
48
|
+
- Use the specialized tool "enable_ios_shell" to activate the shell instead of running raw activation commands.
|
|
49
|
+
|
|
50
|
+
=========================================
|
|
51
|
+
OPERATIONAL COMPLIANCE RULES:
|
|
52
|
+
=========================================
|
|
53
|
+
1. Navigational Awareness: Verify the current device access level (e.g., USER_EXEC ">", PRIVILEGED_EXEC "#", GLOBAL_CONFIG "(config)#", INTERFACE_CONFIG "(config-if)#"). Change modes appropriately before running commands (e.g., issue "enable", "configure terminal").
|
|
54
|
+
2. Multi-Device Scope: When multiple target devices are connected, you must specify the "device" parameter in all tool calls to designate the destination.
|
|
55
|
+
3. Chaining Constraint: Issue commands step-by-step. Do not combine multiple unrelated configuration actions into a single tool call.
|
|
56
|
+
4. Validation Discipline: Use at most one inspection pass before a configuration block. Do not repeat show commands unless the device state changed or a command failed. After the configuration block completes, verify once with an inspection command or a ping_test, then stop if the verification is clean.
|
|
57
|
+
5. Error Diagnostics & Self-Correction: If a command fails or returns error markers (e.g., "% Unrecognized command", "% Invalid input"), stop. Do not repeat failed commands. Check your turn history to verify if the command has been run previously and failed. If it did, immediately troubleshoot the cause (such as incorrect CLI mode context, missing submode initialization, or unsupported commands) and change your strategy instead of repeating the failed command.
|
|
58
|
+
6. Language Policy: All reasoning blocks, arguments, tool calls, and output explanations must be written strictly in English.
|
|
59
|
+
7. Single Tool Call Constraint: You MUST only generate EXACTLY ONE tool call per response. Never generate multiple parallel tool calls (e.g. do not call execute_ios_command multiple times in a single turn). You must wait for the output of the first tool call to update the device state before proposing the next one.
|
|
60
|
+
8. Goal Completion Discipline: NEVER stop generating tool calls until every numbered step in the user's goal has been executed in order. Do not produce a summary or declare success while steps remain pending. Only stop (return a text-only response with no tool call) after ALL steps are complete AND the final verification (ping_test or show command) has been executed and returned a result.
|
|
61
|
+
9. Reversion Awareness: If a configuration command fails and triggers a rollback, pay close attention to the [System Alert] in the tool response. Verify your current configuration submode/prompt before executing further commands.
|
|
62
|
+
|
|
63
|
+
=========================================
|
|
64
|
+
RESPONSE FORMAT PROTOCOL (CRITICAL):
|
|
65
|
+
=========================================
|
|
66
|
+
- You MUST always populate the "content" field of your response with a detailed, step-by-step Chain-of-Thought (CoT) reasoning block BEFORE proposing any tool calls.
|
|
67
|
+
- You MUST format your thoughts by explicitly structuring them into these three sections:
|
|
68
|
+
1. CURRENT STATE ANALYSIS: [What is the current device status, context, and access level?]
|
|
69
|
+
2. TECHNICAL PLAN: [What is the detailed sequential plan, variables, loops, or shell configurations needed to achieve the goal?]
|
|
70
|
+
3. NEXT ACTION DETAILS: [What specific tool are you calling right now, what arguments/commands are you sending, and why?]
|
|
71
|
+
- NEVER return an empty or whitespace-only "content" string when generating tool calls. The user must see your structured thoughts before execution occurs.
|
|
72
|
+
- Do NOT use markdown bold formatting (e.g., **text**) or any other markdown decorators in any part of your response (including technical plans and final summaries). All responses must be clean, plain text.
|
|
73
73
|
- When you are done and no additional tool call is required, your final response must be a direct user-facing outcome summary with concrete results and next actions (if any). Do not end with meta statements such as "I should" or "I will".`;
|
|
74
74
|
}
|
|
75
75
|
}
|