ironmonitor 7.1.0

IronMonitor: hardware monitoring for CPUs, GPUs, NPUs, memory, I/O and network silicon on Linux, Windows and macOS, which reports what it cannot read as well as what it can
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
//! AI Agent Format Exporters
//!
//! Export tools and ontology in formats understood by various AI agents.

use super::tools::get_all_tool_definitions;
use super::{ToolCategory, ToolDefinition};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use std::collections::HashMap;

/// Export format for different AI agent systems
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ExportFormat {
    // These name the provider and its wire format, deliberately not the model
    // generations they were current for. A comment listing model names is a comment
    // that will be wrong by the next release, and the format is what actually
    // differs between these variants.
    /// OpenAI function-calling format.
    OpenAI,
    /// Anthropic tool-use format.
    Anthropic,
    /// Google Gemini function-declaration format.
    Gemini,
    /// xAI — OpenAI-compatible format.
    Grok,
    /// Meta Llama, via any host that serves it — OpenAI-compatible format.
    Llama,
    /// Mistral — OpenAI-compatible format.
    Mistral,
    /// DeepSeek — OpenAI-compatible format.
    DeepSeek,
    /// JSON-LD for semantic web discovery
    JsonLd,
    /// Model Context Protocol (Claude Desktop, etc.)
    Mcp,
    /// Simple JSON manifest
    SimpleJson,
}

/// Complete AI agent manifest
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentManifest {
    pub version: String,
    pub name: String,
    pub description: String,
    pub capabilities: Vec<String>,
    pub tools: Vec<ToolDefinition>,
}

impl AgentManifest {
    pub fn new() -> Self {
        Self {
            version: "1.0.0".to_string(),
            name: "IronMonitor".to_string(),
            description: "Comprehensive hardware monitoring for AI agents.".to_string(),
            capabilities: vec![
                "hardware_monitoring".to_string(),
                "gpu_monitoring".to_string(),
                "cpu_monitoring".to_string(),
                "memory_monitoring".to_string(),
                "process_monitoring".to_string(),
            ],
            tools: get_all_tool_definitions(),
        }
    }

    pub fn export(&self, format: ExportFormat) -> Value {
        match format {
            ExportFormat::OpenAI => self.to_openai(),
            ExportFormat::Anthropic => self.to_anthropic(),
            ExportFormat::Gemini => self.to_gemini(),
            ExportFormat::Grok => self.to_grok(),
            ExportFormat::Llama => self.to_llama(),
            ExportFormat::Mistral => self.to_mistral(),
            ExportFormat::DeepSeek => self.to_deepseek(),
            ExportFormat::JsonLd => self.to_json_ld(),
            ExportFormat::Mcp => self.to_mcp(),
            // A serialisation failure is returned as an error object. It used to
            // be `{}`, a valid-looking empty manifest.
            ExportFormat::SimpleJson => serde_json::to_value(self).unwrap_or_else(
                |e| json!({"error": format!("manifest could not be serialised: {e}")}),
            ),
        }
    }

    /// Where to ask a provider what it currently serves.
    ///
    /// This replaced a per-provider `supported_models` array. That array was a
    /// frozen enumeration of model ids, and it was wrong twice over: it went stale
    /// the moment a provider shipped anything (it still advertised `gpt-4o` and
    /// `claude-3-opus-20240229` long after both were superseded), and it was never
    /// true in the first place — this manifest describes *tools*, so any model that
    /// can call tools in the provider's format can consume it. There was nothing to
    /// "support".
    ///
    /// Naming the listing endpoint instead is strictly better for the agent reading
    /// this: it answers the question the array was pretending to answer, it answers
    /// it about the caller's own account rather than about the day this file was
    /// written, and it cannot rot.
    fn model_discovery(endpoint: &str) -> Value {
        json!({
            "endpoint": endpoint,
            "method": "GET",
            "note": "Ask this endpoint for the models this account can reach. \
                     Any model that supports tool calling in this format works; \
                     the `model` field above is only a starting suggestion.",
        })
    }

    fn to_openai(&self) -> Value {
        let functions: Vec<Value> = self
            .tools
            .iter()
            .map(|tool| {
                json!({
                    "type": "function",
                    "function": {
                        "name": tool.name,
                        "description": tool.description,
                        "parameters": tool.parameters,
                    }
                })
            })
            .collect();
        json!({
            "model": crate::agent::DEFAULT_OPENAI_MODEL,
            "tools": functions,
            "tool_choice": "auto",
            "model_discovery": Self::model_discovery("https://api.openai.com/v1/models"),
        })
    }

    fn to_anthropic(&self) -> Value {
        let tools: Vec<Value> = self
            .tools
            .iter()
            .map(|tool| {
                json!({
                    "name": tool.name,
                    "description": tool.description,
                    "input_schema": tool.parameters,
                })
            })
            .collect();
        json!({
            "model": crate::agent::DEFAULT_ANTHROPIC_MODEL,
            "tools": tools,
            "model_discovery": Self::model_discovery("https://api.anthropic.com/v1/models"),
        })
    }

