Skip to content

feat(runtime): add Kagent deployment and discovery adapter - #655

Open
xytian315 wants to merge 14 commits into
mainfrom
xytian315/oss-kagent
Open

feat(runtime): add Kagent deployment and discovery adapter#655
xytian315 wants to merge 14 commits into
mainfrom
xytian315/oss-kagent

Conversation

@xytian315

Copy link
Copy Markdown
Collaborator

Description

Add a built-in Kagent runtime adapter for deployment and discovery.

  • Deploy and remove prebuilt A2A BYO Agents through Kagent.
  • Deploy and remove remote and source-backed MCPServers through Kagent.
  • Resolve Agent model and MCPServer references when building Kagent workloads.
  • Discover Kagent Agents and MCPServers and correlate them with managed deployments.
  • Support per-runtime authentication through Secret references.
  • Register Kagent deployment and discovery support by default.

Change Type

/kind feature

Changelog

Added Kagent runtime support for deploying BYO Agents and MCPServers and discovering Kagent workloads.

Additional Notes

Targeted development and smoke testing use Kagent v0.10.0-rc3.

Agent deployment currently supports prebuilt A2A workloads defined with spec.source.image. Harness-based deployments and Agents without a prebuilt image are not supported.

Manual smoke coverage included BYO Agent deployment, remote MCPServer deployment, and out-of-band Agent discovery.

Copilot AI lite review requested due to automatic review settings August 27, 2026 20:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a first-party Kagent runtime integration to AgentRegistry, covering workload translation, apply/remove behavior, REST client wiring, and discovery so Kagent-managed Agents/MCPServers can be deployed and correlated back to AgentRegistry Deployments.

Changes:

  • Introduces a new pkg/runtimes/kagent adapter with translation logic (BYO Agents + MCPServer tool servers), REST client, status handling, desired fingerprinting, and discovery.
  • Registers Kagent as a known runtime type and hooks runtime config validation into Runtime.Validate().
  • Wires Kagent into the registry app defaults and adds a DB-backed Deployment finder used to resolve source-backed MCPServer dependencies.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/runtimes/kagent/translate.go Translates AgentRegistry resources into Kagent REST payloads; resolves model + MCP wiring.
pkg/runtimes/kagent/translate_test.go Unit tests for translation, model resolution, and MCP dependency wiring.
pkg/runtimes/kagent/status.go Maps translation/apply outcomes into AgentRegistry ApplyResult conditions + runtime metadata.
pkg/runtimes/kagent/status_test.go Tests condition builders for success/failure/removal.
pkg/runtimes/kagent/rest_types.go Defines private Kagent REST wire payload structs/constants.
pkg/runtimes/kagent/fake_client_test.go Fake Kagent client used by adapter/discovery tests.
pkg/runtimes/kagent/discover.go Implements runtime discovery for Agents and MCPServers from Kagent.
pkg/runtimes/kagent/discover_test.go Tests discovery behavior, namespace filtering, and real ID response shape.
pkg/runtimes/kagent/config.go Runtime/deploy config decoding + admission-time validation helpers.
pkg/runtimes/kagent/config_test.go Tests config decoding/validation and admission registration behavior.
pkg/runtimes/kagent/client.go REST client for Kagent API (create/update/delete/list).
pkg/runtimes/kagent/client_test.go Tests REST client request/response behavior and replacement flows.
pkg/runtimes/kagent/adapter.go Main adapter: Apply/Remove/Discover/DesiredFingerprint + auth token sourcing.
pkg/runtimes/kagent/adapter_test.go Adapter tests for apply/remove, metadata, labels, fingerprint behavior, and auth resolution.
pkg/api/v1alpha1/runtime_validate.go Adds RuntimeConfigValidators and invokes per-runtime config validators during Runtime.Validate().
internal/registry/registry_app.go Registers Kagent adapter/discovery source by default and wires Deployment finder + optional secret resolver.
internal/registry/database/resolvers.go Adds DB-backed NewKagentDeploymentFinder used to locate managed deployments for MCP dependencies.
internal/registry/database/resolvers_integration_test.go Integration test for the Kagent deployment finder SQL filtering/matching.
internal/cli/common/deployments.go Improves CLI DeploymentStatus derivation for Ready=false failures.
internal/cli/common/deployments_test.go Adds coverage for Ready=false/Failed mapping to “failed”.
Makefile Updates Kagent version and Helm install flags for the newer chart layout.
Suppressed comments (1)

