forked from maxvaega/skillkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_usage.py
More file actions
151 lines (121 loc) · 4.71 KB
/
basic_usage.py
File metadata and controls
151 lines (121 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python3
"""Basic usage example for skillkit library.
This script demonstrates standalone usage without framework integration.
Shows both sync (v0.1) and async (v0.2) patterns.
"""
import asyncio
import logging
from pathlib import Path
from skillkit import SkillManager
# Configure logging to see skill discovery and invocation
logging.basicConfig(level=logging.INFO, format="%(name)s - %(levelname)s - %(message)s")
def sync_example() -> None:
"""Demonstrate sync skill manager usage (v0.1 compatible)."""
print("=" * 60)
print("skillkit: Basic Usage Example (Sync)")
print("=" * 60)
# Use example skills from examples/skills/ directory
skills_dir = Path(__file__).parent / "skills"
print(f"\nUsing skills directory: {skills_dir}")
# Create skill manager
manager = SkillManager(skills_dir)
# Discover skills
print("\n[1] Discovering skills...")
manager.discover()
# List all skills
print("\n[2] Available skills:")
skills = manager.list_skills()
for skill in skills:
print(f" - {skill.name}: {skill.description}")
# Get specific skill metadata
print("\n[3] Getting skill metadata...")
try:
metadata = manager.get_skill("code-reviewer")
print(f" Name: {metadata.name}")
print(f" Description: {metadata.description}")
print(f" Path: {metadata.skill_path}")
print(f" Allowed tools: {metadata.allowed_tools}")
except Exception as e:
print(f" Error: {e}")
# Invoke skill with arguments
print("\n[4] Invoking skill...")
try:
result = manager.invoke_skill(
"code-reviewer", "Review the function calculate_total() in src/billing.py"
)
print(f"\nResult preview (first 300 chars):\n{'-' * 60}")
print(result[:300])
print("..." if len(result) > 300 else "")
print("-" * 60)
except Exception as e:
print(f" Error: {e}")
# Load skill for repeated invocations
print("\n[5] Loading skill for repeated use...")
try:
skill = manager.load_skill("git-helper")
print(f" Loaded: {skill.metadata.name}")
# First invocation (loads content)
result1 = skill.invoke("Generate commit message for adding authentication")
print(f" First invocation result length: {len(result1)} chars")
# Second invocation (content cached)
result2 = skill.invoke("Generate commit message for fixing bug in login")
print(f" Second invocation result length: {len(result2)} chars")
except Exception as e:
print(f" Error: {e}")
print("\n" + "=" * 60)
print("Sync example complete!")
print("=" * 60)
async def async_example() -> None:
"""Demonstrate async skill manager usage (v0.2+)."""
print("\n\n" + "=" * 60)
print("skillkit: Basic Usage Example (Async)")
print("=" * 60)
# Use example skills from examples/skills/ directory
skills_dir = Path(__file__).parent / "skills"
print(f"\nUsing skills directory: {skills_dir}")
# Create skill manager
manager = SkillManager(skills_dir)
# Async discover skills (non-blocking)
print("\n[1] Discovering skills asynchronously...")
await manager.adiscover()
# List all skills
print("\n[2] Available skills:")
skills = manager.list_skills()
for skill in skills:
print(f" - {skill.name}: {skill.description}")
# Async invoke skill with arguments
print("\n[3] Invoking skill asynchronously...")
try:
result = await manager.ainvoke_skill(
"code-reviewer", "Review the function calculate_total() in src/billing.py"
)
print(f"\nResult preview (first 300 chars):\n{'-' * 60}")
print(result[:300])
print("..." if len(result) > 300 else "")
print("-" * 60)
except Exception as e:
print(f" Error: {e}")
# Concurrent invocations (async advantage)
print("\n[4] Concurrent skill invocations...")
try:
results = await asyncio.gather(
manager.ainvoke_skill("code-reviewer", "Review auth module"),
manager.ainvoke_skill("git-helper", "Generate commit message"),
manager.ainvoke_skill("markdown-formatter", "Format README"),
)
print(f" Processed {len(results)} invocations concurrently")
for i, result in enumerate(results):
print(f" Result {i + 1} length: {len(result)} chars")
except Exception as e:
print(f" Error: {e}")
print("\n" + "=" * 60)
print("Async example complete!")
print("=" * 60)
def main() -> None:
"""Run both sync and async examples."""
# Run sync example
sync_example()
# Run async example
asyncio.run(async_example())
if __name__ == "__main__":
main()