From e6e1326689682c304cc8e98b633337a0a9f37ac1 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 11 May 2026 10:40:59 -0500 Subject: [PATCH] feat(insights): allow AI observations to link directly to devices The LLM can now copy device_id from the snapshot into its observation output. The worker wires it into the insight's device_id FK so the UI can link directly to the referenced device. --- lib/towerops/llm/network_insight_prompt.ex | 3 ++- lib/towerops/workers/ai_network_insight_worker.ex | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/towerops/llm/network_insight_prompt.ex b/lib/towerops/llm/network_insight_prompt.ex index 68d8dce0..4f3d3736 100644 --- a/lib/towerops/llm/network_insight_prompt.ex +++ b/lib/towerops/llm/network_insight_prompt.ex @@ -53,7 +53,8 @@ defmodule Towerops.LLM.NetworkInsightPrompt do Respond ONLY with JSON of this shape: {"observations": [ {"title": "...", "description": "...", "urgency": "critical"|"warning"|"info", - "recommended_action": "..."} + "recommended_action": "...", + "device_id": "..." (optional — copy the exact device_id from the snapshot for any device you reference)} ]} Aim for 0–5 observations. Quality over quantity. diff --git a/lib/towerops/workers/ai_network_insight_worker.ex b/lib/towerops/workers/ai_network_insight_worker.ex index 16d213aa..66c35f3c 100644 --- a/lib/towerops/workers/ai_network_insight_worker.ex +++ b/lib/towerops/workers/ai_network_insight_worker.ex @@ -91,7 +91,8 @@ defmodule Towerops.Workers.AiNetworkInsightWorker do llm_summary: obs.description, llm_model: model, llm_enriched_at: now, - metadata: metadata + metadata: metadata, + device_id: Map.get(obs.metadata, "device_id") } case Insights.insert_insight_if_new(attrs) do