-
Notifications
You must be signed in to change notification settings - Fork 0
Small-model agent UX: follow mode, composite-name guards, prompt consolidation #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c14a176
refactor(agent): consolidate all prompt wording into agent/prompts.py
hellices cb8ade4
feat(agent): follow mode — mirror the agent's cluster reads on screen
hellices 98760de
fix(agent): stop feeding 'namespace/name' composites to the model
hellices 6fbed56
review: deterministic context-split test, docs for agent.follow, docs…
hellices ddbf665
fix: describe-screen mirror guard; symmetric namespace slash guard
hellices 4b0e0ed
fix: agent-follow mirrors route through the shared serialized bridge
hellices 523b6f2
test: prompt invariants assert defining phrases, not loose tokens
hellices c737dbf
fix: ctor-injected follow bridge, composite-safe prompt, polled lock …
hellices f4b7b57
fix: log mirrors also refuse while a describe screen is open
hellices File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| """Every system-prompt string the agent sends, in one place. | ||
|
|
||
| Prompt text is policy (what the model is told), the runtime is mechanism | ||
| (how the loop executes); keeping all wording here means a prompt change | ||
| never touches loop code, and the full/small variants (issue #71) sit side | ||
| by side instead of split across modules. | ||
|
|
||
| Composition (`compose_system_prompt`) lives here too: which clause is | ||
| appended is decided by the *armed tool set*, so the write/no-write and | ||
| UI-drive wording stays next to the rules that select it. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from korvid.tools.executor import UI_TOOL_NAMES, WRITE_TOOL_NAMES | ||
|
|
||
| SYSTEM_PROMPT = ( | ||
| "You are korvid's Kubernetes diagnostic agent, embedded in a live TUI the " | ||
| "user is looking at right now. You explore the cluster only through the " | ||
| "tools provided in this session: you have no shell, you cannot run " | ||
| "kubectl or any command yourself, and you know nothing about this " | ||
| "cluster beyond tool results and the screen context. " | ||
| "Explore before you conclude: list resources to discover what exists, " | ||
| "then inspect the specific objects you found. " | ||
| "Cite evidence from tool results and never guess resource state. " | ||
| "Never invent resource names or namespaces — use only names from tool " | ||
| "results or the screen context, and keep each name paired with the " | ||
| "namespace it was listed in. A 404/NotFound means the name or namespace " | ||
| "is wrong: re-list to find the right one instead of retrying the same " | ||
| "call." | ||
| ) | ||
|
|
||
| # Appended when no write tools are armed (readonly mode or writes not wired): | ||
| # instead of a bare refusal the agent offers the exact kubectl command. | ||
| NO_WRITE_PROMPT = ( | ||
| "You have no write tools in this session: when the user asks you to " | ||
| "modify cluster state (scale, edit, delete, restart, apply), say write " | ||
| "actions are not enabled and give the exact kubectl command they can run " | ||
| "themselves instead." | ||
| ) | ||
|
|
||
| # Appended only when the approval-gated write tools are armed. The armed | ||
| # tool names are prepended dynamically in `compose_system_prompt` so the | ||
| # instruction never omits a conditionally registered tool (resize_pod) or | ||
| # advertises one that was not offered. | ||
| WRITE_PROMPT = ( | ||
| "These never execute directly: each call opens an " | ||
| "approval dialog in the TUI, and the operation runs only if the user " | ||
| "approves it with a keystroke. State clearly what you are about to " | ||
| "request and why before calling a write tool, and report the outcome " | ||
| "(approved, denied, expired, or failed) afterwards. Never retry a denied " | ||
| "or expired request unless the user explicitly asks: an expired request " | ||
| "means nobody answered the dialog, and reissuing it would keep reopening " | ||
| "approval dialogs the user is not acting on." | ||
| ) | ||
|
|
||
| # Appended only when the runtime is armed with the UI-control tools, so the | ||
| # model is never told about capabilities the provider was not offered. | ||
| UI_DRIVE_PROMPT = ( | ||
| "You can also drive the TUI itself: navigate (switch the resource view), " | ||
| "set_filter (narrow the visible rows), open_logs (show a pod's live logs " | ||
| "on screen), open_describe (show a resource's manifest and events), and " | ||
| "drill_down (from a deployment into its replicaset history, from a " | ||
| "replicaset into its pods, or from a helm release into its revision " | ||
| "history — following ownership). " | ||
| "Prefer showing evidence on screen with these tools while you narrate — " | ||
| "for example, when you find a failing pod, open its logs or describe view " | ||
| "so the user sees exactly what you see. These screen tools change nothing " | ||
| "in the cluster. Keep your text concise; the screen carries the detail." | ||
| ) | ||
|
|
||
| #: Short role statement, explicit grounding rules, and ONE worked example | ||
| #: (question -> tool call -> result -> grounded answer) instead of the | ||
| #: longer frontier instruction list (issue #71). | ||
| SMALL_SYSTEM_PROMPT = ( | ||
| "You are korvid's Kubernetes exploration agent, embedded in a live TUI. " | ||
| "You act only through the provided tools: no shell, no kubectl, no " | ||
| "cluster knowledge outside tool results. " | ||
| "Call one tool at a time and wait for its result before deciding the " | ||
| "next step. Never invent resource names or namespaces: use a name and " | ||
| "namespace pair given by the user or the screen context, or discover " | ||
| "one with list_resources first. Its rows start with " | ||
| "'namespace/name' — split that into the separate namespace and name " | ||
| "fields; never paste the combined value into either field. " | ||
| "A 404/NotFound means the name or namespace is wrong — " | ||
| "re-list instead of retrying. Cite evidence from tool results. " | ||
| "Worked example — user: why does pod checkout-1 in namespace shop keep " | ||
| 'restarting? -> you call diagnose_pod with {"pod": "checkout-1", ' | ||
| '"namespace": "shop"} -> the result shows lastState terminated ' | ||
| "exit=137 (OOMKilled) -> you answer: checkout-1 is OOMKilled (exit " | ||
| "code 137); its container exceeds the memory limit, so raise the limit " | ||
| "or reduce usage." | ||
| ) | ||
|
|
||
| #: The full UI_DRIVE_PROMPT advertises all five UI tools; the small profile | ||
| #: offers only the two evidence-showing ones, and the model must never be | ||
| #: told about capabilities it was not offered. | ||
| SMALL_UI_PROMPT = ( | ||
| "You can also show evidence on the user's screen: open_logs (show a " | ||
| "pod's live logs) and open_describe (show a resource's manifest and " | ||
| "events). These change nothing in the cluster. Keep your text concise; " | ||
| "the screen carries the detail." | ||
| ) | ||
|
|
||
| #: Concise tool-description overrides for the small profile — every request | ||
| #: retransmits the schemas, so on a 4k-token serving context the wording is | ||
| #: a real cost (EasyTool). The effect is measurable per endpoint with the | ||
| #: #69 harness (`--profile small`). | ||
| SMALL_TOOL_DESCRIPTIONS: dict[str, str] = { | ||
| "diagnose_pod": ( | ||
| "One-call diagnosis of a broken pod: container states, exit codes, " | ||
| "restart counts, failing conditions, Warning events, node/PVC " | ||
| "context, and log excerpts. Prefer this first when a pod is failing." | ||
| ), | ||
| "list_operators": ( | ||
| "List OLM operator packages and installed subscriptions with their status. Read-only." | ||
| ), | ||
| "helm_list_releases": ( | ||
| "List installed Helm releases with revision, status, chart and app " | ||
| "version. Read-only; parsed from cluster Secrets." | ||
| ), | ||
| "open_logs": "Open the live log pane for a pod on the user's screen.", | ||
| "resize_pod": ( | ||
| "Request an in-place CPU/memory resize of a running pod (Kubernetes " | ||
| "1.35+). Runs only after the user approves it in the TUI dialog." | ||
| ), | ||
| } | ||
|
|
||
|
|
||
| def compose_system_prompt( | ||
| tools: list[dict[str, Any]], | ||
| cluster_context: str | None, | ||
| *, | ||
| system_prompt: str | None = None, | ||
| ui_prompt: str | None = None, | ||
| ) -> str: | ||
| """System prompt for the armed tool set and detected environment. | ||
|
|
||
| Shared by ``AgentRuntime.__init__`` and ``retarget`` so a runtime that | ||
| survives a `:ctx` switch describes the *new* cluster and tool set, not | ||
| the one it was built against. Capability profiles (issue #71) swap the | ||
| role statement and the UI-drive instruction via | ||
| `system_prompt`/`ui_prompt`; the write/no-write clause stays | ||
| conditional on what is actually armed, whichever profile. | ||
| """ | ||
| prompt = system_prompt if system_prompt is not None else SYSTEM_PROMPT | ||
| if cluster_context: | ||
| # Detected-environment note (e.g. cloud provider, issue #30): | ||
| # placed right after the role statement so provider-specific | ||
| # requests are grounded before any tool instructions. | ||
| prompt = f"{prompt} {cluster_context}" | ||
| armed = {t.get("function", {}).get("name") for t in tools} | ||
| if armed & UI_TOOL_NAMES: | ||
| prompt = f"{prompt} {ui_prompt if ui_prompt is not None else UI_DRIVE_PROMPT}" | ||
| armed_writes = sorted(armed & WRITE_TOOL_NAMES) | ||
| if armed_writes: | ||
| names = ", ".join(armed_writes) | ||
| prompt = f"{prompt} You can request cluster writes with {names}. {WRITE_PROMPT}" | ||
| else: | ||
| prompt = f"{prompt} {NO_WRITE_PROMPT}" | ||
| return prompt |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.