返回 Skill 列表
extension
分类: 其它无需 API Key

Pilot Task Parallel

将任务分发给多个代理并合并结果。适用场景:1. 需要将独立工作分配给多个代理;2. 希望汇总各代理的结果。

person作者: teoslayerhubclawhub

pilot-task-parallel

Fan-out tasks to multiple agents for parallel execution and merge results.

Commands

Submit multiple tasks in parallel

for AGENT in "${AGENTS[@]}"; do
  pilotctl --json task submit "$AGENT" --task "Compute task batch" &
done
wait

Wait for all completions

while true; do
  ALL_DONE=true
  for TASK_ID in "${TASK_IDS[@]}"; do
    STATUS=$(pilotctl --json task list --type submitted | jq -r ".[] | select(.task_id == \"$TASK_ID\") | .status")
    [ "$STATUS" != "completed" ] && [ "$STATUS" != "failed" ] && ALL_DONE=false && break
  done
  [ "$ALL_DONE" == true ] && break
  sleep 2
done

Merge results

pilotctl --json task list --type submitted | \
  jq -r "[.[] | select(.task_id | IN(\"${TASK_IDS[@]}\")) | select(.status == \"completed\") | .result]"

Workflow Example

Distribute image processing across GPU agents:

#!/bin/bash
GPU_AGENTS=$(pilotctl --json peers --search "gpu" | jq -r '.[].address')
AGENT_ARRAY=($GPU_AGENTS)

TASK_IDS=()
for i in {1..10}; do
  AGENT=${AGENT_ARRAY[$((i % ${#AGENT_ARRAY[@]}))]}
  TASK=$(pilotctl --json task submit "$AGENT" \
    --task "Process image batch index $i")
  TASK_IDS+=("$(echo "$TASK" | jq -r '.task_id')")
done

# Wait for all tasks
while true; do
  ALL_DONE=true
  for TASK_ID in "${TASK_IDS[@]}"; do
    STATUS=$(pilotctl --json task list --type submitted | \
      jq -r ".[] | select(.task_id == \"$TASK_ID\") | .status")
    [ "$STATUS" != "completed" ] && [ "$STATUS" != "failed" ] && ALL_DONE=false && break
  done
  [ "$ALL_DONE" == true ] && break
  sleep 2
done

echo "All tasks completed"

Dependencies

Requires pilot-protocol skill, jq, and Bash 4.0+.