pkg/runtimes/kagent/config.go:213

  • decodeDeployConfig guards secretRefs by checking only the exact map key "secretRefs". Since JSON unmarshal is case-insensitive, a user could specify "SecretRefs" and have it populate cfg.SecretRefs without triggering the kind check, allowing unsupported deploy config fields to slip through validation for non-MCPServer targets.
func decodeDeployConfig(m map[string]any, targetKind string) (deployConfig, error) {
	if _, found := m["secretRefs"]; found && targetKind != v1alpha1.KindMCPServer {
		return deployConfig{}, fmt.Errorf("secretRefs is only supported for MCPServer deployments")
	}

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/runtimes/kagent/config.go
@xytian315
xytian315 force-pushed the xytian315/oss-kagent branch from 4bbebb6 to fad7df7 Compare August 28, 2026 06:44
NewStoreDeploymentFinder takes a Deployment store directly; the generic
database package no longer carries Kagent-specific lookup code.
Exports ErrAuthExpired, ErrDependencyNotReady, and FailedApplyResult;
adds finder coverage for namespace mismatches.
@xytian315
xytian315 force-pushed the xytian315/oss-kagent branch from fad7df7 to 9e30614 Compare August 28, 2026 06:45

@timflannagan timflannagan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As always, thanks for running this work down Kristy. One generic question that was hard to capture as an inline review comments. How much of this code can be moved into internal vs. exposed via pkg/? I think some of that will inform whether pkg/runtimes/kagent is a net new package we should introduce here vs. follow existing patterns in the codebase.

Comment thread internal/cli/common/deployments.go Outdated
Comment on lines +163 to +169
if ready := dep.Status.GetCondition("Ready"); ready != nil {
if ready.Status == v1alpha1.ConditionTrue {
return "deployed"
}
if ready.Status == v1alpha1.ConditionFalse && ready.Reason == "Failed" {
return "failed"
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update pkg/status and use the existing constants or expand it

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! changed here 67d030b

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll highlight this here instead of where it's defined. My preference is adding another method on the DeploymentController that was refactored recently. Ex: DeploymentApplied, instead of maintaining another separate type definition and introducing more indirection.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! changed here 67d030b

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much of this testing could be reduced to a single table-driven test?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! changed here 67d030b

Comment thread pkg/api/v1alpha1/runtime_validate.go Outdated
Comment on lines +16 to +18
// RuntimeConfigValidators lets runtime packages register admission checks
// without coupling the API package to concrete adapter implementations.
var RuntimeConfigValidators = map[string]func(map[string]any) error{}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for now, but this comment suggests a smell with our admission/validation logic

Comment on lines +84 to +86
var _ types.DeploymentAdapter = (*adapter)(nil)
var _ types.DeploymentDiscoverySource = (*adapter)(nil)
var _ types.DeploymentDesiredFingerprinter = (*adapter)(nil)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing as above, fine for now, having to satisfy these many interfaces is a clear smell in our abstractions to me.

Comment thread pkg/runtimes/kagent/discover.go Outdated
Name: w.Name,
RuntimeMetadata: map[string]string{
types.RuntimeMetadataRemoteIDKey: w.Name,
"namespace": w.Namespace,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a constant for this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks changed here 67d030b

Comment thread internal/registry/registry_app.go
Comment thread pkg/runtimes/kagent/adapter.go Outdated
}

// WithWorkloadLabels adds labels to pod-backed Kagent resources.
func WithWorkloadLabels(labels map[string]string) Option {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprised we need this type of wiring. Can't this be derived from runtime or deployment config? Or even hardcoded via code?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! moved to runtimeDeploymentConfig in this commit 67d030b

if !ok || input.Deployment == nil {
return types.DefaultApplyFingerprint(ctx, input, options)
}
hasMCPDependencies := len(agent.Spec.MCPServers) > 0 ||

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're at it, we should talk about this spec.deploymentRefs field and the future of whether it's still beneficial here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah want to talk about this more. The assumption going forward is that every adapter will need to implement if it it's in the API surface. This PR just highlights this logic and not something and not a blocker for merging. The issue is I now have N ways to source an MCP server via the Agents API.

Comment thread pkg/runtimes/kagent/rest_types.go Outdated

const (
kagentV1Alpha2APIVersion = "kagent.dev/v1alpha2"
kagentV1Alpha1APIVersion = "kagent.dev/v1alpha1"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd almost be in favor of dropping this tbh. Our approach is best effort anyways.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! removed in this commit 67d030b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants