Documentation
¶
Overview ¶
Package tools implements the kubectl-qyai tool system.
Index ¶
- func ConvertToolToGollm(mcpTool *mcp.Tool) (*gollm.FunctionDefinition, error)
- func DetectKubectlStreaming(command string) (bool, string)
- func ExecuteWithStreamingHandling(ctx context.Context, executor sandbox.Executor, command string, workDir string, ...) (*sandbox.ExecResult, error)
- func ExpandShellVar(value string) (string, error)
- func IsInteractiveCommand(command string) (bool, error)
- func KubectlModifiesResource(command string) string
- 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) CloneWithExecutor(executor sandbox.Executor) *CustomTool
- 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 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
- func (t *MCPTool) UniqueToolName() string
- type StreamDetector
- type Tool
- type ToolCall
- type ToolRequestEvent
- type ToolResponseEvent
- type Tools
- func (t *Tools) AllTools() []Tool
- func (t *Tools) CloneWithExecutor(executor sandbox.Executor) Tools
- func (t *Tools) Init()
- func (t *Tools) Lookup(name string) Tool
- func (t *Tools) Names() []string
- func (t *Tools) ParseToolInvocation(ctx context.Context, name string, arguments map[string]any) (*ToolCall, error)
- func (t *Tools) RegisterTool(tool Tool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertToolToGollm ¶
func ConvertToolToGollm(mcpTool *mcp.Tool) (*gollm.FunctionDefinition, error)
ConvertToolToGollm converts an MCP tool to gollm.FunctionDefinition with a simple schema
func DetectKubectlStreaming ¶
DetectKubectlStreaming checks if a kubectl command is a streaming command
func ExecuteWithStreamingHandling ¶
func ExecuteWithStreamingHandling(ctx context.Context, executor sandbox.Executor, command string, workDir string, env []string, detector StreamDetector) (*sandbox.ExecResult, error)
ExecuteWithStreamingHandling executes a command using the provided executor, handling streaming commands (watch, logs -f, attach) by applying a timeout and capturing partial output.
func ExpandShellVar ¶
ExpandShellVar expands shell variables and syntax using bash
func KubectlModifiesResource ¶ added in v1.0.5
KubectlModifiesResource analyzes a kubectl command to determine if it modifies resources. It returns: - "yes" if the command modifies resources - "no" if the command is read-only - "unknown" if the command could not be safely classified
func LoadAndRegisterCustomTools ¶
LoadAndRegisterCustomTools loads tool configurations from a YAML file and registers them.
Types ¶
type BashTool ¶
type BashTool struct {
// contains filtered or unexported fields
}
func (*BashTool) CheckModifiesResource ¶
CheckModifiesResource determines if the command modifies kubernetes resources This is used for permission checks before command execution Returns "yes", "no", or "unknown"
func (*BashTool) FunctionDefinition ¶
func (t *BashTool) FunctionDefinition() *gollm.FunctionDefinition
func (*BashTool) IsInteractive ¶
type ContextKey ¶
type ContextKey string
const ( KubeconfigKey ContextKey = "kubeconfig" WorkDirKey ContextKey = "work_dir" ExecutorKey ContextKey = "executor" )
type CustomTool ¶
type CustomTool struct {
// contains filtered or unexported fields
}
CustomTool implements the Tool interface for external commands.
func NewCustomTool ¶
func NewCustomTool(config CustomToolConfig) (*CustomTool, error)
NewCustomTool creates a new CustomTool instance.
func (*CustomTool) CheckModifiesResource ¶
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) CloneWithExecutor ¶
func (t *CustomTool) CloneWithExecutor(executor sandbox.Executor) *CustomTool
CloneWithExecutor creates a copy of the CustomTool with the given executor. This is used to create a session-specific instance of the tool.
func (*CustomTool) Description ¶
func (t *CustomTool) Description() string
Description returns the tool's description from its function definition.
func (*CustomTool) FunctionDefinition ¶
func (t *CustomTool) FunctionDefinition() *gollm.FunctionDefinition
FunctionDefinition returns the tool's function definition.
type CustomToolConfig ¶
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 InvokeToolOptions ¶
type Kubectl ¶
type Kubectl struct {
// contains filtered or unexported fields
}
func (*Kubectl) CheckModifiesResource ¶
CheckModifiesResource determines if the command modifies kubernetes resources This is used for permission checks before command execution Returns "yes", "no", or "unknown"
func (*Kubectl) FunctionDefinition ¶
func (t *Kubectl) FunctionDefinition() *gollm.FunctionDefinition
type MCPTool ¶
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-qyai's tool system.
func NewMCPTool ¶
func NewMCPTool(serverName, toolName, description string, schema *gollm.FunctionDefinition, manager *mcp.Manager) *MCPTool
NewMCPTool creates a new MCP tool wrapper.
func (*MCPTool) CheckModifiesResource ¶
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 ¶
Description returns the tool description.
func (*MCPTool) FunctionDefinition ¶
func (t *MCPTool) FunctionDefinition() *gollm.FunctionDefinition
FunctionDefinition returns the tool's function definition.
func (*MCPTool) IsInteractive ¶
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 ¶
Run executes the MCP tool by calling the appropriate MCP server.
func (*MCPTool) ServerName ¶
ServerName returns the MCP server name.
type StreamDetector ¶
StreamDetector determines if a command is a streaming command and returns the stream type. It returns (true, streamType) if it is a streaming command, and (false, "") otherwise.
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 ¶
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.
type ToolRequestEvent ¶
type ToolResponseEvent ¶
type Tools ¶
type Tools struct {
// contains filtered or unexported fields
}
func (*Tools) CloneWithExecutor ¶
CloneWithExecutor creates a shallow copy of the Tools collection, but clones any tools that need a session-specific executor (like CustomTool).
Source Files
¶
- bash_tool.go
- custom_tool.go
- interfaces.go
- kubectl_filter.go
- kubectl_tool.go
- mcp_tool.go
- streaming.go
- tools.go