Skip to content

Conversation

@ksimon1
Copy link

@ksimon1 ksimon1 commented Dec 2, 2025

Summary

This PR extends the KubeVirt toolset with VM lifecycle management capabilities, enabling AI agents to start, stop, and restart virtual machines.

The new vm_lifecycle tool accepts:

  • namespace: The namespace of the virtual machine
  • name: The name of the virtual machine
  • action: The lifecycle action ('start', 'stop', or 'restart')

start

Starts a halted VirtualMachine by updating its runStrategy to Always.

stop

Stops a running VirtualMachine by updating its runStrategy to Halted.

restart

Restarts a VirtualMachine by cycling it through a complete stop-start sequence.

@ksimon1 ksimon1 force-pushed the start-stop-restart-kubevirt branch from 57ac756 to 2a36d67 Compare December 2, 2025 10:21
@ksimon1
Copy link
Author

ksimon1 commented Dec 2, 2025

@manusa, @Cali0707 would you please review this PR?

@ksimon1
Copy link
Author

ksimon1 commented Dec 3, 2025

@codingben can you please review this PR?

Copy link
Collaborator

@Cali0707 Cali0707 left a comment

Choose a reason for hiding this comment

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

Hey @ksimon1 is it possible to consolidate these three tools into one?

IMO, a tool like vm_lifecycle_update or vm_lifecycle_set could work well - stop/start/restart could all be options set in the tool call.

That should help us keep a smaller tool count in this toolset

WDYT? (also cc @manusa as he has lots of great ideas about tool defs)

@ksimon1
Copy link
Author

ksimon1 commented Dec 3, 2025

@Cali0707 for sure I can do that 👍

@codingben
Copy link

Hey @ksimon1 is it possible to consolidate these three tools into one?

IMO, a tool like vm_lifecycle_update or vm_lifecycle_set could work well - stop/start/restart could all be options set in the tool call.

That should help us keep a smaller tool count in this toolset

WDYT? (also cc @manusa as he has lots of great ideas about tool defs)

It's similar to KubeVirt implementation in lifecycle.go from BackEnd perspective.

Why we're not importing "kubevirt.io/api/core/v1" to get the running strategy and actually the KubeVirt's client implementation? I'm not fan of dynamic client and unstructured fields.

Copy link

@codingben codingben left a comment

Choose a reason for hiding this comment

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

Looks good, just try to have a single lifecycle tool, and I'd recommend to get rid of the dynamic client and unstructured fields.

return api.NewToolCallResult("# VirtualMachine restarted successfully\n"+marshalledYaml, nil), nil
}

func getRequiredString(params api.ToolHandlerParams, key string) (string, error) {

Choose a reason for hiding this comment

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

nit: This is a duplicated function, should be part of API utils or something else.

@ksimon1 ksimon1 force-pushed the start-stop-restart-kubevirt branch from 2a36d67 to 1935000 Compare December 4, 2025 09:38
@ksimon1
Copy link
Author

ksimon1 commented Dec 4, 2025

@codingben I am not fan of unstructured and dynamic client too, but problem is, that kubevirt.io/client-go has dependency conflicts with packages in this project. That means I would have to update dependencies in this project to fit our kubevirt dependency. @Cali0707 do you think it would be possible?

@ksimon1
Copy link
Author

ksimon1 commented Dec 4, 2025

@Cali0707, @manusa can you please review new code?

Copy link

@codingben codingben left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Add the vm_start, vm_stop, and vm_restart tools into a
single vm_lifecycle tool with an 'action' parameter.

The new vm_lifecycle tool accepts:
- namespace: The namespace of the virtual machine
- name: The name of the virtual machine
- action: The lifecycle action ('start', 'stop', or 'restart')

- start: changes runStrategy to Always
- stop: changes runStrategy to Halted
- restart: stops then starts the VM

Code was assisted by Cursor AI.

Signed-off-by: Karel Simon <[email protected]>
Add tests for the vm_lifecycle tool

Code was assisted by Cursor AI.

Signed-off-by: Karel Simon <[email protected]>
@ksimon1 ksimon1 force-pushed the start-stop-restart-kubevirt branch from 1935000 to 3773aa9 Compare December 4, 2025 10:28
@codingben
Copy link

@ksimon1 Can you please update the PR description and commit messages?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants