Skip to content

feat(cli): add API v2 AgentInstance workflows - #2559

Open
codyhartsook wants to merge 12 commits into
kagent-dev:mainfrom
codyhartsook:api-v2-cli-pr1-split
Open

feat(cli): add API v2 AgentInstance workflows#2559
codyhartsook wants to merge 12 commits into
kagent-dev:mainfrom
codyhartsook:api-v2-cli-pr1-split

Conversation

@codyhartsook

@codyhartsook codyhartsook commented Aug 25, 2026

Copy link
Copy Markdown

Summary

  • Adds API v2 CLI commands for AgentTemplate discovery and AgentInstance lifecycle and invocation
  • Adds typed AgentInstance and upstream A2A clients over the shared gRPC connection
  • Connects through configured gRPC or a temporary controller port-forward, with optional TLS
  • Removes the legacy client-side agent project workflow while retaining mcp

Note that of the 64 files changed, 35 were removals from the legacy CLI project workflow ; no server-side APIs or controllers are removed.

This is the first of three related CLI PRs:

  1. #2559 : API v2 CLI foundation: template/instance discovery, create/delete, invoke/streaming, JSON output, and quarantining legacy commands.
  2. #2605 : TUI: browse AgentInstances, load history, and chat through the same A2A path as invoke.
  3. #2606 : Cleanup: simplify main.go and align the command structure with agentregistry.

Suspend and resume are deliberately not exposed by this CLI work.

Related to #2366 and the K13 CLI cutover in docs/plans/api-v2-execution-plan.md.

Test plan

  • make -C go test
  • go test ./core/cli/...
  • make -C go lint
  • make -C go build
  • AgentTemplate and AgentInstance CLI smoke test against a local installation

@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 25, 2026
@codyhartsook
codyhartsook marked this pull request as ready for review August 25, 2026 23:57
@codyhartsook
codyhartsook requested a review from a team as a code owner August 25, 2026 23:57

@EItanya EItanya 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.

Initial review, I'm still looking for more simplifications, but this is a good start

Comment thread go/core/cli/internal/tui/dialogs/mcp_server_wizard.go Outdated
Comment thread go/core/cli/internal/cli/agentinstance/lifecycle.go Outdated
Comment thread go/core/cli/internal/config/config.go Outdated
@codyhartsook
codyhartsook requested a review from EItanya August 26, 2026 16:39
Signed-off-by: Cody Hartsook <cody.hartsook@solo.io>
Signed-off-by: Cody Hartsook <cody.hartsook@solo.io>
Signed-off-by: Cody Hartsook <cody.hartsook@solo.io>
Signed-off-by: Cody Hartsook <cody.hartsook@solo.io>
Signed-off-by: Cody Hartsook <cody.hartsook@solo.io>
Signed-off-by: Cody Hartsook <cody.hartsook@solo.io>
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 27, 2026
Comment on lines +85 to +86
checkServer func(context.Context, *client.ClientSet) error
commandContext func(context.Context, string, ...string) *exec.Cmd

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.

I really really hate callbacks unless absolutely necessary. Can you explain this component and why we need these?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, fair point. These callbacks mainly exist for tests and make the production path harder to follow. I’ll remove the runtime wrapper, call the real functions directly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed these

Comment thread go/core/test/e2e/interaction_test.go Outdated
Comment on lines +169 to +183
func buildKagentCLI(t *testing.T) string {
t.Helper()
_, source, _, ok := goruntime.Caller(0)
if !ok {
t.Fatal("locate interaction test source")
}
moduleRoot := filepath.Clean(filepath.Join(filepath.Dir(source), "../../.."))
binary := filepath.Join(t.TempDir(), "kagent")
command := exec.CommandContext(t.Context(), "go", "build", "-o", binary, "./core/cli/cmd/kagent")
command.Dir = moduleRoot
if output, err := command.CombinedOutput(); err != nil {
t.Fatalf("build CLI: %v\n%s", err, output)
}
return binary
}

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.

I'd rather not build from the tests, can we use pre-built?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, the E2E target builds the CLI once and passes it through KAGENT_E2E_CLI. CI uses the same path

Comment thread go/core/test/e2e/interaction_test.go Outdated
}
}

func TestCLIAgentInstanceDiscoveryAndInvoke(t *testing.T) {

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.

All e2e tests should be prefixed with TestE2E

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated the two E2E tests added by this PR to use TestE2E

Comment thread go/core/test/e2e/interaction_test.go Outdated
Comment on lines +95 to +96
"--kagent-grpc-url", target,
"--kagent-grpc-tls=false",

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.

Why do these flags need the kagent prefix?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed the prefix from the new gRPC flags: --grpc-url, --grpc-tls, --grpc-ca-file, and --grpc-server-name.

Comment thread go/core/test/e2e/interaction_test.go Outdated
}
}

func TestCLIAgentInstanceDiscoveryAndInvoke(t *testing.T) {

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.

Can we group all of the cli tests in the same file

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

both CLI E2E tests are now in cli_catalog_lifecycle_test.go

Comment on lines -15 to -25
type Config struct {
KAgentURL string `mapstructure:"kagent_url"`
KAgentGRPCURL string `mapstructure:"kagent_grpc_url"`
KAgentGRPCTLS bool `mapstructure:"kagent_grpc_tls"`
KAgentGRPCCAFile string `mapstructure:"kagent_grpc_ca_file"`
KAgentGRPCServerName string `mapstructure:"kagent_grpc_server_name"`
Namespace string `mapstructure:"namespace"`
OutputFormat string `mapstructure:"output_format"`
Verbose bool `mapstructure:"verbose"`
Timeout time.Duration `mapstructure:"timeout"`
}

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.

I think we still need this config to be embedded in the other cmd configs.

type AgentInstanceConfig struct {
  BaseConfig
}

Something like the above

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I ended up addressing this in PR #2606 by reading shared connection and output flags at each command boundary, so BaseConfig would no longer be needed. Would it be okay to leave this as-is here and handle it in that follow-up or prefer we address here?

EItanya and others added 2 commits August 28, 2026 11:05
@codyhartsook
codyhartsook marked this pull request as draft August 28, 2026 17:50
@codyhartsook
codyhartsook marked this pull request as ready for review August 28, 2026 19:58
@codyhartsook
codyhartsook requested a review from EItanya August 28, 2026 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants