Skip to content

feat: Add AI-powered tool system with function calling capabilities#3

Merged
themusicman merged 5 commits intomainfrom
tool-usage
Jul 23, 2025
Merged

feat: Add AI-powered tool system with function calling capabilities#3
themusicman merged 5 commits intomainfrom
tool-usage

Conversation

@themusicman
Copy link
Copy Markdown
Contributor

Overview

This PR introduces a comprehensive tool system that enables AI-powered interactions with system commands and operations through LangChain integration.

✨ Key Features

  • Tool System: Unified interface for filesystem, git, shell, and AI agent operations
  • AI Agents: Support for both Ollama and simple agent implementations
  • Function Calling: LangChain integration for intelligent tool selection and execution
  • Enhanced Ask Command: AI-powered command suggestions and execution
  • Comprehensive Tools:
    • Filesystem operations (read, write, list directories)
    • Git operations (status, add, commit, push, etc.)
    • Shell command execution
    • Commit message generation

🔧 Technical Changes

New Components

  • tools/ package with complete tool ecosystem
  • OllamaAgent and SimpleAgent implementations
  • Unified Tool interface for consistent tool execution
  • Advanced commit message generation with AI

Enhanced Commands

  • ask: Now supports tool integration and AI-powered responses
  • init: Simplified implementation with better error handling

Configuration Updates

  • Expanded .workie.yaml with comprehensive tool configuration
  • Support for multiple AI models and agents

📊 Stats

  • 858b202: Added 998 lines across 11 files (initial tool system)
  • c595027: Added 484 lines across 4 files (function calling implementation)
  • Total: 1,482 lines of new functionality

🚨 Breaking Changes

  • Restructured command interface
  • Updated configuration format
  • New dependency requirements

🧪 Usage Examples

# AI-powered git operations
workie ask "create a commit with a good message for these changes"

# Filesystem operations
workie ask "show me the contents of the tools directory"

# Shell command assistance
workie ask "help me check the status of this repository"

Dependencies Added

  • LangChain Go integration
  • Enhanced Ollama client support

Ready for review! 🚀

- add tools package with filesystem, git, shell, and agent tools
- implement unified tool interface and execution system
- add ollama and simple agent implementations for AI interactions
- enhance ask command with tool integration
- simplify init command implementation
- update configuration with expanded tool capabilities
- add required dependencies

BREAKING CHANGE: restructured command interface and configuration format
Copilot AI review requested due to automatic review settings July 22, 2025 22:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a comprehensive AI-powered tool system that enables intelligent interaction with system commands and operations through LangChain integration. The implementation adds function calling capabilities to the existing ask command and provides specialized tools for filesystem, git, shell, and commit message operations.

Key changes include:

  • Complete tool ecosystem with unified interface for AI-powered operations
  • Enhanced ask command with tool integration and function calling support
  • AI agent implementations supporting both Ollama and simplified execution patterns

Reviewed Changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tools/tool.go Core tool interface and registry system with JSON schema support
tools/simple_agent.go Simplified agent implementation with direct query handling patterns
tools/ollama_agent.go Full LangChain-integrated agent with conversation management
tools/shell_tool.go Whitelisted shell command execution tool
tools/git_tool.go Git operations tool with smart defaults
tools/filesystem_tool.go File system operations tool with safety controls
tools/commit_message_tool.go AI-powered commit message generation tool
cmd/ask.go Enhanced ask command with tool calling capabilities
go.mod Updated dependencies for LangChain integration
cmd/init.go Updated configuration template with AI settings
.workie.yaml Comprehensive configuration with AI and tool settings

Comment thread tools/tool.go Outdated
toolDescriptions := "You are an AI assistant with access to tools that can execute system commands. You have access to the following tools:\n\n"

for _, tool := range tools {
params, _ := json.MarshalIndent(tool.Parameters(), "", " ")
Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

Error from json.MarshalIndent is silently ignored. This could result in empty or incomplete parameter documentation being shown to users, making it difficult to understand how to use tools properly.

Suggested change
params, _ := json.MarshalIndent(tool.Parameters(), "", " ")
params, err := json.MarshalIndent(tool.Parameters(), "", " ")
if err != nil {
toolDescriptions += "Tool: " + tool.Name() + "\n"
toolDescriptions += "Description: " + tool.Description() + "\n"
toolDescriptions += "Parameters: [Error formatting parameters: " + err.Error() + "]\n\n"
continue
}

Copilot uses AI. Check for mistakes.
Comment thread tools/simple_agent.go Outdated
fmt.Println("Detected list files query, using shell tool directly")
}

