Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ with Dex doing the logins.
every part of `organizations-test` stop at once on a CRD, an operator or
an agent-manager of the earlier shape (organizationkind.go). There
agent-manager's tools take an organization by its name (`organization`),
never its namespace: the lab passes `namespace` only for `kagent`. The Slack surface
never its namespace: the lab passes `namespace` only for `kagent`, except
`turn`, which passes the namespace of the Agent it starts (agent-manager
takes `public-agents` too and refuses an organization's namespace, so
`turn` cannot start an organization's agent; docs/cli.md). The Slack surface
of `organizations-test` needs klaus-gateway 4.18.10 or later, the first
release with giantswarm/klaus-gateway#616, which starts a thread's Session
by the organization's name (the lab takes the component's applied version,
Expand Down
6 changes: 4 additions & 2 deletions docs/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,10 @@ agent-manager finds an organization's namespace itself, in the
they act on the installation's own models, for a cluster admin.
- The agent and session tools take `organization` for an organization's
agents, `organization` with `cluster` for an agent on a workload cluster,
and `namespace` only for the installation's own platform namespace
(`kagent`). An organization's namespace as `namespace` is refused as
and `namespace` only for the installation's own platform namespaces
(`kagent`, and `public-agents` where the chart has it; `agentlab turn`
passes the namespace of the Agent it starts, so it cannot start an
organization's agent). An organization's namespace as `namespace` is refused as
`invalid_request`, naming the organization to pass to a caller with a
right in it; `organization` with `namespace` and no `cluster` is refused
as `invalid_request`.
Expand Down
2 changes: 1 addition & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ The sections below are the groups `agentlab --help` prints, in the same order.
| `logs <component>` | Tail a component's logs: `backstage`, `dex`, `klaus-gateway`, `mcp-prometheus`, `muster` or `prometheus`. |
| `portal dev` / `portal build` | Run your own giantswarm/backstage checkout against the lab (`--checkout`, default `../backstage`, resolved against the directory you run the command from). `dev` runs the checkout's `yarn start` with hot reload — frontend `http://localhost:3000`, backend on `backstage.localDevPort` (`--port`, default 7017), signed in through the lab Dex, talking to the lab's muster, kagent and apiserver. `build` builds the image the way the checkout's CI does, records it as `platform.devImages.backstage` and rolls it in (`--no-apply` only records it). See [agentlab as a development environment](dev-environment.md). |
| `login [email]` | Log in as a lab user: the headless password grant, or `--browser` for the real Dex login page (authorization-code flow, which asks for the user itself). Either way it prints the token claims and writes `.token` and `kubeconfig.oidc` for that user. `--password` overrides the one in `agentlab.yaml`. `--audience` (repeatable, default `kubernetes`, headless only) names the token's audience: `kubernetes` for the apiserver, `agent-platform` for muster and the agent-platform MCP servers behind it (workspace-manager, agent-manager, model-manager), `dex-k8s-authenticator` for muster's own Kubernetes writes. Any set besides `kubernetes` alone is minted by the `agent-platform` Dex client, so its token carries `agent-platform` too; `kubeconfig.oidc` is written only when the token carries `kubernetes`. |
| `turn (--list \| --template <name> <prompt> \| --session <id> --delete)` | One conversation with an agent as a lab user, the way the surfaces drive it: the user's Dex id_token on the kagent controller's gRPC route through the edge. `--list` prints the roster that user sees — `ListAgents` as that person (each Agent with the AgentTemplate and the Harness it pairs), or the gRPC status when the controller refuses. With `--template` and one prompt it starts a `Session`, through agent-manager's `start_session` as that user, of the Agent that pairs the template with a Harness — the template's Agent that reports Ready, the one the portal picks; `--harness` picks the Agent pairing the template with that Harness — streams one turn, prints the answer and the terminal task state, and deletes the session. `--user` picks the lab user (default: the first admin). `--keep` leaves the session for a later `--session <id>` turn (`--instance` is the former name) and prints the command that deletes it: `--session <id> --delete` deletes a kept session as the `--user`, its creator, the way a turn's own cleanup does (`DeleteSession`, retried while its runtime work settles, releasing its actor and snapshot), reads it back gone, and refuses an id that user cannot see — another user's, or one already gone; and `--session … --suspend` suspends it to the snapshot store and resumes it before the turn, the proof that a conversation survives the snapshot. The terminal status message's metadata (a harness's usage of the turn) is printed when present. A turn that pauses for tool approval prints the request and stops; `--decide approve` or `--decide reject` (with `--reason`) answers every request until the task settles. `--events <file>` writes every streamed A2A event as one JSON object per line, the raw material of a parser fixture. `--session <id> --share-with <email>` has the `--user` share the session read-write with another lab user (`--share-ttl` bounds how long the share's token grants access; default until revoked), runs the turn as that user with the share token (their own Dex token plus the token, which adds to their identity), and revokes the share afterwards. |
| `turn (--list \| --template <name> [--namespace <ns>] <prompt> \| --session <id> --delete)` | One conversation with an agent as a lab user, the way the surfaces drive it: the user's Dex id_token on the kagent controller's gRPC route through the edge. `--list` prints the roster that user sees in every namespace — `ListAgents` and `ListAgentTemplates` as that person with no namespace, as klaus-gateway and the Dev Portal ask, so `kagent`, `public-agents` and the organizations' namespaces alike (each Agent as `<namespace>/<name>`, with the AgentTemplate of its own namespace and the Harness it pairs), or the gRPC status when the controller refuses. With `--template` and one prompt it starts a `Session`, through agent-manager's `start_session` as that user, of the Agent that pairs the template with a Harness (or of the inline Agent of that name), in that Agent's own namespace — the template's Agent that reports Ready, the one the portal picks; `--harness` picks the Agent pairing the template with that Harness — streams one turn, prints the answer and the terminal task state, and deletes the session. The Agents of every namespace are candidates; `--namespace` keeps those of one namespace, and a name with Agents in more than one namespace is refused without it, naming the namespaces, before `--harness` or the readiness could pick one. `start_session` names the Agent by its namespace, which agent-manager takes for the installation's own platform namespaces it manages (`kagent`, and `public-agents` where the chart has it) and refuses for an organization's namespace, naming the organization: `turn` cannot start a Session of an organization's agent. `--user` picks the lab user (default: the first admin). `--keep` leaves the session for a later `--session <id>` turn (`--instance` is the former name) and prints the command that deletes it: `--session <id> --delete` deletes a kept session as the `--user`, its creator, the way a turn's own cleanup does (`DeleteSession`, retried while its runtime work settles, releasing its actor and snapshot), reads it back gone, and refuses an id that user cannot see — another user's, or one already gone; and `--session … --suspend` suspends it to the snapshot store and resumes it before the turn, the proof that a conversation survives the snapshot. The terminal status message's metadata (a harness's usage of the turn) is printed when present. A turn that pauses for tool approval prints the request and stops; `--decide approve` or `--decide reject` (with `--reason`) answers every request until the task settles. `--events <file>` writes every streamed A2A event as one JSON object per line, the raw material of a parser fixture. `--session <id> --share-with <email>` has the `--user` share the session read-write with another lab user (`--share-ttl` bounds how long the share's token grants access; default until revoked), runs the turn as that user with the share token (their own Dex token plus the token, which adds to their identity), and revokes the share afterwards. |

`kubectl --kubeconfig kubeconfig.oidc` after `login` is the OIDC path — the
way to verify what a specific user can do. The kind admin context bypasses the
Expand Down
4 changes: 2 additions & 2 deletions internal/lab/a2atest.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,9 @@ func edgePostWithoutToken(cfg *config.Config, contentType string, body []byte) (
// findListing is the roster entry of one Agent among the listed ones.
func findListing(agents []*apiv1alpha1.Agent, templates []*apiv1alpha1.AgentTemplate, name string) (agentListing, error) {
var names []string
byName := templatesByName(templates)
byRef := templatesByRef(templates)
for _, agent := range agents {
l := listingOf(agent, byName)
l := listingOf(agent, byRef)
if l.Name == name {
return l, nil
}
Expand Down
48 changes: 39 additions & 9 deletions internal/lab/kagentapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,17 @@ func (a *kagentAPI) listTemplates(ctx context.Context) ([]*apiv1alpha1.AgentTemp
return resp.GetAgentTemplates(), nil
}

// listTemplatesIn is AgentTemplateService/ListAgentTemplates of one
// namespace, or of every namespace the caller may list when ns is empty —
// listAgentsIn's twin, as klaus-gateway and the portal ask for the roster.
func (a *kagentAPI) listTemplatesIn(ctx context.Context, ns string) ([]*apiv1alpha1.AgentTemplate, error) {
resp, err := a.templates.ListAgentTemplates(a.callCtx(ctx), &apiv1alpha1.ListAgentTemplatesRequest{Namespace: ns})
if err != nil {
return nil, fmt.Errorf("ListAgentTemplates: %w", err)
}
return resp.GetAgentTemplates(), nil
}

// listAgents is AgentService/ListAgents of the kagent namespace, the roster
// call: every runnable definition (an AgentTemplate paired with a Harness) a
// Session can be created of.
Expand Down Expand Up @@ -536,14 +547,26 @@ type agentListing struct {
Name, Namespace, Template, Harness, DisplayName, IconURL, Description, Unavailable string
}

// ref is the reference of the listed Agent, in its own namespace: the Agent
// a Session of it is created of.
func (l agentListing) ref() *apiv1alpha1.ResourceReference {
return &apiv1alpha1.ResourceReference{Namespace: l.Namespace, Name: l.Name}
}

// qualifiedName is the Agent as the roster names it: `<namespace>/<name>`.
func (l agentListing) qualifiedName() string {
return l.Namespace + "/" + l.Name
}

// listingOf derives the roster entry from a listed Agent: the references
// from its spec, the annotations from its metadata (the AgentTemplate's when
// the Agent carries none, templates being the namespace's by name), the
// readiness from its status. An Agent is selectable once it has a
// the Agent carries none — its templateRef is a local reference, so the
// template of that name in the Agent's own namespace), the readiness from
// its status. An Agent is selectable once it has a
// latestSuccessfulRevision: kagent starts new conversations on that revision
// while a newer one prepares (Ready=False, ActorTemplatePending), as the
// kagent UI does; one without falls back to Ready=True.
func listingOf(agent *apiv1alpha1.Agent, templates map[string]*apiv1alpha1.AgentTemplate) agentListing {
func listingOf(agent *apiv1alpha1.Agent, templates map[templateKey]*apiv1alpha1.AgentTemplate) agentListing {
resource := agent.GetResource().GetValue().AsMap()
spec := nestedMap(resource, crSpec)
l := agentListing{
Expand All @@ -555,7 +578,7 @@ func listingOf(agent *apiv1alpha1.Agent, templates map[string]*apiv1alpha1.Agent
annotations, _ := nestedMap(resource, crMetadata)["annotations"].(map[string]any)
l.DisplayName = stringOf(annotations[displayNameAnnotation])
l.IconURL = stringOf(annotations[iconURLAnnotation])
if template := templates[l.Template]; template != nil {
if template := templates[templateKey{namespace: l.Namespace, name: l.Template}]; template != nil {
l.Description = template.GetDescription()
templateAnnotations := nestedMap(nestedMap(template.GetResource().GetValue().AsMap(), crMetadata), "annotations")
if l.DisplayName == "" {
Expand All @@ -579,13 +602,20 @@ func listingOf(agent *apiv1alpha1.Agent, templates map[string]*apiv1alpha1.Agent
return l
}

// templatesByName indexes listed AgentTemplates by name.
func templatesByName(templates []*apiv1alpha1.AgentTemplate) map[string]*apiv1alpha1.AgentTemplate {
byName := make(map[string]*apiv1alpha1.AgentTemplate, len(templates))
// templateKey is a listed AgentTemplate's namespace and name.
type templateKey struct {
namespace, name string
}

// templatesByRef indexes listed AgentTemplates by namespace and name, so a
// roster of several namespaces pairs each Agent with the template of its own
// namespace only.
func templatesByRef(templates []*apiv1alpha1.AgentTemplate) map[templateKey]*apiv1alpha1.AgentTemplate {
byRef := make(map[templateKey]*apiv1alpha1.AgentTemplate, len(templates))
for _, t := range templates {
byName[t.GetRef().GetName()] = t
byRef[templateKey{namespace: t.GetRef().GetNamespace(), name: t.GetRef().GetName()}] = t
}
return byName
return byRef
}

// readyConditionOf reads the Ready condition of an Agent's
Expand Down
40 changes: 32 additions & 8 deletions internal/lab/kagentapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (f *fakeKagent) ListAgentTemplates(ctx context.Context, req *apiv1alpha1.Li
defer f.mu.Unlock()
var out []*apiv1alpha1.AgentTemplate
for _, t := range f.templates {
if t.GetRef().GetNamespace() == req.GetNamespace() {
if listedIn(t.GetRef(), req.GetNamespace()) {
out = append(out, t)
}
}
Expand All @@ -343,13 +343,19 @@ func (f *fakeKagent) ListAgents(ctx context.Context, req *apiv1alpha1.ListAgents
defer f.mu.Unlock()
var out []*apiv1alpha1.Agent
for _, a := range f.agents {
if a.GetRef().GetNamespace() == req.GetNamespace() {
if listedIn(a.GetRef(), req.GetNamespace()) {
out = append(out, a)
}
}
return &apiv1alpha1.ListAgentsResponse{Agents: out}, nil
}

// listedIn mirrors the list calls' namespace: one namespace, or every one
// for an empty namespace (the fake grants the caller every namespace).
func listedIn(ref *apiv1alpha1.ResourceReference, namespace string) bool {
return namespace == "" || ref.GetNamespace() == namespace
}

func (f *fakeKagent) GetSubstrateSummary(ctx context.Context, _ *apiv1alpha1.GetSubstrateSummaryRequest) (*apiv1alpha1.GetSubstrateSummaryResponse, error) {
f.record(ctx, "GetSubstrateSummary")
if _, err := edge(ctx); err != nil {
Expand Down Expand Up @@ -600,7 +606,13 @@ func fakeSession(id, creator, agent string) *apiv1alpha1.Session {
// whole CR as a StructuredObject plus the denormalised fields.
func fakeTemplate(t *testing.T, name string, annotations map[string]any) *apiv1alpha1.AgentTemplate {
t.Helper()
meta := map[string]any{nameKey: name, fieldNamespace: kagentNamespace}
return fakeTemplateIn(t, kagentNamespace, name, annotations)
}

// fakeTemplateIn is fakeTemplate in the namespace.
func fakeTemplateIn(t *testing.T, namespace, name string, annotations map[string]any) *apiv1alpha1.AgentTemplate {
t.Helper()
meta := map[string]any{nameKey: name, fieldNamespace: namespace}
if annotations != nil {
meta["annotations"] = annotations
}
Expand All @@ -612,7 +624,7 @@ func fakeTemplate(t *testing.T, name string, annotations map[string]any) *apiv1a
t.Fatal(err)
}
return &apiv1alpha1.AgentTemplate{
Ref: &apiv1alpha1.ResourceReference{Namespace: kagentNamespace, Name: name},
Ref: &apiv1alpha1.ResourceReference{Namespace: namespace, Name: name},
Resource: &apiv1alpha1.StructuredObject{ApiVersion: agentTemplateAPIVersion, Kind: kindAgentTemplate, Value: value},
Description: "Proof agent " + name,
}
Expand All @@ -623,24 +635,36 @@ func fakeTemplate(t *testing.T, name string, annotations map[string]any) *apiv1a
// annotations and the Ready condition given (nil conditions: no status yet).
func fakeAgent(t *testing.T, name, template, harness string, annotations map[string]any, conditions []any) *apiv1alpha1.Agent {
t.Helper()
meta := map[string]any{nameKey: name, fieldNamespace: kagentNamespace}
return fakeAgentIn(t, kagentNamespace, name, template, harness, annotations, conditions)
}

// fakeAgentIn is fakeAgent in the namespace; template "" writes the Agent
// inline, with no templateRef.
func fakeAgentIn(t *testing.T, namespace, name, template, harness string, annotations map[string]any, conditions []any) *apiv1alpha1.Agent {
t.Helper()
meta := map[string]any{nameKey: name, fieldNamespace: namespace}
if annotations != nil {
meta["annotations"] = annotations
}
status := map[string]any{}
if conditions != nil {
status[crConditions] = conditions
}
spec := map[string]any{"harnessRef": map[string]any{nameKey: harness}}
if template == "" {
spec["template"] = map[string]any{descriptionKey: "Inline agent " + name}
} else {
spec["templateRef"] = map[string]any{nameKey: template}
}
value, err := structpb.NewStruct(map[string]any{
fieldAPIVersion: kagentAPIVersion, fieldKind: kindAgent, fieldMetadata: meta,
fieldSpec: map[string]any{"templateRef": map[string]any{nameKey: template}, "harnessRef": map[string]any{nameKey: harness}},
fieldStatus: status,
fieldSpec: spec, fieldStatus: status,
})
if err != nil {
t.Fatal(err)
}
return &apiv1alpha1.Agent{
Ref: &apiv1alpha1.ResourceReference{Namespace: kagentNamespace, Name: name},
Ref: &apiv1alpha1.ResourceReference{Namespace: namespace, Name: name},
Resource: &apiv1alpha1.StructuredObject{ApiVersion: kagentAPIVersion, Kind: kindAgent, Value: value},
}
}
Expand Down
Loading
Loading