50 lines
2.0 KiB
Bash
Executable File
50 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# args_json: {"type":"object","required":["prompt"],"properties":{"prompt":{"type":"string","description":"Task prompt for the subagent"},"name":{"type":"string","description":"Subagent display name (optional)"},"profile":{"type":"string","description":"Agent profile (optional, default: default)"},"backend":{"type":"string","description":"Backend (optional)"},"model":{"type":"string","description":"Model (optional)"},"cwd":{"type":"string","description":"Working directory (optional, default: current)"},"parent":{"type":"string","description":"Parent agent ID (internal, auto-filled)"}}}
|
|
# ollie:prompt
|
|
# ## subagent_spawn
|
|
#
|
|
# Spawn a sub-agent with a task. Blocks until the sub-agent completes and returns its reply.
|
|
# The sub-agent gets its own context window and tool access. It is destroyed when done.
|
|
#
|
|
# ```
|
|
# subagent_spawn(prompt="fix the failing tests in auth/")
|
|
# subagent_spawn(prompt="implement the login page", cwd="$PWD", model="sonnet")
|
|
# ```
|
|
#
|
|
# Multiple subagent_spawn calls in the same turn run in parallel automatically.
|
|
# ollie:end
|
|
# ollie:scope read
|
|
# ollie:tier hot
|
|
set -euo pipefail
|
|
|
|
source "$(dirname "$0")/_lib/args.sh"
|
|
|
|
prompt_text=$(arg_require "prompt")
|
|
name=$(arg_get "name" "")
|
|
profile=$(arg_get "profile" "default")
|
|
backend=$(arg_get "backend" "")
|
|
model=$(arg_get "model" "")
|
|
cwd=$(arg_get "cwd" "$(pwd)")
|
|
parent=$(arg_get "parent" "${OLLIE_UNAME:-}")
|
|
|
|
# Escape newlines in prompt for the key=value wire format.
|
|
escaped_prompt=$(printf '%s' "$prompt_text" | sed 's/\\/\\\\/g; s/$/\\n/' | tr -d '\n' | sed 's/\\n$//')
|
|
|
|
# Build the payload.
|
|
payload="cwd=${cwd}
|
|
profile=${profile}
|
|
timeout=600
|
|
prompt=${escaped_prompt}"
|
|
|
|
[ -n "$parent" ] && payload="${payload}
|
|
parent=${parent}"
|
|
[ -n "$name" ] && payload="${payload}
|
|
name=${name}"
|
|
[ -n "$backend" ] && payload="${payload}
|
|
backend=${backend}"
|
|
[ -n "$model" ] && payload="${payload}
|
|
model=${model}"
|
|
|
|
# rdwr to agent/new: blocks until sub-agent completes, returns reply.
|
|
printf '%s\n' "$payload" | ollie-9p rdwr "session/${OLLIE_SESSION_ID}/agent/new"
|