Loading...
Loading...
Use when generating 50+ structured items with parallel Claude Code subagents and merging outputs into one file.
npx skill4agent add shimo4228/claude-code-learned-skills parallel-subagent-batch-merge{ "id": { ...data } }[{ "id": "...", "data": {...} }][{ "questionId": "...", "data": {...} }]:=relatedConceptsstringarray# prepare_batches.py: 入力データを N 件ずつのテキストファイルに分割
# → 各サブエージェントが1ファイルだけ読めばよい
batches = [items[i:i+BATCH_SIZE] for i in range(0, len(items), BATCH_SIZE)]run_in_background=true# 21バッチ × Sonnet subagent を同時起動
for batch in 1..21:
Task(subagent_type="general-purpose", model="sonnet",
run_in_background=true, prompt=f"Read batch_{batch}.txt ...")batch_XX_output.jsondef normalize_batch(batch_data):
"""辞書型・リスト型どちらでも { id: data } に正規化"""
if isinstance(batch_data, dict):
return batch_data
elif isinstance(batch_data, list):
result = {}
for item in batch_data:
qid = item.get("id") or item.get("questionId")
data = item.get("enhancedExplanation", item)
result[qid] = data
return result# relatedConcepts: String? なのに array で返ってきた場合
if isinstance(val, list):
val = "".join(val) if val else Noneraw = raw.replace(':="', ': "') # := → : のタイポ修正# contrastTable の point 重複チェック
points = [e["point"] for e in contrast_table]
if len(set(points)) < len(points):
# → 手動で固有テキストに差し替え| 項目 | 数値 |
|---|---|
| 対象データ | 408問 |
| バッチ数 | 21(20問×20 + 8問×1) |
| 並列エージェント | 21(全同時起動) |
| フォーマット種類 | 3種(辞書14 / リスト+id 2 / リスト+questionId 5) |
| 構文エラー | 1件(batch_21: |
| 型の揺れ | 8件(batch_21: relatedConcepts が配列) |
| コンテンツ重複 | 7問(contrastTable point 重複) |
| 最終結果 | 全408問マージ成功、検証 ALL GREEN |
claude-code-self-generation-over-api.mdchoicechoiceLabeloptionkey_sets = set()
for item in data['items']:
for entry in item.get('nested', []):
key_sets.add(tuple(sorted(entry.keys())))
print(f'Unique key patterns: {len(key_sets)}')
for ks in sorted(key_sets):
print(f' {ks}')for entry in item.get('nested', []):
normalized = {}
normalized['choice'] = entry.get('choice') or entry.get('choiceLabel') or entry.get('option', '')
normalized['point'] = entry.get('point') or entry.get('reason', '')
# ...bad = [(item['id'], set(e.keys()))
for item in data['items']
for e in item.get('nested', [])
if set(e.keys()) != EXPECTED_KEYS]
assert not bad, f'Still inconsistent: {bad}'validate