# bg-model-call ## Purpose Submit a prompt to a third-party model via the agent-runtimes control plane, wait for completion, and write the result to a file — enabling the `ScheduleWakeup` polling pattern for second-opinion consultations without blocking the main Claude Code session. ## Usage ``` bg-model-call [OPTIONS] ``` ### Required flags | Flag | Description | |------|-------------| | `--model ` | Model alias: `minimax`, `sonnet`, `haiku`, `opus` | | `--prompt ` | Path to a file containing the prompt text | | `--output ` | Path where the result will be written | ### Optional flags | Flag | Default | Description | |------|---------|-------------| | `--template ` | (derived from `--model`) | Override the task template name (without `.yaml`). Takes precedence over the `--model` → template mapping. | | `--project ` | `bg-model-call` | Project ID sent to the CP, used for task grouping in agent-monitor | | `--url ` | `$CP_URL`, then `http://localhost:8100` | Control plane base URL | | `--task-name ` | `bg-model-call-` | Short task name shown in agent-monitor | | `--timeout ` | `1800` | Max seconds to wait for the task before declaring it failed | | `--poll-interval ` | `10` | Seconds between CP state polls | | `--dryrun`, `-n` | — | Resolve all values and print what would be submitted; do not call the CP or write any files | | `--help`, `-h` | — | Show usage information and exit 0 | ## Model-to-Template Mapping A constant defined at the top of the script: | Model alias | Template name | |-------------|---------------| | `minimax` | `minimax-planning` | | `sonnet` | `sonnet-code-repo` | | `haiku` | `haiku-code-repo` | | `opus` | `opus-code-repo` | The `--template` flag overrides this mapping entirely. ## Behaviour 1. Parse and validate all flags. Exit 1 with an error message if required flags are missing or values are invalid. 2. Resolve the CP URL: `--url` flag → `$CP_URL` env var → `http://localhost:8100`. 3. Resolve the template name: `--template` flag if given, otherwise look up `--model` in the mapping table. If the model alias is not in the table, exit 1. 4. Read the prompt text from the `--prompt` file. If the file is not readable, exit 1. 5. Locate the `dispatch-task` CLI: - Check if `dispatch-task` is on PATH. - Otherwise try `/../../../projects/agent-runtimes/scripts/dispatch-task` as a fallback (for dev environments). - If neither is found, fall back to direct `curl` POST to `$CP_URL/tasks`. 6. Submit the task to the CP via the resolved `dispatch-task` (or curl fallback): - `--name ` - `--project-id ` - `--prompt-file ` - `--template