    fn to_gemini(&self) -> Value {
        let function_declarations: Vec<Value> = self
            .tools
            .iter()
            .map(|tool| {
                json!({
                    "name": tool.name,
                    "description": tool.description,
                    "parameters": tool.parameters,
                })
            })
            .collect();
        json!({
            "tools": [{ "function_declarations": function_declarations }],
            "model_discovery": Self::model_discovery(
                "https://generativelanguage.googleapis.com/v1beta/models",
            ),
        })
    }

    fn to_grok(&self) -> Value {
        // xAI Grok uses OpenAI-compatible format
        let functions: Vec<Value> = self
            .tools
            .iter()
            .map(|tool| {
                json!({
                    "type": "function",
                    "function": {
                        "name": tool.name,
                        "description": tool.description,
                        "parameters": tool.parameters,
                    }
                })
            })
            .collect();
        json!({
            "tools": functions,
            "tool_choice": "auto",
            "model_discovery": Self::model_discovery("https://api.x.ai/v1/models"),
        })
    }

    fn to_llama(&self) -> Value {
        // Meta Llama via various providers (Together, Fireworks, etc.) - OpenAI-compatible
        let functions: Vec<Value> = self
            .tools
            .iter()
            .map(|tool| {
                json!({
                    "type": "function",
                    "function": {
                        "name": tool.name,
                        "description": tool.description,
                        "parameters": tool.parameters,
                    }
                })
            })
            .collect();
        json!({
            "tools": functions,
            "tool_choice": "auto",
            // Llama is served by many hosts, each with its own catalogue and its own
            // naming, so there is no one endpoint to name here.
            "model_discovery": {
                "note": "Llama is served by third parties (Together, Fireworks, Groq, \
                         and others). Ask your chosen provider's OpenAI-compatible \
                         `/v1/models` endpoint for the models and exact ids it serves.",
            },
        })
    }

    fn to_mistral(&self) -> Value {
        // Mistral AI - OpenAI-compatible format
        let functions: Vec<Value> = self
            .tools
            .iter()
            .map(|tool| {
                json!({
                    "type": "function",
                    "function": {
                        "name": tool.name,
                        "description": tool.description,
                        "parameters": tool.parameters,
                    }
                })
            })
            .collect();
        json!({
            // A `-latest` alias tracks the current release, so unlike a pinned id
            // this default does not go stale on its own.
            "model": "mistral-large-latest",
            "tools": functions,
            "tool_choice": "auto",
            "model_discovery": Self::model_discovery("https://api.mistral.ai/v1/models"),
        })
    }

    fn to_deepseek(&self) -> Value {
        // DeepSeek - OpenAI-compatible format
        let functions: Vec<Value> = self
            .tools
            .iter()
            .map(|tool| {
                json!({
                    "type": "function",
                    "function": {
                        "name": tool.name,
                        "description": tool.description,
                        "parameters": tool.parameters,
                    }
                })
            })
            .collect();
        json!({
            // DeepSeek's ids name a role rather than a release, so they follow the
            // current model rather than pinning one.
            "model": "deepseek-chat",
            "tools": functions,
            "tool_choice": "auto",
            "model_discovery": Self::model_discovery("https://api.deepseek.com/models"),
        })
    }

    /// The manifest as linked data, **including the tools it is a manifest of**.
    ///
    /// This arm ignored `self.tools` entirely. Every sibling exporter maps the
    /// catalogue into its format's tool schema; this one emitted six fixed keys
    /// naming the application and stopped, so `ironmon ai manifest --format
    /// jsonld` returned 295 bytes where `--format openai` returns 25 KB. Not an
    /// error and not an empty list with a reason: a well-formed document that
    /// describes the program and claims nothing about what it can do, offered
    /// in the CLI's help on equal footing with the formats that answer.
    ///
    /// `potentialAction` is schema.org's property for the actions an entity
    /// supports, which is what a tool is. The parameter schema has no
    /// schema.org vocabulary, so it goes under the `ironmon:` prefix the context
    /// already declares -- the same choice `ontology::jsonld` makes for
    /// `ironmon:unavailableReason`.
    fn to_json_ld(&self) -> Value {
        let actions: Vec<Value> = self
            .tools
            .iter()
            .map(|tool| {
                json!({
                    "@type": "Action",
                    "name": tool.name,
                    "description": tool.description,
                    "ironmon:parameters": tool.parameters,
                })
            })
            .collect();
        json!({
            // The same namespace the ontology publishes, rather than a second
            // one. This read `https://schema.siliconmonitor.dev/` while
            // `ontology::jsonld` used `nervosys.github.io/.../ns#`, so the
            // `ironmon:` prefix meant two different vocabularies depending on
            // which command produced the document. The rename surfaced it; the
            // disagreement predates it.
            "@context": {
                "@vocab": "https://schema.org/",
                "ironmon": crate::ontology::jsonld::IRONMON_NS,
            },
            "@type": "SoftwareApplication",
            "name": self.name,
            "description": self.description,
            "applicationCategory": "SystemUtility",
            "softwareVersion": self.version,
            "potentialAction": actions
        })
    }

