fix: include VMID in AI context to prevent incorrect references
The LLM was confusing VMIDs because they weren't included in the context. Now the formatted context shows: ### Container: ollama (VMID 200) on minipc This prevents the AI from referencing the wrong VMID when generating findings and recommendations.
This commit is contained in:
parent
8546112abe
commit
f054012c44
4 changed files with 10 additions and 1 deletions
|
|
@ -112,6 +112,7 @@ func (b *Builder) BuildForInfrastructure(state models.StateSnapshot) *Infrastruc
|
|||
trends := b.computeGuestTrends(vm.ID)
|
||||
resourceCtx := FormatGuestForContext(
|
||||
vm.ID, vm.Name, vm.Node, "vm", vm.Status,
|
||||
vm.VMID,
|
||||
vm.CPU, vm.Memory.Usage, vm.Disk.Usage,
|
||||
vm.Uptime, vm.LastBackup, trends,
|
||||
)
|
||||
|
|
@ -137,6 +138,7 @@ func (b *Builder) BuildForInfrastructure(state models.StateSnapshot) *Infrastruc
|
|||
|
||||
resourceCtx := FormatGuestForContext(
|
||||
ct.ID, ct.Name, ct.Node, containerType, ct.Status,
|
||||
ct.VMID,
|
||||
ct.CPU, ct.Memory.Usage, ct.Disk.Usage,
|
||||
ct.Uptime, ct.LastBackup, trends,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -15,8 +15,11 @@ func FormatResourceContext(ctx ResourceContext) string {
|
|||
// Header with resource identity
|
||||
typeLabel := formatResourceType(ctx.ResourceType)
|
||||
sb.WriteString(fmt.Sprintf("### %s: %s", typeLabel, ctx.ResourceName))
|
||||
if ctx.VMID > 0 {
|
||||
sb.WriteString(fmt.Sprintf(" (VMID %d)", ctx.VMID))
|
||||
}
|
||||
if ctx.Node != "" && ctx.ResourceType != "node" {
|
||||
sb.WriteString(fmt.Sprintf(" (on %s)", ctx.Node))
|
||||
sb.WriteString(fmt.Sprintf(" on %s", ctx.Node))
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
|
||||
|
|
@ -471,6 +474,7 @@ func FormatNodeForContext(node models.Node, trends map[string]Trend) ResourceCon
|
|||
// Note: cpu is 0-1 ratio from Proxmox API, memUsage and diskUsage are already 0-100 percentages
|
||||
func FormatGuestForContext(
|
||||
id, name, node, guestType, status string,
|
||||
vmid int,
|
||||
cpu, memUsage, diskUsage float64,
|
||||
uptime int64,
|
||||
lastBackup time.Time,
|
||||
|
|
@ -481,6 +485,7 @@ func FormatGuestForContext(
|
|||
ResourceType: guestType,
|
||||
ResourceName: name,
|
||||
Node: node,
|
||||
VMID: vmid,
|
||||
CurrentCPU: cpu * 100, // Convert from 0-1 to percentage
|
||||
CurrentMemory: memUsage, // Already 0-100 percentage from Memory.Usage
|
||||
CurrentDisk: diskUsage, // Already 0-100 percentage from Disk.Usage
|
||||
|
|
|
|||
|
|
@ -385,6 +385,7 @@ func TestFormatGuestForContext(t *testing.T) {
|
|||
"pve-1",
|
||||
"vm",
|
||||
"running",
|
||||
100, // VMID
|
||||
0.35, // CPU (0-1)
|
||||
65.0, // Memory (0-100)
|
||||
45.0, // Disk (0-100)
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ type ResourceContext struct {
|
|||
ResourceType string // "node", "vm", "container", "oci_container", "storage", "docker_host"
|
||||
ResourceName string
|
||||
Node string // Parent node (for guests)
|
||||
VMID int // Proxmox VMID for VMs/containers (0 if not applicable)
|
||||
|
||||
// Current state (point-in-time)
|
||||
CurrentCPU float64
|
||||
|
|
|
|||
Loading…
Reference in a new issue