diff --git a/Makefile.custom.mk b/Makefile.custom.mk index 4b7bc54..6fb9ef8 100644 --- a/Makefile.custom.mk +++ b/Makefile.custom.mk @@ -22,7 +22,25 @@ helm-template: ## Render the chart with the CI values. # Prerequisite-only, no recipe: make merges it into the generated helm-test # rule, which keeps its recipe (the helm-unittest run) and gains the lint. .PHONY: helm-test -helm-test: helm-lint helm-toolset-schema-test +helm-test: helm-lint helm-toolset-schema-test helm-require-approval-test + +# Chart 3.0 refuses muster.requireApproval in its templates, not only in the +# values schema: a HelmRelease with disableSchemaValidation must not render the +# agent with neither kagent's flag nor default: Ask. helm-unittest validates +# the schema first, so this check renders with the schema skipped. +.PHONY: helm-require-approval-test +helm-require-approval-test: + @set -eu; \ + for v in true false; do \ + for extra in "" "--set muster.enabled=false" "--set toolset[0]=preset:none"; do \ + if out=$$(helm template example helm/agent --kubeconfig /dev/null --skip-schema-validation \ + --set-string modelConfig.name=schema-test --set muster.requireApproval=$$v $$extra 2>&1); then \ + echo "FAIL: muster.requireApproval=$$v $$extra renders with the schema skipped"; exit 1; \ + fi; \ + echo "$$out" | grep -q 'muster.requireApproval was removed in agent chart 3.0' || { echo "$$out" >&2; exit 1; }; \ + done; \ + done; \ + helm template example helm/agent --kubeconfig /dev/null --skip-schema-validation --set-string modelConfig.name=schema-test --set default=Ask >/dev/null .PHONY: helm-toolset-schema-test helm-toolset-schema-test: diff --git a/README.md b/README.md index 8a58469..e6b85ef 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ labels: The technical resource name defaults to the Helm release name. By default the agent is wired to the platform's muster gateway with **all** of its (dynamic) tools — implicit full access to everything the gateway exposes to the invoking -human. Declare a **toolset** to compose the agent with a subset: +human. Declare a **toolset** (deprecated, see `tools` below) to compose the agent with a subset: ```yaml toolset: @@ -99,6 +99,35 @@ preset), and `toolset:` is reserved. Composition, not authorization: the human's identity and the backends' own authorization remain the boundary. The agent gets no wider access of its own. +### Tools with approval settings + +`tools` replaces the deprecated `toolset`. An item is a selector or a one-key +object giving it a setting (`Allow`, `Ask` or `Block`, case-sensitive); +`default` is the setting of every listed tool without its own. + +```yaml +tools: # 1 to 32 items; unlisted tools are invisible + - server:pagerduty # visible; the connector's settings apply + - server:github: Ask # every GitHub tool asks, new ones too + - tool:x_github_merge_pull_request: Allow # holds over the connector's Ask only with a grant + - tool:x_github_delete_repository: Block # hidden from the agent +default: Ask # optional +``` + +- The selectors alone render as `toolset` does (`X-Muster-Toolset`; + `["preset:none"]` renders no `RemoteMCPServer` and no muster binding). + Settings and `default` render as the header `X-Muster-Tool-Approval`, which + muster applies where no Session binding carries settings (it only tightens). + agent-manager binds them, with grants, to every Session it starts; only + those bindings hold whatever the runtime does. +- The render fails for `tools` with `toolset`, a duplicate selector, + `preset:none` beside other entries or with a setting or `default`, and any + value but `Allow`, `Ask` or `Block`. +- An `Allow` over a connector's `Ask` needs a grant by a connector admin + through agent-manager's `set_agent_approval`; without it the `Ask` stays. +- `muster.requireApproval` is removed in chart 3.0 (the schema refuses it): + use `default: Ask`, see [Migrating from 2.x](#migrating-from-2x). + `muster.tools` narrows the binding to a subset of muster's *meta-tools* (`list_tools`, `call_tool`, ...), not the tools behind the gateway — a toolset is the way to narrow those. A Harness enforces a partial selection only when @@ -398,6 +427,31 @@ namespace's default model, the ModelConfig annotated or to any other ModelConfig in the namespace. A release that already sets `modelConfig.name` upgrades unchanged. +Chart 3.0 also removes `muster.requireApproval`, in the schema and the +templates (also with schema validation skipped): a 2.x release still carrying +it fails its 3.0 render and stays on its 2.x revision until its values change. +Replace `true` with `default: Ask` (muster asks a person before every tool +call, where kagent's flag paused the agent), never just delete it; `false` is +dropped. A release that also sets `tools` settings or `default` never rendered +before: choose its settings by hand. + +```diff + muster: +- requireApproval: true ++default: Ask +``` + +agent-manager's `migrate` (run by the Agent Platform upgrade to the 3.x line) +does both rewrites before it moves a namespace's chart source: `requireApproval: +true` becomes `default: Ask` (only where the muster binding renders), and an +unset `modelConfig.name` is written as `default-model-config`. Releases in +organization namespaces that migrate manages are rewritten the same way. A +GitOps-owned release gets the change as a diff in the report; apply it together +with the move of the source's range to 3.x. A release with `spec.valuesFrom` or +one whose source migrate cannot move is reported, never written. Readiness is +reported through the ready mark the operator waits for (with the release's UID +and generation). + ## Migrating from 1.x Chart 2.0 renders the kagent API that ships the `Agent` kind diff --git a/helm/agent/README.md b/helm/agent/README.md index a03f847..f5ef207 100644 --- a/helm/agent/README.md +++ b/helm/agent/README.md @@ -42,15 +42,16 @@ What an agent can reach and how to add a host (`agent.egress`): [What an agent c | plugins | list | `[]` | Plugins, each pinned to an immutable source like a skill. An entry is `{git: {url, commit}, path, skills: [...]}` or `{oci: , path, skills: [...]}`. An Agent Plugins format package (`plugin.json` at its root) enables only the skills `skills` names (optional, unique, never a name `skills[]` or another plugin already uses), and its `mcp.json` servers load either way. A Claude Code format plugin (`.claude-plugin/plugin.json`) loads whole on the `claude` Harness, its hooks, commands and subagents included, and needs no `skills`. Rendered into the Agent's spec.template.plugins[] as `{source: {git | oci, path}, skills}`, `skills` only when set. The pinning rules of `skills[]` apply (a branch, a tag, a short SHA or an OCI tag fails the render), and `skillsGitAuthSecretRef` reaches every git plugin the way it reaches every git skill. | | skillsGitAuthSecretRef | object | `{"name":""}` | One read credential for every private git skill and git plugin. The chart never creates the Secret; the tenant provisions it in the agent's namespace (on the platform: the namespace the agents are compiled in), or agent-manager mints it. | | skillsGitAuthSecretRef.name | string | `""` | Name of a Secret in the agent's namespace whose key `token` holds `base64(":")` (on GitHub `x-access-token:`) with read access to the agent's private git skills and plugins; the egress gateway sends it as `Authorization: Basic` to every request to that host, public repositories included. When set, every `skills[]` and `plugins[]` entry with `git` renders `source.git.credentialRef: {name, key: token}`; OCI sources are unchanged. Empty (the default) renders anonymous fetches. Requires an `https://` URL on every git skill and plugin: the CRD refuses a credential on any other source, and the chart fails the render first, naming the entry. Rotate the Secret's contents, never its name. The full contract and its failure modes: the README's "Private skill repositories". | -| muster | object | `{"discovery":{"enabled":false},"enabled":true,"requireApproval":false,"timeout":"60m","tools":[],"url":"http://muster.agent-platform.svc.cluster.local:8090/mcp"}` | The platform's muster MCP gateway. Unless the agent is chat-only (toolset exactly `["preset:none"]`) or `enabled` is false, the chart renders a RemoteMCPServer named after the agent that points at muster and carries the toolset header, and binds it into the Agent's spec.template.tools. | +| muster | object | `{"discovery":{"enabled":false},"enabled":true,"timeout":"60m","tools":[],"url":"http://muster.agent-platform.svc.cluster.local:8090/mcp"}` | The platform's muster MCP gateway. Unless the agent is chat-only (toolset exactly `["preset:none"]`) or `enabled` is false, the chart renders a RemoteMCPServer named after the agent that points at muster and carries the toolset header, and binds it into the Agent's spec.template.tools. | | muster.enabled | bool | `true` | Wire muster into the agent's tools: render the agent's RemoteMCPServer and bind it in the Agent's template. | | muster.url | string | `"http://muster.agent-platform.svc.cluster.local:8090/mcp"` | URL of muster's MCP endpoint, rendered into the RemoteMCPServer's spec.url. The default is the platform's in-cluster URL; set it for an installation whose muster is elsewhere. | | muster.timeout | string | `"60m"` | How long one tool call through muster may run before the agent's runtime cancels it, rendered as given into the RemoteMCPServer's spec.timeout (a duration with a unit: `180s`, `5m`). Without the field kagent applies its own 30 s, which cuts a backend tool that legitimately runs longer — a write that creates a repository and opens a pull request in one call, a watch that blocks for minutes — although muster's own per-server budget for that backend allows more. The default is muster's progress cap (an MCPServer's `progress.maxDuration`, at most an hour): kagent applies the value to the whole request, which no MCP progress notification restarts, so a wait kept alive by progress (devctl's `pr_wait`, `pr_merge`, `release_wait`) returns its verdict in one call; muster still bounds every call by its backend's own `spec.timeout`, restarted by that progress, so a call is bounded by its backend, not by the caller. | | muster.tools | list | `[]` | Set to narrow the binding to a subset of muster's meta-tools (`list_tools`, `call_tool`, ...); leave empty to bind every tool. Rendered into the binding's `tools`. A toolset is the way to narrow the tools behind the gateway. A Harness enforces a partial selection only when it can discover the server's tools; with discovery off (the default) it may expose the whole server and report a warning in the Agent's status.warnings. | -| muster.requireApproval | bool | `false` | Pause the agent before every tool call through muster until a person approves it. Rendered as `requireApproval: true` on the binding (kagent's human-in-the-loop): the Harness stops the task at `input-required` for each call and continues with the person's decision. It applies to the tools the binding exposes — `tools` when set, otherwise every muster tool. A client that negotiates kagent's HITL A2A extension (`https://kagent.dev/extensions/hitl/v1`) receives the structured `tool_approval_request` and answers it; one that does not sees a plain notice that human input is required. Off by default: the agent calls tools without asking. | | muster.discovery | object | `{"enabled":false}` | Tool discovery by the kagent controller against muster. | | muster.discovery.enabled | bool | `false` | Let the kagent controller list muster's tools when it reconciles the RemoteMCPServer. Off by default: muster is an OAuth resource server and the controller holds no user token, so the chart labels the server `kagent.dev/discovery: disabled` and the agent resolves its tools at run time as the signed-in person. Turn on only for a muster without OAuth. | -| toolset | list | unset: implicit full access, renders no header | The tools the agent is composed with: a list of selectors that muster resolves per request. Selectors are `preset:`, `server:`, `workflow:` or `tool:` with exact, case-sensitive names (regex `^(preset|server|workflow|tool):[^\s,]+$`); at most 128 inline and 8192 UTF-8 bytes joined by commas, define a preset for more. `toolset:` is reserved and refused; patterns, excludes, the read-only predicate and `label:` exist only inside presets. Rendered as the static `X-Muster-Toolset` header on the agent's RemoteMCPServer (`spec.headersFrom`, the selectors joined by `,`). Exactly `["preset:none"]` renders NO RemoteMCPServer and no muster binding at all, so a chat-only agent pays no context for meta-tools; an empty list fails the render (say `preset:none` instead). Unset (the default) renders no header and the agent keeps implicit full access to everything the gateway exposes to the invoking human. Built-in presets: `read-only`, `none`, `full`; the platform charts ship `infrastructure` and `agent-platform`. Composition, not authorization: the human's identity and the backends' own authorization stay the boundary. | +| tools | list | unset: implicit full access, renders no header | The tools the agent is composed with, 1 to 32 items; replaces `toolset`. An item is a selector (`preset:`, `server:`, `workflow:` or `tool:`, exact and case-sensitive, each once) or a one-key object giving it `Allow`, `Ask` or `Block`, e.g. `- server:github: Ask`. Unlisted tools are invisible. The selectors render as `toolset` does (exactly `["preset:none"]` renders no RemoteMCPServer and takes no setting or other entry); settings and `default` render as the header `X-Muster-Tool-Approval`, which muster applies where no Session binding carries them, and agent-manager binds them per Session. An `Allow` over a connector's `Ask` needs a grant by a connector admin through agent-manager's `set_agent_approval`. `tools` with `toolset` fails the render. | +| default | string | unset: no default | The setting of every tool in `tools` without its own: `Allow`, `Ask` or `Block` (case-sensitive). `default: Ask` replaces the removed `muster.requireApproval: true`. | +| toolset | list | unset: implicit full access, renders no header | Deprecated, use `tools`. The tools the agent is composed with: a list of selectors that muster resolves per request. Selectors are `preset:`, `server:`, `workflow:` or `tool:` with exact, case-sensitive names (regex `^(preset|server|workflow|tool):[^\s,]+$`); at most 128 inline and 8192 UTF-8 bytes joined by commas, define a preset for more. `toolset:` is reserved and refused; patterns, excludes, the read-only predicate and `label:` exist only inside presets. Rendered as the static `X-Muster-Toolset` header on the agent's RemoteMCPServer (`spec.headersFrom`, the selectors joined by `,`). Exactly `["preset:none"]` renders NO RemoteMCPServer and no muster binding at all, so a chat-only agent pays no context for meta-tools; an empty list fails the render (say `preset:none` instead). Unset (the default) renders no header and the agent keeps implicit full access to everything the gateway exposes to the invoking human. Built-in presets: `read-only`, `none`, `full`; the platform charts ship `infrastructure` and `agent-platform`. Composition, not authorization: the human's identity and the backends' own authorization stay the boundary. | | extraTools | list | `[]` | Additional raw api.kagent.dev/v1alpha3 tool bindings appended after the muster binding: `{mcp: {server: {kind: RemoteMCPServer, name}, tools, requireApproval}}` or `{subAgent: {name, description, templateRef: {name}}}` (`agentRef` in place of `templateRef` names an Agent; the runtime does not compile it yet). Servers, templates and agents are referenced in the agent's own namespace. | | labels | object | `{}` | Extra labels merged over the standard set on both objects, e.g. tenant/owner dimensions. They win over the standard set on both objects. | | annotations | object | `{}` | Extra annotations merged next to the display-name, icon-url and tags annotations on the Agent. ui.giantswarm.io/display-name, icon-url and tags are refused here; set agent.displayName, agent.iconUrl and agent.tags. | diff --git a/helm/agent/ci/tools-settings-values.yaml b/helm/agent/ci/tools-settings-values.yaml new file mode 100644 index 0000000..e194243 --- /dev/null +++ b/helm/agent/ci/tools-settings-values.yaml @@ -0,0 +1,11 @@ +# ct lint case: tools with Allow/Ask/Block settings and a default. The +# selectors render as the X-Muster-Toolset header; settings and default render +# nothing. +tools: + - server:pagerduty + - server:github: Ask + - tool:x_github_merge_pull_request: Allow + - tool:x_github_delete_repository: Block +default: Ask +modelConfig: + name: demo-model diff --git a/helm/agent/templates/_helpers.tpl b/helm/agent/templates/_helpers.tpl index d6aa1a5..0112d74 100644 --- a/helm/agent/templates/_helpers.tpl +++ b/helm/agent/templates/_helpers.tpl @@ -106,68 +106,151 @@ the agent.* values. Empty when there is nothing to render. {{- end -}} {{/* -Validate the toolset: a list of selector strings, each preset:, -server:, workflow: or tool:. Unset means implicit full -access (no header); an empty list is refused so it can never silently mean -full access; more than 128 selectors is refused (define a preset instead); +Resolve and validate the agent's tool list. `tools` (selector strings or +one-key objects {selector: Allow|Ask|Block}) replaces the deprecated `toolset` +(selector strings); both set fails. Prints the effective selectors, settings +stripped, as a JSON array; prints nothing when neither is set (implicit full +access). Settings and `default` are read by agent-manager from the release +values and render nothing. + +Selectors are preset:, server:, workflow: or tool:. +An empty list is refused so it can never silently mean full access; more than +128 selectors (`tools`: 32) is refused (define a preset instead); toolset: is reserved for shared toolsets; label: exists only inside -presets. Fails the render with the offending selector. +presets. `tools` also refuses a duplicated selector, preset:none next to other +entries or with a setting (or `default`), and muster.requireApproval (removed +in 3.0) whatever its value, also when the values schema is skipped +(HelmRelease disableSchemaValidation). Fails the render with the offending +value. */}} -{{- define "agent.toolset.validate" -}} -{{- $ts := .Values.toolset -}} -{{- if not (kindIs "invalid" $ts) -}} - {{- if not (kindIs "slice" $ts) -}} - {{- fail (printf "toolset must be a list of selector strings, got %s" (kindOf $ts)) -}} +{{- define "agent.tools.resolve" -}} +{{- if and (kindIs "map" .Values.muster) (hasKey .Values.muster "requireApproval") -}} + {{- fail "muster.requireApproval was removed in agent chart 3.0: set default: Ask instead (muster asks a person before every tool call; agent-manager's migrate rewrites requireApproval: true to it). Remove the key, true or false" -}} +{{- end -}} +{{- $name := "toolset" -}} +{{- $items := .Values.toolset -}} +{{- if not (kindIs "invalid" .Values.tools) -}} + {{- if not (kindIs "invalid" .Values.toolset) -}} + {{- fail "tools and toolset are both set: use tools only (toolset is deprecated)" -}} + {{- end -}} + {{- $name = "tools" -}} + {{- $items = .Values.tools -}} +{{- end -}} +{{- $settings := false -}} +{{- if not (kindIs "invalid" .Values.default) -}} + {{- if not (has .Values.default (list "Allow" "Ask" "Block")) -}} + {{- fail (printf "default %v is invalid: expected Allow, Ask or Block (case-sensitive)" .Values.default) -}} + {{- end -}} + {{- $settings = true -}} +{{- end -}} +{{- $selectors := list -}} +{{- if not (kindIs "invalid" $items) -}} + {{- if not (kindIs "slice" $items) -}} + {{- fail (printf "%s must be a list of selector strings, got %s" $name (kindOf $items)) -}} + {{- end -}} + {{- if eq (len $items) 0 -}} + {{- fail (printf "%s is empty: an agent without tools declares %s: [\"preset:none\"]; leave %s unset for implicit full access to everything the gateway exposes" $name $name $name) -}} {{- end -}} - {{- if eq (len $ts) 0 -}} - {{- fail "toolset is empty: an agent without tools declares toolset: [\"preset:none\"]; leave toolset unset for implicit full access to everything the gateway exposes" -}} + {{- if and (eq $name "tools") (gt (len $items) 32) -}} + {{- fail (printf "tools has %d items, above the limit of 32: define a preset (muster toolsetPresets) and select it with preset:" (len $items)) -}} {{- end -}} - {{- range $ts -}} - {{- if not (kindIs "string" .) -}} - {{- fail (printf "toolset selector %v must be a string" .) -}} + {{- range $items -}} + {{- $sel := . -}} + {{- if and (eq $name "tools") (kindIs "map" .) -}} + {{- if ne (len .) 1 -}} + {{- fail (printf "tools item %v must have exactly one key (a selector), got %d" . (len .)) -}} + {{- end -}} + {{- range $k, $v := . -}} + {{- $sel = $k -}} + {{- if not (has $v (list "Allow" "Ask" "Block")) -}} + {{- fail (printf "tools entry %q has the setting %v: expected Allow, Ask or Block (case-sensitive)" $k $v) -}} + {{- end -}} + {{- end -}} + {{- $settings = true -}} {{- end -}} - {{- if hasPrefix "toolset:" . -}} - {{- fail (printf "toolset selector %q: toolset: is reserved for shared toolsets" .) -}} + {{- if not (kindIs "string" $sel) -}} + {{- fail (printf "%s selector %v must be a string" $name $sel) -}} {{- end -}} - {{- if hasPrefix "label:" . -}} - {{- fail (printf "toolset selector %q: label: selectors are allowed inside presets only" .) -}} + {{- if hasPrefix "toolset:" $sel -}} + {{- fail (printf "%s selector %q: toolset: is reserved for shared toolsets" $name $sel) -}} {{- end -}} - {{- if not (regexMatch `^(preset|server|workflow|tool):[^\s,]+$` .) -}} - {{- fail (printf "toolset selector %q is invalid: expected preset:, server:, workflow: or tool: (exact name, no whitespace or commas)" .) -}} + {{- if hasPrefix "label:" $sel -}} + {{- fail (printf "%s selector %q: label: selectors are allowed inside presets only" $name $sel) -}} {{- end -}} + {{- if not (regexMatch `^(preset|server|workflow|tool):[^\s,]+$` $sel) -}} + {{- fail (printf "%s selector %q is invalid: expected preset:, server:, workflow: or tool: (exact name, no whitespace or commas)" $name $sel) -}} + {{- end -}} + {{- if and (eq $name "tools") (has $sel $selectors) -}} + {{- fail (printf "tools selector %q is listed more than once: a selector appears once, with or without a setting" $sel) -}} + {{- end -}} + {{- $selectors = append $selectors $sel -}} {{- end -}} - {{- $bytes := len (join "," $ts) -}} + {{- $bytes := len (join "," $selectors) -}} {{- if gt $bytes 8192 -}} - {{- fail (printf "toolset encodes to %d bytes, above the inline limit of 8192: define a preset (muster toolsetPresets) and select it with preset:" $bytes) -}} + {{- fail (printf "%s encodes to %d bytes, above the inline limit of 8192: define a preset (muster toolsetPresets) and select it with preset:" $name $bytes) -}} + {{- end -}} + {{- if and (eq $name "tools") (has "preset:none" $selectors) -}} + {{- if gt (len $selectors) 1 -}} + {{- fail "tools: preset:none cannot be combined with other entries: a chat-only agent declares tools: [\"preset:none\"]" -}} + {{- end -}} + {{- if $settings -}} + {{- fail "tools: preset:none cannot carry a setting (Allow, Ask or Block) and has no default: a chat-only agent has no tools to approve" -}} + {{- end -}} {{- end -}} {{- end -}} +{{- if $selectors -}}{{ toJson $selectors }}{{- end -}} {{- end -}} {{/* -"true" when the toolset is exactly ["preset:none"]: the agent has no tools, -so neither the RemoteMCPServer nor the muster binding is rendered. The ifs -are nested: Helm built with Go before 1.18 (the ct image) evaluates every -argument of `and`, so `len` would run on an unset toolset. +The agent's approval settings as the X-Muster-Tool-Approval header value: +"=" per tools entry with a setting, then "default=", +joined by commas; empty without settings. muster applies it to requests that +no Session binding with agent-manager's settings covers (Sessions not started +through agent-manager): it carries no grants, so it can only make tools +stricter than their connectors' settings. */}} -{{- define "agent.toolset.isNone" -}} -{{- $ts := .Values.toolset -}} -{{- if kindIs "slice" $ts -}} - {{- if eq (len $ts) 1 -}} - {{- if eq (index $ts 0) "preset:none" -}}true{{- end -}} +{{- define "agent.tools.approvalHeader" -}} +{{- $parts := list -}} +{{- if not (kindIs "invalid" .Values.tools) -}} + {{- range .Values.tools -}} + {{- if kindIs "map" . -}} + {{- range $k, $v := . -}} + {{- $parts = append $parts (printf "%s=%s" $k $v) -}} + {{- end -}} + {{- end -}} {{- end -}} {{- end -}} +{{- if not (kindIs "invalid" .Values.default) -}} + {{- $parts = append $parts (printf "default=%s" .Values.default) -}} +{{- end -}} +{{- join "," $parts -}} +{{- end -}} + +{{/* +Validate the tool list (see agent.tools.resolve); prints nothing. +*/}} +{{- define "agent.toolset.validate" -}} +{{- $_ := include "agent.tools.resolve" . -}} {{- end -}} {{/* -The X-Muster-Toolset header value: the selectors joined by "," (no spaces). -Empty when the toolset is unset. +"true" when the tool list is exactly ["preset:none"]: the agent has no tools, +so neither the RemoteMCPServer nor the muster binding is rendered. +*/}} +{{- define "agent.toolset.isNone" -}} +{{- if eq (include "agent.tools.resolve" .) "[\"preset:none\"]" -}}true{{- end -}} +{{- end -}} + +{{/* +The X-Muster-Toolset header value: the selectors (settings stripped) joined by +"," (no spaces). Empty when neither tools nor toolset is set. */}} {{- define "agent.toolset.header" -}} -{{- if kindIs "slice" .Values.toolset -}}{{ join "," .Values.toolset }}{{- end -}} +{{- with include "agent.tools.resolve" . -}}{{ join "," (fromJsonArray .) }}{{- end -}} {{- end -}} {{/* -"true" when the agent is bound to muster: muster.enabled and the toolset is +"true" when the agent is bound to muster: muster.enabled and the tool list is not exactly ["preset:none"]. Gates the RemoteMCPServer and the binding alike. */}} {{- define "agent.musterBinding" -}} @@ -356,9 +439,6 @@ tools: tools: {{- toYaml . | nindent 8 }} {{- end }} - {{- if .Values.muster.requireApproval }} - requireApproval: true - {{- end }} {{- end }} {{- with .Values.extraTools }} {{- toYaml . | nindent 2 }} diff --git a/helm/agent/templates/remotemcpserver.yaml b/helm/agent/templates/remotemcpserver.yaml index 5a2c27c..b5f4850 100644 --- a/helm/agent/templates/remotemcpserver.yaml +++ b/helm/agent/templates/remotemcpserver.yaml @@ -18,9 +18,17 @@ spec: url: {{ .Values.muster.url | quote }} protocol: STREAMABLE_HTTP timeout: {{ .Values.muster.timeout }} - {{- with include "agent.toolset.header" . }} + {{- $toolset := include "agent.toolset.header" . }} + {{- $approval := include "agent.tools.approvalHeader" . }} + {{- if or $toolset $approval }} headersFrom: + {{- with $toolset }} - name: X-Muster-Toolset value: {{ . | quote }} + {{- end }} + {{- with $approval }} + - name: X-Muster-Tool-Approval + value: {{ . | quote }} + {{- end }} {{- end }} {{- end }} diff --git a/helm/agent/tests/agent_test.yaml b/helm/agent/tests/agent_test.yaml index 39afd66..e11695b 100644 --- a/helm/agent/tests/agent_test.yaml +++ b/helm/agent/tests/agent_test.yaml @@ -972,47 +972,13 @@ tests: - list_tools - call_tool - - it: gates every muster tool call behind a human approval with muster.requireApproval + - it: refuses muster.requireApproval, removed in chart 3.0 (default Ask replaces it) set: muster: requireApproval: true - asserts: - - lengthEqual: - path: spec.template.tools - count: 1 - - equal: - path: spec.template.tools[0].mcp.server.name - value: demo - - equal: - path: spec.template.tools[0].mcp.requireApproval - value: true - - notExists: - path: spec.template.tools[0].mcp.tools - - - it: gates the narrowed binding when muster.requireApproval and muster.tools are combined - set: - muster: - requireApproval: true - tools: - - call_tool - asserts: - - equal: - path: spec.template.tools[0].mcp - value: - server: - kind: RemoteMCPServer - name: demo - tools: - - call_tool - requireApproval: true - - - it: refuses a non-boolean muster.requireApproval through the values schema - set: - muster: - requireApproval: "yes" asserts: - failedTemplate: - errorPattern: 'muster[./]requireApproval' + errorPattern: 'additional properties .requireApproval. not allowed' - it: appends extraTools after the muster binding set: @@ -1052,16 +1018,6 @@ tests: - notExists: path: spec.template.tools - - it: renders no tools for ["preset:none"] even with muster.requireApproval - set: - toolset: - - preset:none - muster: - requireApproval: true - asserts: - - notExists: - path: spec.template.tools - - it: renders only the extraTools for ["preset:none"] with extraTools set: toolset: diff --git a/helm/agent/tests/remotemcpserver_test.yaml b/helm/agent/tests/remotemcpserver_test.yaml index a29e6af..4231d19 100644 --- a/helm/agent/tests/remotemcpserver_test.yaml +++ b/helm/agent/tests/remotemcpserver_test.yaml @@ -61,23 +61,6 @@ tests: - notMatchRegexRaw: pattern: '(?i)authorization' - - it: is untouched by muster.requireApproval (the pause is the binding's, not the server's) - set: - muster: - requireApproval: true - asserts: - - hasDocuments: - count: 1 - - notMatchRegexRaw: - pattern: requireApproval - - equal: - path: spec - value: - description: muster MCP gateway of agent demo (implicit full access) - url: http://muster.agent-platform.svc.cluster.local:8090/mcp - protocol: STREAMABLE_HTTP - timeout: 60m - - it: follows agent.name set: agent: diff --git a/helm/agent/tests/tools_test.yaml b/helm/agent/tests/tools_test.yaml new file mode 100644 index 0000000..a90b55c --- /dev/null +++ b/helm/agent/tests/tools_test.yaml @@ -0,0 +1,323 @@ +# Render tests for `tools` and `default` (tool approval settings): the +# selectors render exactly as `toolset` does, settings and `default` render as +# X-Muster-Tool-Approval, and the combinations the chart refuses fail with a message that +# names the value. +# +# Run with: make helm-test (helm unittest helm/agent). +suite: tools +templates: + - templates/remotemcpserver.yaml + - templates/agent.yaml +release: + name: demo + namespace: demo-ns +set: + modelConfig.name: demo-model +tests: + # tools without settings == toolset + - it: renders tools without settings as the same header as toolset + set: + tools: + - preset:read-only + - workflow:incident-triage + asserts: + - equal: + path: spec.headersFrom + value: + - name: X-Muster-Toolset + value: preset:read-only,workflow:incident-triage + template: templates/remotemcpserver.yaml + - equal: + path: spec.description + value: muster MCP gateway of agent demo (toolset preset:read-only,workflow:incident-triage) + template: templates/remotemcpserver.yaml + - equal: + path: spec.template.tools[0].mcp.server.name + value: demo + template: templates/agent.yaml + + # tools with settings: the selectors, settings stripped + - it: renders the selectors of tools with settings and nothing else + set: + tools: + - server:pagerduty + - server:github: Ask + - tool:x_github_merge_pull_request: Allow + - tool:x_github_delete_repository: Block + asserts: + - hasDocuments: + count: 1 + template: templates/remotemcpserver.yaml + - equal: + path: spec.headersFrom + value: + - name: X-Muster-Toolset + value: server:pagerduty,server:github,tool:x_github_merge_pull_request,tool:x_github_delete_repository + - name: X-Muster-Tool-Approval + value: server:github=Ask,tool:x_github_merge_pull_request=Allow,tool:x_github_delete_repository=Block + template: templates/remotemcpserver.yaml + - equal: + path: spec.description + value: muster MCP gateway of agent demo (toolset server:pagerduty,server:github,tool:x_github_merge_pull_request,tool:x_github_delete_repository) + template: templates/remotemcpserver.yaml + - lengthEqual: + path: spec.template.tools + count: 1 + template: templates/agent.yaml + - notExists: + path: spec.template.tools[0].mcp.requireApproval + template: templates/agent.yaml + + - it: renders default into X-Muster-Tool-Approval + set: + tools: + - server:github + default: Ask + asserts: + - equal: + path: spec.headersFrom + value: + - name: X-Muster-Toolset + value: server:github + - name: X-Muster-Tool-Approval + value: default=Ask + template: templates/remotemcpserver.yaml + - notExists: + path: spec.template.tools[0].mcp.requireApproval + template: templates/agent.yaml + - notMatchRegex: + path: spec.description + pattern: Ask + template: templates/remotemcpserver.yaml + + - it: renders a chat-only agent for tools ["preset:none"] + set: + tools: + - preset:none + asserts: + - hasDocuments: + count: 0 + template: templates/remotemcpserver.yaml + - notExists: + path: spec.template.tools + template: templates/agent.yaml + + # failures + - it: fails when tools and toolset are both set + set: + tools: + - server:a + toolset: + - server:a + asserts: + - failedTemplate: + errorPattern: tools and toolset are both set + template: templates/remotemcpserver.yaml + + - it: fails on a duplicated selector in tools + set: + tools: + - server:github + - server:github: Ask + asserts: + - failedTemplate: + errorPattern: 'tools selector "server:github" is listed more than once' + template: templates/remotemcpserver.yaml + + - it: fails on preset:none with a setting + set: + tools: + - preset:none: Ask + asserts: + - failedTemplate: + errorPattern: 'tools: preset:none cannot carry a setting' + template: templates/remotemcpserver.yaml + + - it: fails on preset:none with default + set: + tools: + - preset:none + default: Ask + asserts: + - failedTemplate: + errorPattern: 'tools: preset:none cannot carry a setting' + template: templates/remotemcpserver.yaml + + - it: fails on preset:none with other entries + set: + tools: + - preset:none + - server:github + asserts: + - failedTemplate: + errorPattern: 'tools: preset:none cannot be combined with other entries' + template: templates/remotemcpserver.yaml + + # chart 3.0: muster.requireApproval is gone; `default: Ask` replaces it + - it: refuses muster.requireApproval through the values schema (removed in 3.0) + set: + muster: + requireApproval: true + tools: + - server:github + asserts: + - failedTemplate: + errorPattern: requireApproval + + - it: refuses muster.requireApproval false too (the key is gone, not only the flag) + set: + muster: + requireApproval: false + asserts: + - failedTemplate: + errorPattern: requireApproval + + # The template's own refusal (schema skipped) is pinned by + # `make helm-require-approval-test`: helm-unittest validates the schema + # first, whose message would satisfy any pattern here. + + - it: renders default Ask, what muster.requireApproval true becomes, as a header and no kagent flag + set: + toolset: + - server:github + default: Ask + asserts: + - equal: + path: spec.headersFrom + value: + - name: X-Muster-Toolset + value: server:github + - name: X-Muster-Tool-Approval + value: default=Ask + template: templates/remotemcpserver.yaml + - notExists: + path: spec.template.tools[0].mcp.requireApproval + template: templates/agent.yaml + + # schema + - it: refuses a setting that is not Allow, Ask or Block through the values schema + set: + tools: + - server:github: Deny + asserts: + - failedTemplate: + errorPattern: tools + + - it: refuses a lower-case setting through the values schema + set: + tools: + - server:github: ask + asserts: + - failedTemplate: + errorPattern: tools + + - it: refuses default Deny through the values schema + set: + default: Deny + asserts: + - failedTemplate: + errorPattern: default + + - it: refuses an object item with two keys through the values schema + set: + tools: + - server:github: Ask + server:pagerduty: Allow + asserts: + - failedTemplate: + errorPattern: tools + + - it: refuses an object item whose key is not a selector through the values schema + set: + tools: + - github: Ask + asserts: + - failedTemplate: + errorPattern: tools + + - it: refuses an empty tools list through the values schema + set: + tools: [] + asserts: + - failedTemplate: + errorPattern: tools + + - it: renders 32 tools + set: + tools: + - tool:t0 + - tool:t1 + - tool:t2 + - tool:t3 + - tool:t4 + - tool:t5 + - tool:t6 + - tool:t7 + - tool:t8 + - tool:t9 + - tool:t10 + - tool:t11 + - tool:t12 + - tool:t13 + - tool:t14 + - tool:t15 + - tool:t16 + - tool:t17 + - tool:t18 + - tool:t19 + - tool:t20 + - tool:t21 + - tool:t22 + - tool:t23 + - tool:t24 + - tool:t25 + - tool:t26 + - tool:t27 + - tool:t28 + - tool:t29 + - tool:t30 + - tool:t31 + asserts: + - isKind: + of: RemoteMCPServer + template: templates/remotemcpserver.yaml + + - it: refuses 33 tools through the values schema + set: + tools: + - tool:t0 + - tool:t1 + - tool:t2 + - tool:t3 + - tool:t4 + - tool:t5 + - tool:t6 + - tool:t7 + - tool:t8 + - tool:t9 + - tool:t10 + - tool:t11 + - tool:t12 + - tool:t13 + - tool:t14 + - tool:t15 + - tool:t16 + - tool:t17 + - tool:t18 + - tool:t19 + - tool:t20 + - tool:t21 + - tool:t22 + - tool:t23 + - tool:t24 + - tool:t25 + - tool:t26 + - tool:t27 + - tool:t28 + - tool:t29 + - tool:t30 + - tool:t31 + - tool:t32 + asserts: + - failedTemplate: + errorPattern: tools diff --git a/helm/agent/tool.schema.json b/helm/agent/tool.schema.json new file mode 100644 index 0000000..cb805eb --- /dev/null +++ b/helm/agent/tool.schema.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$comment": "One entry of the `tools` value: a selector string, or an object with exactly one key (a selector) whose value is the tool's approval setting. Referenced from values.yaml (`tools: # @schema itemRef:tool.schema.json`) and bundled into values.schema.json by the helm-schema pre-commit hook.", + "oneOf": [ + { + "type": "string", + "pattern": "^(preset|server|workflow|tool):[^\\s,]+$" + }, + { + "type": "object", + "minProperties": 1, + "maxProperties": 1, + "propertyNames": { + "pattern": "^(preset|server|workflow|tool):[^\\s,]+$" + }, + "additionalProperties": { + "type": "string", + "enum": ["Allow", "Ask", "Block"] + } + } + ] +} diff --git a/helm/agent/values.schema.json b/helm/agent/values.schema.json index 94713e3..228d076 100644 --- a/helm/agent/values.schema.json +++ b/helm/agent/values.schema.json @@ -149,11 +149,50 @@ "$comment": "One entry of the `agent.tags` value: a lowercase kebab-case keyword. Referenced from values.yaml (`tags: [] # @schema itemRef:tag.schema.json`) and bundled into values.schema.json by the helm-schema pre-commit hook.", "maxLength": 63, "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$" + }, + "tool.schema.json": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$comment": "One entry of the `tools` value: a selector string, or an object with exactly one key (a selector) whose value is the tool's approval setting. Referenced from values.yaml (`tools: # @schema itemRef:tool.schema.json`) and bundled into values.schema.json by the helm-schema pre-commit hook.", + "oneOf": [ + { + "type": "string", + "pattern": "^(preset|server|workflow|tool):[^\\s,]+$" + }, + { + "type": "object", + "additionalProperties": { + "type": "string", + "enum": [ + "Allow", + "Ask", + "Block" + ] + }, + "maxProperties": 1, + "minProperties": 1, + "propertyNames": { + "pattern": "^(preset|server|workflow|tool):[^\\s,]+$" + } + } + ] } }, "type": "object", "additionalProperties": false, "properties": { + "default": { + "type": [ + "string", + "null" + ], + "description": "The setting of every tool in `tools` without its own: `Allow`, `Ask` or `Block` (case-sensitive). `default: Ask` replaces the removed `muster.requireApproval: true`.", + "enum": [ + "Allow", + "Ask", + "Block", + null + ] + }, "agent": { "type": "object", "description": "Identity and prompt of the agent.", @@ -414,10 +453,6 @@ "type": "boolean", "description": "Wire muster into the agent's tools: render the agent's RemoteMCPServer and bind it in the Agent's template." }, - "requireApproval": { - "type": "boolean", - "description": "Pause the agent before every tool call through muster until a person approves it. Rendered as `requireApproval: true` on the binding (kagent's human-in-the-loop): the Harness stops the task at `input-required` for each call and continues with the person's decision. It applies to the tools the binding exposes — `tools` when set, otherwise every muster tool. A client that negotiates kagent's HITL A2A extension (`https://kagent.dev/extensions/hitl/v1`) receives the structured `tool_approval_request` and answers it; one that does not sees a plain notice that human input is required. Off by default: the agent calls tools without asking." - }, "timeout": { "type": "string", "description": "How long one tool call through muster may run before the agent's runtime cancels it, rendered as given into the RemoteMCPServer's spec.timeout (a duration with a unit: `180s`, `5m`). Without the field kagent applies its own 30 s, which cuts a backend tool that legitimately runs longer — a write that creates a repository and opens a pull request in one call, a watch that blocks for minutes — although muster's own per-server budget for that backend allows more. The default is muster's progress cap (an MCPServer's `progress.maxDuration`, at most an hour): kagent applies the value to the whole request, which no MCP progress notification restarts, so a wait kept alive by progress (devctl's `pr_wait`, `pr_merge`, `release_wait`) returns its verdict in one call; muster still bounds every call by its backend's own `spec.timeout`, restarted by that progress, so a call is bounded by its backend, not by the caller.", @@ -475,12 +510,24 @@ "subscriptionID": { "type": "string" }, + "tools": { + "type": [ + "array", + "null" + ], + "description": "The tools the agent is composed with, 1 to 32 items; replaces `toolset`. An item is a selector (`preset:`, `server:`, `workflow:` or `tool:`, exact and case-sensitive, each once) or a one-key object giving it `Allow`, `Ask` or `Block`, e.g. `- server:github: Ask`. Unlisted tools are invisible. The selectors render as `toolset` does (exactly `[\"preset:none\"]` renders no RemoteMCPServer and takes no setting or other entry); settings and `default` render as the header `X-Muster-Tool-Approval`, which muster applies where no Session binding carries them, and agent-manager binds them per Session. An `Allow` over a connector's `Ask` needs a grant by a connector admin through agent-manager's `set_agent_approval`. `tools` with `toolset` fails the render.", + "items": { + "$ref": "#/$defs/tool.schema.json" + }, + "maxItems": 32, + "minItems": 1 + }, "toolset": { "type": [ "array", "null" ], - "description": "The tools the agent is composed with: a list of selectors that muster resolves per request. Selectors are `preset:`, `server:`, `workflow:` or `tool:` with exact, case-sensitive names (regex `^(preset|server|workflow|tool):[^\\s,]+$`); at most 128 inline and 8192 UTF-8 bytes joined by commas, define a preset for more. `toolset:` is reserved and refused; patterns, excludes, the read-only predicate and `label:` exist only inside presets. Rendered as the static `X-Muster-Toolset` header on the agent's RemoteMCPServer (`spec.headersFrom`, the selectors joined by `,`). Exactly `[\"preset:none\"]` renders NO RemoteMCPServer and no muster binding at all, so a chat-only agent pays no context for meta-tools; an empty list fails the render (say `preset:none` instead). Unset (the default) renders no header and the agent keeps implicit full access to everything the gateway exposes to the invoking human. Built-in presets: `read-only`, `none`, `full`; the platform charts ship `infrastructure` and `agent-platform`. Composition, not authorization: the human's identity and the backends' own authorization stay the boundary.", + "description": "Deprecated, use `tools`. The tools the agent is composed with: a list of selectors that muster resolves per request. Selectors are `preset:`, `server:`, `workflow:` or `tool:` with exact, case-sensitive names (regex `^(preset|server|workflow|tool):[^\\s,]+$`); at most 128 inline and 8192 UTF-8 bytes joined by commas, define a preset for more. `toolset:` is reserved and refused; patterns, excludes, the read-only predicate and `label:` exist only inside presets. Rendered as the static `X-Muster-Toolset` header on the agent's RemoteMCPServer (`spec.headersFrom`, the selectors joined by `,`). Exactly `[\"preset:none\"]` renders NO RemoteMCPServer and no muster binding at all, so a chat-only agent pays no context for meta-tools; an empty list fails the render (say `preset:none` instead). Unset (the default) renders no header and the agent keeps implicit full access to everything the gateway exposes to the invoking human. Built-in presets: `read-only`, `none`, `full`; the platform charts ship `infrastructure` and `agent-platform`. Composition, not authorization: the human's identity and the backends' own authorization stay the boundary.", "items": { "type": "string" }, diff --git a/helm/agent/values.yaml b/helm/agent/values.yaml index a61afe4..b5820d9 100644 --- a/helm/agent/values.yaml +++ b/helm/agent/values.yaml @@ -10,9 +10,9 @@ # are platform-owned and referenced by name. # # values.schema.json is generated from the # @schema annotations in this file -# (and skill.schema.json for the skills entries) by the helm-schema pre-commit -# hook (losisin/helm-values-schema-json); edit the annotations here, never the -# schema directly. +# (and skill.schema.json, tool.schema.json for the skills and tools entries) by +# the helm-schema pre-commit hook (losisin/helm-values-schema-json); edit the +# annotations here, never the schema directly. # -- Identity and prompt of the agent. agent: @@ -278,18 +278,6 @@ muster: # discover the server's tools; with discovery off (the default) it may expose # the whole server and report a warning in the Agent's status.warnings. tools: [] - # @schema type:boolean - # -- Pause the agent before every tool call through muster until a person - # approves it. Rendered as `requireApproval: true` on the binding (kagent's - # human-in-the-loop): the Harness stops the task at `input-required` for - # each call and continues with the person's decision. It applies to the - # tools the binding exposes — `tools` when set, otherwise every muster - # tool. A client that negotiates kagent's HITL A2A extension - # (`https://kagent.dev/extensions/hitl/v1`) receives the structured - # `tool_approval_request` and answers it; one that does not sees a plain - # notice that human input is required. Off by default: the agent calls - # tools without asking. - requireApproval: false # -- Tool discovery by the kagent controller against muster. discovery: # @schema type:boolean @@ -300,13 +288,36 @@ muster: # time as the signed-in person. Turn on only for a muster without OAuth. enabled: false +# @schema type:[array, null];itemRef:tool.schema.json;minItems:1;maxItems:32 +# -- (list) The tools the agent is composed with, 1 to 32 items; replaces +# `toolset`. An item is a selector (`preset:`, `server:`, `workflow:` or +# `tool:`, exact and case-sensitive, each once) or a one-key object +# giving it `Allow`, `Ask` or `Block`, e.g. `- server:github: Ask`. Unlisted +# tools are invisible. The selectors render as `toolset` does (exactly +# `["preset:none"]` renders no RemoteMCPServer and takes no setting or other +# entry); settings and `default` render as the header `X-Muster-Tool-Approval`, +# which muster applies where no Session binding carries them, and +# agent-manager binds them per Session. An `Allow` over a connector's `Ask` +# needs a grant by a connector admin through agent-manager's +# `set_agent_approval`. `tools` with `toolset` fails the render. +# @default -- unset: implicit full access, renders no header +tools: + +# @schema type:[string, null];enum:[Allow, Ask, Block, null] +# -- (string) The setting of every tool in `tools` without its own: `Allow`, +# `Ask` or `Block` (case-sensitive). `default: Ask` replaces the removed +# `muster.requireApproval: true`. +# @default -- unset: no default +default: + # @schema type:[array, null];item:string;maxItems:128 -# -- (list) The tools the agent is composed with: a list of selectors that muster -# resolves per request. Selectors are `preset:`, `server:`, -# `workflow:` or `tool:` with exact, case-sensitive names (regex -# `^(preset|server|workflow|tool):[^\s,]+$`); at most 128 inline and 8192 UTF-8 bytes joined by commas, define a -# preset for more. `toolset:` is reserved and refused; patterns, -# excludes, the read-only predicate and `label:` exist only inside presets. +# -- (list) Deprecated, use `tools`. The tools the agent is composed with: a +# list of selectors that muster resolves per request. Selectors are +# `preset:`, `server:`, `workflow:` or `tool:` with +# exact, case-sensitive names (regex `^(preset|server|workflow|tool):[^\s,]+$`); +# at most 128 inline and 8192 UTF-8 bytes joined by commas, define a preset for +# more. `toolset:` is reserved and refused; patterns, excludes, the +# read-only predicate and `label:` exist only inside presets. # Rendered as the static `X-Muster-Toolset` header on the agent's # RemoteMCPServer (`spec.headersFrom`, the selectors joined by `,`). Exactly # `["preset:none"]` renders NO RemoteMCPServer and no muster binding at all, so