From 4ca0140d775478d0d6a10788691d822d9d760cd7 Mon Sep 17 00:00:00 2001 From: Marian Steinbach Date: Fri, 23 Oct 2026 11:27:31 +0200 Subject: [PATCH 1/2] feat: agent.platformPrompt.egressNote renders the network access note after the prompt --- CHANGELOG.md | 2 + README.md | 8 ++- helm/agent/README.md | 6 +- helm/agent/templates/_helpers.tpl | 34 ++++++++- helm/agent/tests/agent_test.yaml | 113 ++++++++++++++++++++++++++++++ helm/agent/values.schema.json | 13 +++- helm/agent/values.yaml | 22 +++++- 7 files changed, 190 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca439f2..b5945eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- `agent.platformPrompt.egressNote` (`false` by default): appends the network access note, a `## Network access (set by the platform)` section naming the origins of `agent.egress` and the toolchain registries, to the Agent's `spec.template.systemPrompt`, after `agent.systemMessage`. agent-manager sets it on every agent on a coding Harness instead of writing the note into `agent.systemMessage`, so the person's prompt stays their own and a chart release updates the wording on every agent. A note found inside `agent.systemMessage` (its heading and the paragraph after it) is dropped from the render, with or without the flag, so a release whose values still carry one renders the chart's note once (giantswarm/giantswarm#38803). + - `agent.egressPolicyRefs` (empty by default): names of EgressPolicies in the agent's namespace, rendered into the Agent's `spec.egressPolicyRefs` as `{name}` entries beside `spec.egress`. The chart copies none of a policy's rules. At most 16 unique resource names; the schema refuses anything else, naming the entry. Needs a kagent line that serves `egresspolicies.api.kagent.dev` (giantswarm/kagent-upstream#620). - `agent.egress` accepts `tls://:` entries: TLS that the egress gateway forwards without decrypting it, matched on the SNI server name, for a database or message broker that speaks TLS from its first byte. Same host rules as an HTTP(S) origin, and a port is required. The schema and the render refuse an entry without a port, with a path or on an IP address, naming it. Needs the kagent line from 1.21.0, whose Agent accepts `tls://` in `spec.egress` (giantswarm/kagent-upstream#740); an older kagent refuses the Agent (giantswarm/agent#58). diff --git a/README.md b/README.md index 76dcb44..eb2b7c3 100644 --- a/README.md +++ b/README.md @@ -259,7 +259,13 @@ agent: agent's own spec, not a separate approval. - An agent on a coding Harness (a runtime other than `kagent`) gets its origins from the platform's per-Harness list, which agent-manager writes into - `agent.egress`; another origin is refused there. + `agent.egress`; another origin is refused there. agent-manager also sets + `agent.platformPrompt.egressNote`, and the chart appends a `## Network + access (set by the platform)` section to the system prompt that names those + origins and tells the agent that a refusal is policy, not an outage. The + section is the chart's, not part of `agent.systemMessage`: a chart release + updates its wording on every agent, and a note found inside `systemMessage` + is dropped so the prompt never carries two. **Picking an EgressPolicy.** A tenant's admins can bundle origins, and the credential header the gateway adds to them, into an `EgressPolicy` in the diff --git a/helm/agent/README.md b/helm/agent/README.md index 5c1e0ea..2d168bb 100644 --- a/helm/agent/README.md +++ b/helm/agent/README.md @@ -14,15 +14,17 @@ What an agent can reach and how to add a host (`agent.egress`): [What an agent c | Key | Type | Default | Description | |-----|------|---------|-------------| -| agent | object | `{"description":"","displayName":"","egress":[],"egressPolicyRefs":[],"harness":"kagent","iconUrl":"","name":"","systemMessage":"You are a helpful agent.\n"}` | Identity and prompt of the agent. | +| agent | object | `{"description":"","displayName":"","egress":[],"egressPolicyRefs":[],"harness":"kagent","iconUrl":"","name":"","platformPrompt":{"egressNote":false},"systemMessage":"You are a helpful agent.\n"}` | Identity and prompt of the agent. | | agent.name | string | `""` | Technical resource name (DNS-1123) of the Agent and of its RemoteMCPServer. Defaults to the Helm release name. | | agent.displayName | string | `""` | Human-friendly name, Unicode allowed. Rendered as the ui.giantswarm.io/display-name annotation on the Agent. Size-limited so it cannot become a description. | | agent.description | string | `""` | Rendered into the Agent's spec.template.description. It shares the compiled agent config's size budget with the system prompt (see systemMessage), so keep it to a few sentences. | | agent.iconUrl | string | `""` | Fully qualified URL of the agent's avatar icon. Rendered as the ui.giantswarm.io/icon-url annotation on the Agent (the template has no icon field); the Dev Portal reads it. Populated by the agent-creation flows with the canonical avatar URL. | -| agent.systemMessage | string | `"You are a helpful agent.\n"` | The agent's system prompt. Rendered into the Agent's spec.template.systemPrompt. At most 20000 characters; move long reference material into a skill. A prompt heavy in `<`, `>` or `&` can still exceed the runtime limit under this cap, and the Agent then reports why. | +| agent.systemMessage | string | `"You are a helpful agent.\n"` | The agent's system prompt. Rendered into the Agent's spec.template.systemPrompt, followed by the sections of `platformPrompt`. At most 20000 characters; move long reference material into a skill. A prompt heavy in `<`, `>` or `&` can still exceed the runtime limit under this cap, and the Agent then reports why. A `## Network access (set by the platform)` heading and the paragraph after it are the platform's and are dropped from it: `platformPrompt.egressNote` renders that section. | | agent.harness | string | `"kagent"` | Name of the platform Harness that runs the agent, in the agent's namespace. Rendered into the Agent's spec.harnessRef.name; the Agent selects its Harness, no label and no Harness-side selector is involved. The platform ships the `kagent` Harness (the Go ADK runtime); an Agent whose Harness does not exist reports `ResolvedRefs=False` and never becomes Ready. | | agent.egress | list | `[]` | Origins the agent may reach besides the destinations its revision compiles (the model, its MCP servers, its skill and plugin sources, telemetry), such as `https://github.com:443`, `https://proxy.golang.org` or `tls://db.example.com:5432`. Rendered into the Agent's spec.egress. An origin is `http(s)://[:port]` with no path, or `tls://:` with a required port: TLS that the egress gateway forwards without decrypting it, matched on the SNI server name (a database or message broker that speaks TLS from the first byte, not STARTTLS). The host may have `*` as its leftmost label (`https://*.githubusercontent.com` matches one label, such as raw.githubusercontent.com) and a wildcard needs two labels under it, so nothing opens a whole top-level domain or every host. At most 64 origins. The chart refuses anything else, naming the entry. | | agent.egressPolicyRefs | list | `[]` | Names of EgressPolicies in the agent's namespace whose origins (and credential headers) the agent may also reach, such as `github` or `go-modules`. Rendered into the Agent's spec.egressPolicyRefs as `{name}` entries; the chart copies none of a policy's rules, so a change to the policy reaches the agent from its next Session without an upgrade of this release. At most 16 unique names. A name with no EgressPolicy in the namespace keeps the Agent from becoming Ready (ResolvedRefs=False). | +| agent.platformPrompt | object | `{"egressNote":false}` | Sections the platform appends to the system prompt, after `systemMessage`. The platform (agent-manager) sets them, not the agent's author: the chart owns their wording, so a chart release updates them on every agent, and an edit of `systemMessage` neither shows nor removes them. | +| agent.platformPrompt.egressNote | bool | `false` | Append the network access note: a `## Network access (set by the platform)` section that names the origins of `egress` and the registries of the toolchains mounted under /opt/kagent/tools, and tells the agent that a request to any other host is refused by policy, not an outage to retry. agent-manager sets it on every agent on a coding Harness (any runtime but kagent's). | | modelConfig | object | `{"name":"default-model-config"}` | Which platform-provisioned ModelConfig the agent uses, referenced by name. kagent resolves it in the agent's own namespace. The chart never creates or mutates a ModelConfig, and tenants never handle LLM credentials. | | modelConfig.name | string | `"default-model-config"` | Name of the platform-provisioned ModelConfig in the agent's namespace. Rendered into the Agent's spec.template.modelConfig.name. | | context | object | `{"compaction":{"compactionInterval":null,"enabled":true,"eventRetentionSize":4,"overlapSize":null,"summarizer":{"modelConfig":"","promptTemplate":""},"tokenThreshold":24000}}` | Kept for the values of existing releases; rendered into nothing. Context compaction moved from the agent's template to the platform Harness (kagent-dev/kagent#2790; Harness.spec.kagent.compaction, set by the platform as kagent.harness.compaction), where it applies to every agent the Harness admits. The kagent line from 1.1.0 has no spec.context on the AgentTemplate, and a template that carries it is refused at admission. Everything under this key is ignored. | diff --git a/helm/agent/templates/_helpers.tpl b/helm/agent/templates/_helpers.tpl index 519951f..1cd667b 100644 --- a/helm/agent/templates/_helpers.tpl +++ b/helm/agent/templates/_helpers.tpl @@ -171,6 +171,38 @@ Description of the agent's RemoteMCPServer: names the agent and its toolset. {{- printf "muster MCP gateway of agent %s (%s)" (include "agent.name" .) (ternary (printf "toolset %s" $toolset) "implicit full access" (ne $toolset "")) -}} {{- end -}} +{{- /* +agent.systemPrompt is systemMessage followed by the sections of +agent.platformPrompt. A network access note inside systemMessage (the heading +and the paragraph after it) is dropped, so the prompt carries the note at most +once and always in the chart's wording. +*/ -}} +{{- define "agent.systemPrompt" -}} +{{- $prompt := .Values.agent.systemMessage -}} +{{- $own := regexReplaceAll `\s*## Network access \(set by the platform\)\n\n[^\n]*` $prompt "" -}} +{{- if ne $own $prompt -}} +{{- $prompt = trim $own -}} +{{- end -}} +{{- if .Values.agent.platformPrompt.egressNote -}} +{{- $prompt = regexReplaceAll `\s+$` $prompt "" -}} +{{- $note := include "agent.egressNote" . -}} +{{- $prompt = ternary $note (printf "%s\n\n%s" $prompt $note) (eq $prompt "") -}} +{{- end -}} +{{- $prompt -}} +{{- end -}} + +{{- /* +agent.egressNote tells a coding agent what its sandbox reaches, so a refused +request reads as policy rather than as an outage. A Session's toolchains bring +origins of their own, which differ per Session, so the note names them by +place. +*/ -}} +{{- define "agent.egressNote" -}} +## Network access (set by the platform) + +Besides your model and your tools, your sandbox reaches only {{ with .Values.agent.egress }}these origins: {{ join ", " . }}, and {{ end }}the registries of the toolchains mounted under /opt/kagent/tools. A request to any other host is refused by the egress policy and shows up as a failed command or tool call (connection refused, reset or 403). It is not transient: do not retry it or work around it; say which host the task needs. +{{- end -}} + {{- /* agent.egress.validate mirrors the Agent CRD's rule for spec.egress (HTTP(S) origins and tls:// origins with a port) so a bad origin fails the render naming @@ -287,7 +319,7 @@ description: {{ . | quote }} modelConfig: name: {{ .Values.modelConfig.name | quote }} systemPrompt: |- - {{- .Values.agent.systemMessage | nindent 2 }} + {{- include "agent.systemPrompt" . | nindent 2 }} {{- with .Values.skills }} skills: {{- include "agent.skills" $ | nindent 2 }} diff --git a/helm/agent/tests/agent_test.yaml b/helm/agent/tests/agent_test.yaml index 84baccb..7c8bcdb 100644 --- a/helm/agent/tests/agent_test.yaml +++ b/helm/agent/tests/agent_test.yaml @@ -102,6 +102,119 @@ tests: You are an SRE assistant. Be concise. + # platform prompt + - it: appends the network access note naming agent.egress + set: + agent: + systemMessage: | + You keep the GitOps repositories tidy. + egress: + - https://github.com + - https://*.githubusercontent.com + platformPrompt: + egressNote: true + asserts: + - equal: + path: spec.template.systemPrompt + value: |- + You keep the GitOps repositories tidy. + + ## Network access (set by the platform) + + Besides your model and your tools, your sandbox reaches only these origins: https://github.com, https://*.githubusercontent.com, and the registries of the toolchains mounted under /opt/kagent/tools. A request to any other host is refused by the egress policy and shows up as a failed command or tool call (connection refused, reset or 403). It is not transient: do not retry it or work around it; say which host the task needs. + + - it: names only the toolchain registries in the network access note without agent.egress + set: + agent: + platformPrompt: + egressNote: true + asserts: + - equal: + path: spec.template.systemPrompt + value: |- + You are a helpful agent. + + ## Network access (set by the platform) + + Besides your model and your tools, your sandbox reaches only the registries of the toolchains mounted under /opt/kagent/tools. A request to any other host is refused by the egress policy and shows up as a failed command or tool call (connection refused, reset or 403). It is not transient: do not retry it or work around it; say which host the task needs. + + - it: replaces a network access note in systemMessage with the chart's + set: + agent: + systemMessage: |- + You keep the GitOps repositories tidy. + + ## Network access (set by the platform) + + Besides your model and your tools, your sandbox reaches only these origins: https://example.com, and an outdated wording. + egress: + - https://github.com + platformPrompt: + egressNote: true + asserts: + - equal: + path: spec.template.systemPrompt + value: |- + You keep the GitOps repositories tidy. + + ## Network access (set by the platform) + + Besides your model and your tools, your sandbox reaches only these origins: https://github.com, and the registries of the toolchains mounted under /opt/kagent/tools. A request to any other host is refused by the egress policy and shows up as a failed command or tool call (connection refused, reset or 403). It is not transient: do not retry it or work around it; say which host the task needs. + + - it: drops a network access note from systemMessage and keeps the text around it + set: + agent: + systemMessage: |- + You keep the GitOps repositories tidy. + + ## Network access (set by the platform) + + Besides your model and your tools, your sandbox reaches only the registries of the toolchains mounted under /opt/kagent/tools. + + Open one pull request per repository. + asserts: + - equal: + path: spec.template.systemPrompt + value: |- + You keep the GitOps repositories tidy. + + Open one pull request per repository. + + - it: renders only the network access note when systemMessage held nothing but one + set: + agent: + systemMessage: |- + ## Network access (set by the platform) + + Besides your model and your tools, your sandbox reaches only the registries of the toolchains mounted under /opt/kagent/tools. + platformPrompt: + egressNote: true + asserts: + - equal: + path: spec.template.systemPrompt + value: |- + ## Network access (set by the platform) + + Besides your model and your tools, your sandbox reaches only the registries of the toolchains mounted under /opt/kagent/tools. A request to any other host is refused by the egress policy and shows up as a failed command or tool call (connection refused, reset or 403). It is not transient: do not retry it or work around it; say which host the task needs. + + - it: refuses a platformPrompt.egressNote that is not a boolean through the values schema + set: + agent: + platformPrompt: + egressNote: "yes" + asserts: + - failedTemplate: + errorPattern: 'agent[./]platformPrompt[./]egressNote' + + - it: refuses an unknown platformPrompt section through the values schema + set: + agent: + platformPrompt: + mood: cheerful + asserts: + - failedTemplate: + errorPattern: 'agent[./]platformPrompt' + - it: references the ModelConfig by name set: modelConfig: diff --git a/helm/agent/values.schema.json b/helm/agent/values.schema.json index 7b16c46..02a8ae9 100644 --- a/helm/agent/values.schema.json +++ b/helm/agent/values.schema.json @@ -198,9 +198,20 @@ "maxLength": 63, "pattern": "^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?$" }, + "platformPrompt": { + "type": "object", + "description": "Sections the platform appends to the system prompt, after `systemMessage`. The platform (agent-manager) sets them, not the agent's author: the chart owns their wording, so a chart release updates them on every agent, and an edit of `systemMessage` neither shows nor removes them.", + "additionalProperties": false, + "properties": { + "egressNote": { + "type": "boolean", + "description": "Append the network access note: a `## Network access (set by the platform)` section that names the origins of `egress` and the registries of the toolchains mounted under /opt/kagent/tools, and tells the agent that a request to any other host is refused by policy, not an outage to retry. agent-manager sets it on every agent on a coding Harness (any runtime but kagent's)." + } + } + }, "systemMessage": { "type": "string", - "description": "The agent's system prompt. Rendered into the Agent's spec.template.systemPrompt. At most 20000 characters; move long reference material into a skill. A prompt heavy in `<`, `>` or `&` can still exceed the runtime limit under this cap, and the Agent then reports why.", + "description": "The agent's system prompt. Rendered into the Agent's spec.template.systemPrompt, followed by the sections of `platformPrompt`. At most 20000 characters; move long reference material into a skill. A prompt heavy in `<`, `>` or `&` can still exceed the runtime limit under this cap, and the Agent then reports why. A `## Network access (set by the platform)` heading and the paragraph after it are the platform's and are dropped from it: `platformPrompt.egressNote` renders that section.", "maxLength": 20000, "minLength": 1 } diff --git a/helm/agent/values.yaml b/helm/agent/values.yaml index db48b19..d322025 100644 --- a/helm/agent/values.yaml +++ b/helm/agent/values.yaml @@ -40,9 +40,12 @@ agent: # JSON escaping of the prompt and the rest of the compiled agent config. # @schema type:string;minLength:1;maxLength:20000 # -- The agent's system prompt. Rendered into the Agent's - # spec.template.systemPrompt. At most 20000 characters; move long reference - # material into a skill. A prompt heavy in `<`, `>` or `&` can still exceed - # the runtime limit under this cap, and the Agent then reports why. + # spec.template.systemPrompt, followed by the sections of `platformPrompt`. + # At most 20000 characters; move long reference material into a skill. A + # prompt heavy in `<`, `>` or `&` can still exceed the runtime limit under + # this cap, and the Agent then reports why. A `## Network access (set by the + # platform)` heading and the paragraph after it are the platform's and are + # dropped from it: `platformPrompt.egressNote` renders that section. systemMessage: | You are a helpful agent. # @schema type:string;minLength:1;maxLength:63;pattern:^[a-z0-9]([-a-z0-9]*[a-z0-9])?$ @@ -77,6 +80,19 @@ agent: # of this release. At most 16 unique names. A name with no EgressPolicy in # the namespace keeps the Agent from becoming Ready (ResolvedRefs=False). egressPolicyRefs: [] + # -- Sections the platform appends to the system prompt, after + # `systemMessage`. The platform (agent-manager) sets them, not the agent's + # author: the chart owns their wording, so a chart release updates them on + # every agent, and an edit of `systemMessage` neither shows nor removes them. + platformPrompt: + # @schema type:boolean + # -- Append the network access note: a `## Network access (set by the + # platform)` section that names the origins of `egress` and the registries + # of the toolchains mounted under /opt/kagent/tools, and tells the agent + # that a request to any other host is refused by policy, not an outage to + # retry. agent-manager sets it on every agent on a coding Harness (any + # runtime but kagent's). + egressNote: false # -- Which platform-provisioned ModelConfig the agent uses, referenced by name. # kagent resolves it in the agent's own namespace. The chart never creates or From 40d901931f7d1278a1783ba10172969b1ab19b3b Mon Sep 17 00:00:00 2001 From: Marian Steinbach Date: Fri, 23 Oct 2026 11:50:50 +0200 Subject: [PATCH 2/2] fix: replace a note in systemMessage with the chart's, match it by line, render the prompt as a string --- CHANGELOG.md | 4 +- README.md | 7 ++- helm/agent/README.md | 2 +- helm/agent/templates/_helpers.tpl | 22 ++++----- helm/agent/tests/agent_test.yaml | 75 +++++++++++++++++++++++++++++-- helm/agent/values.schema.json | 2 +- helm/agent/values.yaml | 11 ++--- 7 files changed, 100 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5945eb..c7a725a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- `agent.platformPrompt.egressNote` (`false` by default): appends the network access note, a `## Network access (set by the platform)` section naming the origins of `agent.egress` and the toolchain registries, to the Agent's `spec.template.systemPrompt`, after `agent.systemMessage`. agent-manager sets it on every agent on a coding Harness instead of writing the note into `agent.systemMessage`, so the person's prompt stays their own and a chart release updates the wording on every agent. A note found inside `agent.systemMessage` (its heading and the paragraph after it) is dropped from the render, with or without the flag, so a release whose values still carry one renders the chart's note once (giantswarm/giantswarm#38803). +- `agent.platformPrompt.egressNote` (`false` by default): appends the network access note, a `## Network access (set by the platform)` section naming the origins of `agent.egress` and the toolchain registries, to the Agent's `spec.template.systemPrompt`, after `agent.systemMessage`. agent-manager sets it on every agent on a coding Harness instead of writing the note into `agent.systemMessage`, so the person's prompt stays their own and a chart release updates the wording on every agent. A note found inside `agent.systemMessage` (a line that is its heading, and the paragraph after it up to the next blank line, in any line endings) is replaced by the chart's note at the end of the prompt, with or without the flag: an agent whose values carry the note agent-manager wrote before keeps exactly one note, in the chart's wording, when its release moves to this chart version (giantswarm/giantswarm#38803). + +- `spec.template.systemPrompt` is rendered as a quoted string instead of a `|-` block, so a prompt whose first line is indented renders instead of failing; trailing line breaks are still dropped. - `agent.egressPolicyRefs` (empty by default): names of EgressPolicies in the agent's namespace, rendered into the Agent's `spec.egressPolicyRefs` as `{name}` entries beside `spec.egress`. The chart copies none of a policy's rules. At most 16 unique resource names; the schema refuses anything else, naming the entry. Needs a kagent line that serves `egresspolicies.api.kagent.dev` (giantswarm/kagent-upstream#620). diff --git a/README.md b/README.md index eb2b7c3..d5bbd89 100644 --- a/README.md +++ b/README.md @@ -264,8 +264,11 @@ agent: access (set by the platform)` section to the system prompt that names those origins and tells the agent that a refusal is policy, not an outage. The section is the chart's, not part of `agent.systemMessage`: a chart release - updates its wording on every agent, and a note found inside `systemMessage` - is dropped so the prompt never carries two. + updates its wording on every agent. A note found inside `systemMessage` (a + line that is the heading, and the paragraph after it) is replaced by the + chart's, with or without the flag, so values that still carry one render the + current note once. `extraAgentSpec.systemPrompt` replaces the whole prompt, + the note included. **Picking an EgressPolicy.** A tenant's admins can bundle origins, and the credential header the gateway adds to them, into an `EgressPolicy` in the diff --git a/helm/agent/README.md b/helm/agent/README.md index 2d168bb..9aca46f 100644 --- a/helm/agent/README.md +++ b/helm/agent/README.md @@ -19,7 +19,7 @@ What an agent can reach and how to add a host (`agent.egress`): [What an agent c | agent.displayName | string | `""` | Human-friendly name, Unicode allowed. Rendered as the ui.giantswarm.io/display-name annotation on the Agent. Size-limited so it cannot become a description. | | agent.description | string | `""` | Rendered into the Agent's spec.template.description. It shares the compiled agent config's size budget with the system prompt (see systemMessage), so keep it to a few sentences. | | agent.iconUrl | string | `""` | Fully qualified URL of the agent's avatar icon. Rendered as the ui.giantswarm.io/icon-url annotation on the Agent (the template has no icon field); the Dev Portal reads it. Populated by the agent-creation flows with the canonical avatar URL. | -| agent.systemMessage | string | `"You are a helpful agent.\n"` | The agent's system prompt. Rendered into the Agent's spec.template.systemPrompt, followed by the sections of `platformPrompt`. At most 20000 characters; move long reference material into a skill. A prompt heavy in `<`, `>` or `&` can still exceed the runtime limit under this cap, and the Agent then reports why. A `## Network access (set by the platform)` heading and the paragraph after it are the platform's and are dropped from it: `platformPrompt.egressNote` renders that section. | +| agent.systemMessage | string | `"You are a helpful agent.\n"` | The agent's system prompt. Rendered into the Agent's spec.template.systemPrompt, followed by the sections of `platformPrompt`. At most 20000 characters, the platform's sections not counted; move long reference material into a skill. A prompt heavy in `<`, `>` or `&` can still exceed the runtime limit under this cap, and the Agent then reports why. A line `## Network access (set by the platform)` and the paragraph after it are the platform's: the chart takes them out and appends its own network access note instead, as `platformPrompt.egressNote` does. | | agent.harness | string | `"kagent"` | Name of the platform Harness that runs the agent, in the agent's namespace. Rendered into the Agent's spec.harnessRef.name; the Agent selects its Harness, no label and no Harness-side selector is involved. The platform ships the `kagent` Harness (the Go ADK runtime); an Agent whose Harness does not exist reports `ResolvedRefs=False` and never becomes Ready. | | agent.egress | list | `[]` | Origins the agent may reach besides the destinations its revision compiles (the model, its MCP servers, its skill and plugin sources, telemetry), such as `https://github.com:443`, `https://proxy.golang.org` or `tls://db.example.com:5432`. Rendered into the Agent's spec.egress. An origin is `http(s)://[:port]` with no path, or `tls://:` with a required port: TLS that the egress gateway forwards without decrypting it, matched on the SNI server name (a database or message broker that speaks TLS from the first byte, not STARTTLS). The host may have `*` as its leftmost label (`https://*.githubusercontent.com` matches one label, such as raw.githubusercontent.com) and a wildcard needs two labels under it, so nothing opens a whole top-level domain or every host. At most 64 origins. The chart refuses anything else, naming the entry. | | agent.egressPolicyRefs | list | `[]` | Names of EgressPolicies in the agent's namespace whose origins (and credential headers) the agent may also reach, such as `github` or `go-modules`. Rendered into the Agent's spec.egressPolicyRefs as `{name}` entries; the chart copies none of a policy's rules, so a change to the policy reaches the agent from its next Session without an upgrade of this release. At most 16 unique names. A name with no EgressPolicy in the namespace keeps the Agent from becoming Ready (ResolvedRefs=False). | diff --git a/helm/agent/templates/_helpers.tpl b/helm/agent/templates/_helpers.tpl index 1cd667b..fbc360a 100644 --- a/helm/agent/templates/_helpers.tpl +++ b/helm/agent/templates/_helpers.tpl @@ -173,22 +173,25 @@ Description of the agent's RemoteMCPServer: names the agent and its toolset. {{- /* agent.systemPrompt is systemMessage followed by the sections of -agent.platformPrompt. A network access note inside systemMessage (the heading -and the paragraph after it) is dropped, so the prompt carries the note at most -once and always in the chart's wording. +agent.platformPrompt. A network access note inside systemMessage (a line that +is the note's heading, and the paragraph after it up to the next blank line) +is replaced by the chart's: the prompt carries the note once, in the chart's +wording, whether or not agent.platformPrompt.egressNote is set. */ -}} {{- define "agent.systemPrompt" -}} {{- $prompt := .Values.agent.systemMessage -}} -{{- $own := regexReplaceAll `\s*## Network access \(set by the platform\)\n\n[^\n]*` $prompt "" -}} +{{- $egressNote := dig "platformPrompt" "egressNote" false .Values.agent -}} +{{- $own := regexReplaceAll `(?m)\s*^[ \t]*## Network access \(set by the platform\)[ \t]*\r?$(?:\n[ \t]*\r?$)*(?:\n[^\r\n]*\S[^\r\n]*\r?$)*` $prompt "" -}} {{- if ne $own $prompt -}} -{{- $prompt = trim $own -}} +{{- $prompt = regexReplaceAll `\A(?:[ \t]*\r?\n)+` $own "" -}} +{{- $egressNote = true -}} {{- end -}} -{{- if .Values.agent.platformPrompt.egressNote -}} -{{- $prompt = regexReplaceAll `\s+$` $prompt "" -}} +{{- if $egressNote -}} +{{- $prompt = regexReplaceAll `\s+\z` $prompt "" -}} {{- $note := include "agent.egressNote" . -}} {{- $prompt = ternary $note (printf "%s\n\n%s" $prompt $note) (eq $prompt "") -}} {{- end -}} -{{- $prompt -}} +{{- regexReplaceAll `\n+\z` $prompt "" -}} {{- end -}} {{- /* @@ -318,8 +321,7 @@ description: {{ . | quote }} {{- end }} modelConfig: name: {{ .Values.modelConfig.name | quote }} -systemPrompt: |- - {{- include "agent.systemPrompt" . | nindent 2 }} +systemPrompt: {{ include "agent.systemPrompt" . | toJson }} {{- with .Values.skills }} skills: {{- include "agent.skills" $ | nindent 2 }} diff --git a/helm/agent/tests/agent_test.yaml b/helm/agent/tests/agent_test.yaml index 7c8bcdb..13890da 100644 --- a/helm/agent/tests/agent_test.yaml +++ b/helm/agent/tests/agent_test.yaml @@ -161,7 +161,9 @@ tests: Besides your model and your tools, your sandbox reaches only these origins: https://github.com, and the registries of the toolchains mounted under /opt/kagent/tools. A request to any other host is refused by the egress policy and shows up as a failed command or tool call (connection refused, reset or 403). It is not transient: do not retry it or work around it; say which host the task needs. - - it: drops a network access note from systemMessage and keeps the text around it + # Values written before platformPrompt carry the note in systemMessage and + # no flag: they render the chart's note, never none and never two. + - it: replaces a network access note in systemMessage without the flag and keeps the text around it set: agent: systemMessage: |- @@ -180,6 +182,75 @@ tests: Open one pull request per repository. + ## Network access (set by the platform) + + Besides your model and your tools, your sandbox reaches only the registries of the toolchains mounted under /opt/kagent/tools. A request to any other host is refused by the egress policy and shows up as a failed command or tool call (connection refused, reset or 403). It is not transient: do not retry it or work around it; say which host the task needs. + + - it: replaces a network access note with CRLF line endings + set: + agent: + systemMessage: "You keep the GitOps repositories tidy.\r\n\r\n## Network access (set by the platform)\r\n\r\nBesides your model and your tools, your sandbox reaches only https://example.com.\r\n" + asserts: + - matchRegex: + path: spec.template.systemPrompt + pattern: '\AYou keep the GitOps repositories tidy\.\n\n## Network access \(set by the platform\)\n\nBesides your model and your tools, your sandbox reaches only the registries of the toolchains' + + - it: replaces a network access note whose paragraph follows the heading directly and wraps over lines + set: + agent: + systemMessage: |- + You keep the GitOps repositories tidy. + + ## Network access (set by the platform) + Besides your model and your tools, your sandbox reaches only + these origins: https://example.com. + + Open one pull request per repository. + asserts: + - equal: + path: spec.template.systemPrompt + value: |- + You keep the GitOps repositories tidy. + + Open one pull request per repository. + + ## Network access (set by the platform) + + Besides your model and your tools, your sandbox reaches only the registries of the toolchains mounted under /opt/kagent/tools. A request to any other host is refused by the egress policy and shows up as a failed command or tool call (connection refused, reset or 403). It is not transient: do not retry it or work around it; say which host the task needs. + + - it: keeps the heading's text when it is not a line of its own + set: + agent: + systemMessage: |- + Never write a section titled ## Network access (set by the platform) + + yourself; the platform owns it. + asserts: + - equal: + path: spec.template.systemPrompt + value: |- + Never write a section titled ## Network access (set by the platform) + + yourself; the platform owns it. + + - it: keeps the indentation a prompt starts with when it replaces a note + set: + agent: + systemMessage: " make test\nRun this first.\n\n## Network access (set by the platform)\n\nBesides your model and your tools, your sandbox reaches only https://example.com." + asserts: + - matchRegex: + path: spec.template.systemPrompt + pattern: '\A make test\nRun this first\.\n\n## Network access \(set by the platform\)\n\n' + + - it: renders no network access note with platformPrompt set to null + set: + agent: + platformPrompt: null + asserts: + - equal: + path: spec.template.systemPrompt + value: You are a helpful agent. + - it: renders only the network access note when systemMessage held nothing but one set: agent: @@ -187,8 +258,6 @@ tests: ## Network access (set by the platform) Besides your model and your tools, your sandbox reaches only the registries of the toolchains mounted under /opt/kagent/tools. - platformPrompt: - egressNote: true asserts: - equal: path: spec.template.systemPrompt diff --git a/helm/agent/values.schema.json b/helm/agent/values.schema.json index 02a8ae9..c632927 100644 --- a/helm/agent/values.schema.json +++ b/helm/agent/values.schema.json @@ -211,7 +211,7 @@ }, "systemMessage": { "type": "string", - "description": "The agent's system prompt. Rendered into the Agent's spec.template.systemPrompt, followed by the sections of `platformPrompt`. At most 20000 characters; move long reference material into a skill. A prompt heavy in `<`, `>` or `&` can still exceed the runtime limit under this cap, and the Agent then reports why. A `## Network access (set by the platform)` heading and the paragraph after it are the platform's and are dropped from it: `platformPrompt.egressNote` renders that section.", + "description": "The agent's system prompt. Rendered into the Agent's spec.template.systemPrompt, followed by the sections of `platformPrompt`. At most 20000 characters, the platform's sections not counted; move long reference material into a skill. A prompt heavy in `<`, `>` or `&` can still exceed the runtime limit under this cap, and the Agent then reports why. A line `## Network access (set by the platform)` and the paragraph after it are the platform's: the chart takes them out and appends its own network access note instead, as `platformPrompt.egressNote` does.", "maxLength": 20000, "minLength": 1 } diff --git a/helm/agent/values.yaml b/helm/agent/values.yaml index d322025..533391c 100644 --- a/helm/agent/values.yaml +++ b/helm/agent/values.yaml @@ -41,11 +41,12 @@ agent: # @schema type:string;minLength:1;maxLength:20000 # -- The agent's system prompt. Rendered into the Agent's # spec.template.systemPrompt, followed by the sections of `platformPrompt`. - # At most 20000 characters; move long reference material into a skill. A - # prompt heavy in `<`, `>` or `&` can still exceed the runtime limit under - # this cap, and the Agent then reports why. A `## Network access (set by the - # platform)` heading and the paragraph after it are the platform's and are - # dropped from it: `platformPrompt.egressNote` renders that section. + # At most 20000 characters, the platform's sections not counted; move long + # reference material into a skill. A prompt heavy in `<`, `>` or `&` can + # still exceed the runtime limit under this cap, and the Agent then reports + # why. A line `## Network access (set by the platform)` and the paragraph + # after it are the platform's: the chart takes them out and appends its own + # network access note instead, as `platformPrompt.egressNote` does. systemMessage: | You are a helpful agent. # @schema type:string;minLength:1;maxLength:63;pattern:^[a-z0-9]([-a-z0-9]*[a-z0-9])?$