Skills Composition and Orchestration
A single Skill solves a single problem, while complex workflows often require multiple Skills to work together.
This article introduces how to design dependencies between Skills and orchestrate multi-Skill workflows in SKILL.md.
Composition patterns: two approaches
| Mode | Description | Applicable scenarios |
|---|---|---|
| Sequential orchestration | Skill A's output serves as Skill B's input | Data processing pipeline |
| Parallel invocation | Use multiple Skills simultaneously and merge the results | Multi-source data aggregation |
Claude can call across Skills in a single conversation, but can only "actively read" one Skill's main content at a time. Complex multi-Skill workflows are usually coordinated by an "orchestrator Skill."
Sequential orchestration example
Take "upload PDF → extract text → generate a Word summary report" as an example; three Skills work together in sequence.
---
name: pdf-to-word-report
description: >
将 PDF 文档转换为 Word 格式的摘要报告,包含文字提取、
内容分析和格式化输出三个阶段。当用户需要从 PDF 生成报告、
提取 PDF 内容并整理为 Word 文档时触发。
---
# PDF to Word summary report
## Workflow
本 Skill 协调三个处理阶段,最终生成 .docx 报告。
### 阶段一:提取 PDF 文字
Processing logic of the pdf-reading Skill (located at /mnt/skills/public/pdf-reading/):
```bash
python /mnt/skills/public/pdf-reading/scripts/extract.py \
--input \
--output /home/claude/extracted_text.txt
When done, tell the user: extracted {N} pages of content, {word_count} characters in total.
Phase 2: Generate summary content
Perform content analysis on the extracted text and generate:
- Document topic (1 sentence)
- Key chapter summaries (2-3 sentences per chapter)
- Important data and conclusions
Write the summary content to /home/claude/summary.json
Phase 3: Generate the Word report
Follow the docx Skill's specification and call:
python /mnt/skills/public/docx/scripts/generate.py \
--template /mnt/skills/public/docx/assets/report_template.docx \
--data /home/claude/summary.json \
--output /mnt/user-data/outputs/report.docx
When done, call present_files to display the download link.
---
## Implement Skill combination via script
当多个 Skill 共享脚本时,可以通过主脚本直接调用其他 Skill 的脚本,形成处理管道。
## 实例
# File path: scripts/pipeline_orchestrator.py
# Orchestrating the processing pipeline for multiple Skill scripts
import
subprocess
import
sys
import
os
import
json
SKILLS_BASE
=
"/mnt/skills/public"
def
run_script
(
script_path:
str
,
args:
list
)
-
>
dict
:
"""运行指定路径的脚本并返回 JSON 结果"""
cmd
=
[
sys
.
executable
,
script_path
]
+ args
result
=
subprocess
.
run
(
cmd
,
capture_output
=
True
,
text
=
True
,
timeout
=
120
)
if
result.
returncode
!=
0
:
return
{
"status"
:
"error"
,
"message"
: result.
stderr
}
try
:
return
json.
loads
(
result.
stdout
)
except
json.
JSONDecodeError
:
return
{
"status"
:
"success"
,
"raw_output"
: result.
stdout
}
def
run_pipeline
(
pdf_path:
str
,
output_dir:
str
)
-
>
dict
:
"""
执行完整的 PDF → Word 报告生成管道
阶段 1:PDF 文字提取
阶段 2:内容摘要生成(由 Claude 处理,此处跳过)
阶段 3:Word 文档生成
"""
os
.
makedirs
(
output_dir
,
exist_ok
=
True
)
extracted_txt
=
os
.
path
.
join
(
output_dir
,
"extracted.txt"
)
final_docx
=
os
.
path
.
join
(
output_dir
,
"report.docx"
)
# Phase 1: Extract PDF text
print
(
"阶段 1:正在提取 PDF 文字..."
)
step1
=
run_script
(
f
"{SKILLS_BASE}/pdf-reading/scripts/extract.py"
,
[
"--input"
,
pdf_path
,
"--output"
,
extracted_txt
]
)
if
step1.
get
(
"status"
)
==
"error"
:
return
{
"status"
:
"error"
,
"stage"
:
1
,
"message"
: step1
[
"message"
]
}
print
(
f
" 已提取 {step1.get('pages', '?')} 页"
)
# Phase 3: Generate Word report (summary generated by Claude before calling this script and passed in)
summary_json
=
os
.
path
.
join
(
output_dir
,
"summary.json"
)
if
not
os
.
path
.
exists
(
summary_json
)
:
return
{
"status"
:
"error"
,
"stage"
:
3
,
"message"
:
"缺少 summary.json,请先完成阶段 2"
}
print
(
"阶段 3:正在生成 Word 报告..."
)
step3
=
run_script
(
f
"{SKILLS_BASE}/docx/scripts/generate.py"
,
[
"--data"
,
summary_json
,
"--output"
,
final_docx
]
)
if
step3.
get
(
"status"
)
==
"error"
:
return
{
"status"
:
"error"
,
"stage"
:
3
,
"message"
: step3
[
"message"
]
}
return
{
"status"
:
"success"
,
"output"
: final_docx
}
if
__name__
==
"__main__"
:
pdf_path
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
>
1
else
""
output_dir
=
sys
.
argv
[
2
]
if
len
(
sys
.
argv
)
>
2
else
"/home/claude/pipeline_output"
result
=
run_pipeline
(
pdf_path
,
output_dir
)
print
(
json.
dumps
(
result
,
ensure_ascii
=
False
,
indent
=
2
)
)
---
## Avoid circular dependencies
当 Skill A 依赖 Skill B、Skill B 又依赖 Skill A 时,会形成循环依赖,导致无法执行。
设计 Skill 组合时,应保持单向依赖关系。
---
## Shared utility functions
多个 Skill 都需要的通用函数,可以提取为公共模块,避免重复实现。
## 实例
# File path: /home/claude/shared/file_utils.py
# Shared utility functions for multiple Skills
import
os
UPLOAD_DIR
=
"/mnt/user-data/uploads"
OUTPUT_DIR
=
"/mnt/user-data/outputs"
def
resolve_upload
(
filename:
str
)
-
>
str
:
"""将文件名解析为完整的上传路径"""
if
os
.
path
.
isabs
(
filename
)
:
return
filename
# Already an absolute path
return
os
.
path
.
join
(
UPLOAD_DIR
,
filename
)
def
resolve_output
(
filename:
str
)
-
>
str
:
"""将文件名解析为完整的输出路径,并确保目录存在"""
if
os
.
path
.
isabs
(
filename
)
:
path
=
filename
else
:
path
=
os
.
path
.
join
(
OUTPUT_DIR
,
filename
)
os
.
makedirs
(
os
.
path
.
dirname
(
path
)
,
exist_ok
=
True
)
return
path
# Used in each Skill script:
# import sys; sys.path.insert(0, "/home/claude/shared")
# from file_utils import resolve_upload, resolve_output