README
¶
GoSkills Integration Example
This example demonstrates how to integrate GoSkills with LangGraphGo, allowing agents to use skills as tools.
1. Background
GoSkills is a framework for creating and managing reusable skills that can execute Python scripts, shell commands, and provide various built-in tools like web search and file operations. By integrating GoSkills with LangGraphGo, you can easily extend your agents with powerful, pre-packaged capabilities without writing custom tool implementations.
2. Key Concepts
- GoSkills: A skill management framework that packages scripts and tools into reusable skill packages.
- Skill Package: A directory containing a
SKILL.mdfile with metadata and optional scripts in ascripts/subdirectory. - SkillsToTools Adapter: A convenience function (
adapter.SkillsToTools) that converts GoSkills skill packages intotools.Toolinterfaces compatible with LangGraphGo. - Multi-Skill Support: The adapter can load and register multiple skills from a directory, aggregating all their tools.
3. How It Works
- Load Skills: Use
goskills.ParseSkillPackagesto scan a directory (e.g.,./skills) for skill packages. - Convert to Tools: For each skill package, call
adapter.SkillsToToolsto convert the skill's capabilities intotools.Toolinstances. - Aggregate Tools: Combine tools from all skills into a single slice.
- Create Agent: Use
prebuilt.CreateAgentwith the aggregated tools and a system message that includes all skill descriptions. - Invoke: Run the agent with a user query. The agent will automatically select and use the appropriate tools from the loaded skills.
4. Code Highlights
Loading All Skills
skillsDir := "skills"
packages, err := goskills.ParseSkillPackages(skillsDir)
if err != nil {
log.Fatal(err)
}
Converting Skills to Tools
var allTools []tools.Tool
var allSystemMessages strings.Builder
allSystemMessages.WriteString("You are a helpful assistant that can use skills.\n\n")
for _, skill := range packages {
fmt.Printf("Loading skill: %s\n", skill.Meta.Name)
skillTools, err := adapter.SkillsToTools(*skill)
if err != nil {
log.Printf("Failed to convert skill %s to tools: %v", skill.Meta.Name, err)
continue
}
allTools = append(allTools, skillTools...)
allSystemMessages.WriteString(fmt.Sprintf("Skill: %s\n%s\n\n", skill.Meta.Name, skill.Body))
}
Creating the Agent
agent, err := prebuilt.CreateAgent(llm, allTools,
prebuilt.WithSystemMessage(allSystemMessages.String()))
if err != nil {
log.Fatal(err)
}
5. Skill Structure
A basic skill package structure:
skills/
└── hello_world/
├── SKILL.md # Skill metadata and description
└── scripts/
└── hello.py # Python script
SKILL.md example:
---
name: hello_world
description: A simple skill that prints a greeting
version: 1.0.0
---
## Overview
This skill demonstrates basic script execution.
6. Running the Example
# Ensure you have skills in the ./skills directory
# The example will create a dummy skill if none exists
export OPENAI_API_KEY=your_api_key
go run main.go
Expected Output:
Loading skill: hello_world
Tool: hello, Description: Run hello.py script
User: Please use the available skill to say hello to the world.
Agent: [Agent uses the hello_world skill and returns the greeting]
7. Available Skill Tools
GoSkills provides several built-in tool types that can be used in skills:
- Script Execution:
run_python_script,run_shell_script - Code Execution:
run_python_code,run_shell_code - File Operations:
read_file,write_file - Web Search:
duckduckgo_search,wikipedia_search,tavily_search - Web Fetching:
web_fetch
8. Learn More
Documentation
¶
There is no documentation for this package.
Click to show internal directories.
Click to hide internal directories.