-
Notifications
You must be signed in to change notification settings - Fork 733
Expand file tree
/
Copy pathupload-managed-agent-skill.sh
More file actions
executable file
·119 lines (96 loc) · 3.61 KB
/
Copy pathupload-managed-agent-skill.sh
File metadata and controls
executable file
·119 lines (96 loc) · 3.61 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
#!/bin/bash
#
# Upload the developing-in-lightdash skill to Anthropic's Skills API.
# Run once, then set MANAGED_AGENT_SKILL_ID with the returned ID.
#
# Usage:
# ANTHROPIC_API_KEY=sk-ant-... ./scripts/upload-managed-agent-skill.sh
#
# Optionally attach to an existing agent:
# ANTHROPIC_API_KEY=sk-ant-... AGENT_ID=agent_... ./scripts/upload-managed-agent-skill.sh
#
set -euo pipefail
if [ -z "${ANTHROPIC_API_KEY:-}" ]; then
echo "Error: ANTHROPIC_API_KEY is required"
echo "Usage: ANTHROPIC_API_KEY=sk-ant-... $0"
exit 1
fi
SKILL_DIR="skills/developing-in-lightdash"
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
if [ ! -f "$REPO_ROOT/$SKILL_DIR/SKILL.md" ]; then
echo "Error: $SKILL_DIR/SKILL.md not found. Run from repo root."
exit 1
fi
cd "$REPO_ROOT"
# Check if skill already exists
echo "Checking for existing skill..."
EXISTING=$(curl -sS "https://api.anthropic.com/v1/skills?source=custom" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: skills-2025-10-02")
SKILL_ID=$(echo "$EXISTING" | jq -r '.data[] | select(.display_title == "Developing in Lightdash") | .id // empty' 2>/dev/null | head -1)
if [ -n "$SKILL_ID" ]; then
echo "Skill already exists: $SKILL_ID"
echo "To create a new version, archive the existing one first."
else
echo "Collecting skill files..."
# Build the -F arguments dynamically
CURL_ARGS=()
while IFS= read -r file; do
CURL_ARGS+=(-F "files[]=@${file};filename=${file#skills/}")
done < <(find "$SKILL_DIR" -type f -o -type l | sort)
echo "Uploading ${#CURL_ARGS[@]} files to Anthropic Skills API..."
RESPONSE=$(curl -sS -X POST "https://api.anthropic.com/v1/skills" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: skills-2025-10-02" \
-F "display_title=Developing in Lightdash" \
"${CURL_ARGS[@]}")
SKILL_ID=$(echo "$RESPONSE" | jq -r '.id // empty')
if [ -z "$SKILL_ID" ]; then
echo "Error uploading skill:"
echo "$RESPONSE" | jq .
exit 1
fi
echo "Skill uploaded!"
fi
echo ""
echo "Skill ready!"
echo " ID: $SKILL_ID"
echo ""
echo "Add to your .env:"
echo " MANAGED_AGENT_SKILL_ID=$SKILL_ID"
# Optionally attach to an agent
if [ -n "${AGENT_ID:-}" ]; then
echo ""
echo "Attaching skill to agent $AGENT_ID..."
# Get current agent version
AGENT_RESPONSE=$(curl -sS "https://api.anthropic.com/v1/agents/$AGENT_ID" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: managed-agents-2026-04-01")
AGENT_VERSION=$(echo "$AGENT_RESPONSE" | jq -r '.version // empty')
if [ -z "$AGENT_VERSION" ]; then
echo "Error: Could not get agent version"
echo "$AGENT_RESPONSE" | jq .
exit 1
fi
UPDATE_RESPONSE=$(curl -sS -X PATCH "https://api.anthropic.com/v1/agents/$AGENT_ID" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: managed-agents-2026-04-01" \
-H "content-type: application/json" \
-d "{
\"version\": $AGENT_VERSION,
\"skills\": [
{\"type\": \"custom\", \"skill_id\": \"$SKILL_ID\", \"version\": \"latest\"}
]
}")
NEW_VERSION=$(echo "$UPDATE_RESPONSE" | jq -r '.version // empty')
if [ -z "$NEW_VERSION" ]; then
echo "Error attaching skill to agent:"
echo "$UPDATE_RESPONSE" | jq .
exit 1
fi
echo "Skill attached to agent $AGENT_ID (version $AGENT_VERSION -> $NEW_VERSION)"
fi