Documentation
¶
Overview ¶
Package tools implements the kubectl-ai tool system.
Index ¶
- func ConvertToolToGollm(mcpTool *mcp.Tool) (*gollm.FunctionDefinition, error)
- func IsInteractiveCommand(command string) (bool, error)
- func LoadAndRegisterCustomTools(configPath string) error
- func RegisterTool(tool Tool)
- func ToolResultToMap(result any) (map[string]any, error)
- type BashTool
- func (t *BashTool) CheckModifiesResource(args map[string]any) string
- func (t *BashTool) Description() string
- func (t *BashTool) FunctionDefinition() *gollm.FunctionDefinition
- func (t *BashTool) IsInteractive(args map[string]any) (bool, error)
- func (t *BashTool) Name() string
- func (t *BashTool) Run(ctx context.Context, args map[string]any) (any, error)
- type ContextKey
- type CustomTool
- func (t *CustomTool) CheckModifiesResource(args map[string]any) string
- func (t *CustomTool) Description() string
- func (t *CustomTool) FunctionDefinition() *gollm.FunctionDefinition
- func (t *CustomTool) IsInteractive(args map[string]any) (bool, error)
- func (t *CustomTool) Name() string
- func (t *CustomTool) Run(ctx context.Context, args map[string]any) (any, error)
- type CustomToolConfig
- type ExecResult
- type InvokeToolOptions
- type Kubectl
- func (t *Kubectl) CheckModifiesResource(args map[string]any) string
- func (t *Kubectl) Description() string
- func (t *Kubectl) FunctionDefinition() *gollm.FunctionDefinition
- func (t *Kubectl) IsInteractive(args map[string]any) (bool, error)
- func (t *Kubectl) Name() string
- func (t *Kubectl) Run(ctx context.Context, args map[string]any) (any, error)
- type MCPTool
- func (t *MCPTool) CheckModifiesResource(args map[string]any) string
- func (t *MCPTool) Description() string
- func (t *MCPTool) FunctionDefinition() *gollm.FunctionDefinition
- func (t *MCPTool) IsInteractive(args map[string]any) (bool, error)
- func (t *MCPTool) Name() string
- func (t *MCPTool) Run(ctx context.Context, args map[string]any) (any, error)
- func (t *MCPTool) ServerName() string
- type Tool
- type ToolCall
- type ToolRequestEvent
- type ToolResponseEvent
- type Tools
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertToolToGollm ¶ added in v0.0.12
func ConvertToolToGollm(mcpTool *mcp.Tool) (*gollm.FunctionDefinition, error)
ConvertToolToGollm converts an MCP tool to gollm.FunctionDefinition with a simple schema
func IsInteractiveCommand ¶ added in v0.0.11
func LoadAndRegisterCustomTools ¶ added in v0.0.9
LoadAndRegisterCustomTools loads tool configurations from a YAML file and registers them.
Types ¶
type BashTool ¶
type BashTool struct{}
func (*BashTool) CheckModifiesResource ¶ added in v0.0.13
CheckModifiesResource determines if the command modifies kubernetes resources This is used for permission checks before command execution Returns "yes", "no", or "unknown"
func (*BashTool) Description ¶
func (*BashTool) FunctionDefinition ¶
func (t *BashTool) FunctionDefinition() *gollm.FunctionDefinition
func (*BashTool) IsInteractive ¶ added in v0.0.11
type ContextKey ¶ added in v0.0.9
type ContextKey string
const ( KubeconfigKey ContextKey = "kubeconfig" WorkDirKey ContextKey = "work_dir" )
type CustomTool ¶ added in v0.0.9
type CustomTool struct {
// contains filtered or unexported fields
}
CustomTool implements the Tool interface for external commands.
func NewCustomTool ¶ added in v0.0.9
func NewCustomTool(config CustomToolConfig) (*CustomTool, error)
NewCustomTool creates a new CustomTool instance.
func (*CustomTool) CheckModifiesResource ¶ added in v0.0.13
func (t *CustomTool) CheckModifiesResource(args map[string]any) string
CheckModifiesResource determines if the command modifies resources For custom tools, we'll conservatively assume they might modify resources unless we have specific knowledge otherwise Returns "yes", "no", or "unknown"
func (*CustomTool) Description ¶ added in v0.0.9
func (t *CustomTool) Description() string
Description returns the tool's description from its function definition.
func (*CustomTool) FunctionDefinition ¶ added in v0.0.9
func (t *CustomTool) FunctionDefinition() *gollm.FunctionDefinition
FunctionDefinition returns the tool's function definition.
func (*CustomTool) IsInteractive ¶ added in v0.0.11
func (t *CustomTool) IsInteractive(args map[string]any) (bool, error)
For CustomTool
func (*CustomTool) Name ¶ added in v0.0.9
func (t *CustomTool) Name() string
Name returns the tool's name.
type CustomToolConfig ¶ added in v0.0.9
type CustomToolConfig struct { Name string `yaml:"name"` Description string `yaml:"description"` Command string `yaml:"command"` CommandDesc string `yaml:"command_desc"` IsInteractive bool `yaml:"is_interactive"` }
CustomToolConfig defines the structure for configuring a custom tool.
type ExecResult ¶
type ExecResult struct { Command string `json:"command,omitempty"` Error string `json:"error,omitempty"` Stdout string `json:"stdout,omitempty"` Stderr string `json:"stderr,omitempty"` ExitCode int `json:"exit_code,omitempty"` StreamType string `json:"stream_type,omitempty"` }
func (*ExecResult) String ¶ added in v0.0.12
func (e *ExecResult) String() string
type InvokeToolOptions ¶
type Kubectl ¶
type Kubectl struct{}
func (*Kubectl) CheckModifiesResource ¶ added in v0.0.13
CheckModifiesResource determines if the command modifies kubernetes resources This is used for permission checks before command execution Returns "yes", "no", or "unknown"
func (*Kubectl) Description ¶
func (*Kubectl) FunctionDefinition ¶
func (t *Kubectl) FunctionDefinition() *gollm.FunctionDefinition
func (*Kubectl) IsInteractive ¶ added in v0.0.11
type MCPTool ¶ added in v0.0.12
type MCPTool struct {
// contains filtered or unexported fields
}
MCPTool wraps an MCP server tool to implement the Tool interface. It serves as an adapter between MCP-based tools and kubectl-ai's tool system.
func NewMCPTool ¶ added in v0.0.12
func NewMCPTool(serverName, toolName, description string, schema *gollm.FunctionDefinition, manager *mcp.Manager) *MCPTool
NewMCPTool creates a new MCP tool wrapper.
func (*MCPTool) CheckModifiesResource ¶ added in v0.0.13
CheckModifiesResource determines if the command modifies kubernetes resources For MCP tools, we'll conservatively assume they might modify resources since we can't easily determine this for arbitrary external tools Returns "yes", "no", or "unknown"
func (*MCPTool) Description ¶ added in v0.0.12
Description returns the tool description.
func (*MCPTool) FunctionDefinition ¶ added in v0.0.12
func (t *MCPTool) FunctionDefinition() *gollm.FunctionDefinition
FunctionDefinition returns the tool's function definition.
func (*MCPTool) IsInteractive ¶ added in v0.0.12
TODO(tuannvm): This is a placeholder implementation. Need to implement detection of interactive MCP tools. IsInteractive checks if the tool requires interactive input.
func (*MCPTool) Run ¶ added in v0.0.12
Run executes the MCP tool by calling the appropriate MCP server.
func (*MCPTool) ServerName ¶ added in v0.0.12
ServerName returns the MCP server name.
type Tool ¶
type Tool interface { // Name is the identifier for the tool; we pass this to the LLM. // The LLM uses this name when it wants to invoke the tool. // It should be meaningful and (we think) camel_case as (we think) that works better with most LLMs. Name() string // Description is an additional description that gives the LLM instructions on when to use the tool. Description() string // FunctionDefinition provides the full schema for the parameters to be used when invoking the tool. // The Description fields provides hints that the LLM may use to use the tool more effectively/correctly. FunctionDefinition() *gollm.FunctionDefinition // Run invokes the tool, the agent calls this when the LLM requests tool invocation. Run(ctx context.Context, args map[string]any) (any, error) // IsInteractive checks if a command is interactive // If the command is interactive, we need to handle it differently in the agent // Returns true if interactive, with an error explaining why it's interactive IsInteractive(args map[string]any) (bool, error) // CheckModifiesResource determines if the command modifies resources // This is used for permission checks before command execution // Returns "yes", "no", or "unknown" CheckModifiesResource(args map[string]any) string }
type ToolCall ¶
type ToolCall struct {
// contains filtered or unexported fields
}
func (*ToolCall) Description ¶ added in v0.0.15
Description returns a description of the tool call. This is used to display the tool call in the UI. It should be human-readable, and should be concise enough that the user can read it quickly, but precise enough that the user can decide whether to invoke the tool.
func (*ToolCall) InvokeTool ¶
InvokeTool handles the execution of a single action
type ToolRequestEvent ¶
type ToolResponseEvent ¶
type Tools ¶
type Tools struct {
// contains filtered or unexported fields
}
func (*Tools) ParseToolInvocation ¶
func (t *Tools) ParseToolInvocation(ctx context.Context, name string, arguments map[string]any) (*ToolCall, error)
ParseToolInvocation parses a request from the LLM into a tool call.