tool, _ := s.registry.Get("shell")
Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

Tool retrieval error is ignored. If the shell tool is not registered, this will cause a panic when calling tool.Execute. Should check the exists boolean and handle the error gracefully.

Suggested change
tool, _ := s.registry.Get("shell")
tool, exists := s.registry.Get("shell")
if !exists {
return "", fmt.Errorf("shell tool is not registered in the tool registry")
}

Copilot uses AI. Check for mistakes.
Comment thread tools/simple_agent.go Outdated
fmt.Println("Detected branch query, using git tool directly")
}

tool, _ := s.registry.Get("git")
Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

Tool retrieval error is ignored. If the git tool is not registered, this will cause a panic when calling tool.Execute. Should check the exists boolean and handle the error gracefully.

Suggested change
tool, _ := s.registry.Get("git")
tool, exists := s.registry.Get("git")
if !exists {
return "", fmt.Errorf("the 'git' tool is not registered in the tool registry")
}

Copilot uses AI. Check for mistakes.
Comment thread tools/simple_agent.go Outdated
fmt.Println("Detected pwd query, using shell tool directly")
}

tool, _ := s.registry.Get("shell")
Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

Tool retrieval error is ignored. If the shell tool is not registered, this will cause a panic when calling tool.Execute. Should check the exists boolean and handle the error gracefully.

Suggested change
tool, _ := s.registry.Get("shell")
tool, exists := s.registry.Get("shell")
if !exists {
return "", fmt.Errorf("shell tool is not registered in the tool registry")
}

Copilot uses AI. Check for mistakes.
Comment thread tools/simple_agent.go Outdated

// generateCommitMessageWithGit uses git tools to analyze changes
func (s *SimpleAgent) generateCommitMessageWithGit(ctx context.Context) (string, error) {
gitTool, _ := s.registry.Get("git")
Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

Tool retrieval error is ignored. If the git tool is not registered, this will cause a panic when calling tool.Execute. Should check the exists boolean and handle the error gracefully.

Suggested change
gitTool, _ := s.registry.Get("git")
gitTool, exists := s.registry.Get("git")
if !exists {
return "", fmt.Errorf("git tool is not registered in the tool registry")
}

Copilot uses AI. Check for mistakes.
Comment thread tools/filesystem_tool.go
Comment on lines +63 to +66

// Clean the path to prevent directory traversal
path = filepath.Clean(path)

Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

The filepath.Clean() function alone is insufficient to prevent directory traversal attacks. An attacker could still access files outside the intended directory using paths like '../../../etc/passwd'. Consider implementing additional validation to restrict access to a specific base directory.

Suggested change
// Clean the path to prevent directory traversal
path = filepath.Clean(path)
// Define the base directory for file operations
baseDir := "/safe/base/directory"
// Clean the path to prevent directory traversal
path = filepath.Clean(path)
// Ensure the path is within the base directory
if !strings.HasPrefix(path, filepath.Clean(baseDir)+string(os.PathSeparator)) {
return "", fmt.Errorf("access to the path is restricted: %s", path)
}

Copilot uses AI. Check for mistakes.
Comment thread tools/commit_message_tool.go Outdated
commitType = "feat"
if len(added) == 1 {
fileName := getFileName(added[0])
if fileName == "commit_message_tool.go" {
Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

Hard-coded filename check creates brittle logic that will break if the file is renamed. This creates a maintenance burden and inconsistent behavior. Consider using more generic pattern matching or removing this special case.

Suggested change
if fileName == "commit_message_tool.go" {
if strings.Contains(fileName, "commit_message_tool") {

Copilot uses AI. Check for mistakes.
- Add proper error handling for json.MarshalIndent in FormatToolsPrompt
- Fix all tool registry lookups to check existence before use
- Add directory traversal protection in FileSystemTool
- Replace hard-coded filename check with pattern matching
@themusicman themusicman merged commit 3931025 into main Jul 23, 2025
5 of 9 checks passed
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.

2 participants