    fn to_mcp(&self) -> Value {
        let tools: Vec<Value> = self
            .tools
            .iter()
            .map(|tool| {
                json!({
                    "name": tool.name,
                    "description": tool.description,
                    "inputSchema": tool.parameters,
                })
            })
            .collect();
        json!({
            "name": env!("CARGO_PKG_NAME"),
            "version": self.version,
            "description": self.description,
            "protocol_version": "2024-11-05",
            "capabilities": { "tools": { "listChanged": false } },
            "tools": tools
        })
    }
}

impl Default for AgentManifest {
    fn default() -> Self {
        Self::new()
    }
}

pub fn get_tools_by_category() -> HashMap<ToolCategory, Vec<ToolDefinition>> {
    let tools = get_all_tool_definitions();
    let mut grouped: HashMap<ToolCategory, Vec<ToolDefinition>> = HashMap::new();
    for tool in tools {
        grouped.entry(tool.category).or_default().push(tool);
    }
    grouped
}

#[cfg(test)]
mod model_staleness_tests {
    use super::{AgentManifest, ExportFormat};

    const ALL_FORMATS: &[ExportFormat] = &[
        ExportFormat::OpenAI,
        ExportFormat::Anthropic,
        ExportFormat::Gemini,
        ExportFormat::Grok,
        ExportFormat::Llama,
        ExportFormat::Mistral,
        ExportFormat::DeepSeek,
        ExportFormat::JsonLd,
        ExportFormat::Mcp,
        ExportFormat::SimpleJson,
    ];

    /// The manifest must not carry a frozen catalogue of model ids again.
    ///
    /// Seven of these formats used to ship a `supported_models` array. Each was a
    /// claim about the world on the day it was typed, and every one of them was
    /// wrong within months — the OpenAI entry still advertised `gpt-4o` and the
    /// Anthropic entry `claude-3-opus-20240229`. Nothing consumed them, and they
    /// were never true anyway: this manifest describes tools, and any tool-calling
    /// model can use it. If the key comes back, so does the rot.
    #[test]
    fn no_export_format_ships_a_frozen_model_catalogue() {
        let manifest = AgentManifest::new();
        for format in ALL_FORMATS {
            let exported = manifest.export(*format);
            assert!(
                exported.get("supported_models").is_none(),
                "{format:?} advertises a fixed list of model ids; name the \
                 provider's listing endpoint instead so the answer stays current"
            );
        }
    }

    /// A format that suggests a model must also say how to find a better one, so an
    /// agent reading the manifest is never stuck with the suggestion.
    #[test]
    fn a_suggested_model_comes_with_a_way_to_discover_others() {
        let manifest = AgentManifest::new();
        for format in ALL_FORMATS {
            let exported = manifest.export(*format);
            if exported.get("model").is_some() {
                assert!(
                    exported.get("model_discovery").is_some(),
                    "{format:?} names a default model but gives an agent no way to \
                     learn what else is available"
                );
            }
        }
    }
    /// Every format is a manifest *of the tools*, so every format must carry
    /// them.
    ///
    /// `to_json_ld` did not. It emitted six fixed keys about the application
    /// and dropped the catalogue, and nothing noticed because the document was
    /// valid, the CLI exited zero, and the only test over these formats checked
    /// that they had stopped shipping a frozen model list. A consumer asking
    /// for linked data got a well-formed answer with no tools in it.
    ///
    /// This counts occurrences of a tool's name in the serialised output rather
    /// than knowing each format's shape, deliberately: the assertion should
    /// hold for a format added next year by someone who never reads this file.
    #[test]
    fn every_format_carries_every_tool() {
        let manifest = AgentManifest::new();
        assert!(
            !manifest.tools.is_empty(),
            "the manifest has no tools, so the assertion below would pass \
             vacuously for every format"
        );
        let names: Vec<String> = manifest.tools.iter().map(|t| t.name.clone()).collect();

        let mut missing: Vec<String> = Vec::new();
        for format in ALL_FORMATS {
            let text = manifest.export(*format).to_string();
            let absent: Vec<&String> = names
                .iter()
                .filter(|n| !text.contains(n.as_str()))
                .collect();
            if !absent.is_empty() {
                missing.push(format!(
                    "{format:?} omits {} of {} tools, starting with {}",
                    absent.len(),
                    names.len(),
                    absent[0]
                ));
            }
        }

        assert!(
            missing.is_empty(),
            "a manifest format dropped the tools it is a manifest of:\n  {}",
            missing.join("\n  ")
        );
    }
}