Skip to content

ai-assistant: Let the model target a cluster by name - #1291

Open
tejhan wants to merge 1 commit into
headlamp-k8s:mainfrom
tejhan:ai-assistant-cluster-targeting
Open

ai-assistant: Let the model target a cluster by name#1291
tejhan wants to merge 1 commit into
headlamp-k8s:mainfrom
tejhan:ai-assistant-cluster-targeting

Conversation

@tejhan

@tejhan tejhan commented Sep 10, 2026

Copy link
Copy Markdown

Description

From the Home screen, the assistant ignores which cluster you ask about and answers using whatever cluster the host defaults to.

For instance, with the kubeconfig on cluster-2, the prompt "tell me about cluster-1" returns cluster-2's data, many times with no indication anything was substituted. I've attached a screenshot below of an example of the broken behavior:

(In this instance, I've created the clus-2-ns in a-test-cluster-2 to highlight that we're fetching from the wrong cluster, even though my prompt specifies a-test-cluster-1)

Screenshot 2026-09-10 113750

This issue can surface in many different permutations. You can ask about different clusters, different resources, anything, but the underlying assistant will still perform queries on the default cluster, so even if it's not the cluster referred to in the prompt, the data for the default one still surfaces.

Cause

The cause is that kubernetes_api_request only accepts url, method , and body. The model has no way to explicitly name a cluster, so modal.tsx picks one via targetCluster || selectedClusters[0] || getCluster() || Object.keys(clusters)[0]. When inside a cluster view getCluster() returns the right answer, which is why this only shows up from Home.

Changes

  • buildContextDescription.ts: Now lists the available clusters when none is selected, so the model knows what it can pass
  • KubernetesTool.ts : Asdded optional cluster arg, passed through on reads & saved for the confirm dialog when writing.
  • modal.tsx : Now only auto-pick when exactly one cluster is configured
  • Added 4 tests to cover the passing of cluster arg & associated context changes

Note: Both of the new params are optional, so in-cluster and single-cluster behaviour should remain unchanged.

Testing:

  1. Configure 2 clusters in your kubeconfig and set your kubeconfig context to cluster no.2.
  2. Open AI assistant from the home screen
  3. Ask the assistant to list all pods in cluster no.1
  4. Before: Would return pods in cluster no.2 . After: Should list pods in cluster no.1

Signed-off-by: Tejhan <tejhan.diallo@gmail.com>
@tejhan
tejhan force-pushed the ai-assistant-cluster-targeting branch from 64dbb39 to b145ead Compare September 10, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant