Skip to content

Content-agent model selection via .uf/model-matrix.yaml (model-matrix-delegation) #887

Closed

Description

@jflowers

Outcome

uf_delegate_command — the tool /uf.unleash and /uf.run-pipeline-plan use to delegate work to content agents (default cobalt-crush-dev) — must run each delegated task on the model best suited to it, selected from a configured, capability-driven matrix, instead of always replaying the parent session's model.

Done means:

  • Spec/plan/tasks authoring work ("meta-prompting") can run on a different model than code implementation, per configuration.
  • Selection is deterministic, auditable, and overridable per call.
  • A gitignored per-developer override file carries model identities; tracked config carries structure only (mirrors the review-matrix pattern).
  • Zero-config is unchanged: with no matrix present, delegation behaves exactly as today (host model).
  • The capability taxonomy ties back to UF convention packs (.opencode/uf/packs/): a new meta-prompt pack maps to spec-authoring; language packs (go, typescript, python) map to code-writing. Example stakeholder configuration: meta-prompt → glm, go → deepseek (per developer, via the override file).

Motivation (stakeholder intent): there is a large capability gap between models good at meta-prompt engineering (spec/plan/tasks/command authoring) and models good at writing code; other capability categories likely exist and must be expressible without code changes.

Background

Where selection hooks in today

  • uf_delegate_command is defined in .opencode/plugins/uf-workflow/index.ts (factory createDelegateCommandTool, ~line 1964). Current params: agent (any non-divisor- name, 1–128 chars), command_path, prompt, feature_dir, expected_artifact, checkpoint_step, phase, timeout (default 600,000 ms), task_classification (deterministic|judgment; required for prompt-only delegation), skill / skill_absent_reason (deterministic-only, mutually exclusive).
  • The child model today ALWAYS comes from resolveHostModel() (.opencode/lib/agent-executor.ts ~line 259) — parent-session introspection of the current assistant message. If that fails, delegation aborts with HOST_MODEL_UNAVAILABLE.
  • executeAgentSession (.opencode/lib/agent-executor.ts ~line 318) already accepts any ModelIdentity {providerID, modelID, combined} plus optional variant — review agents already run on non-host models via invoke_agent. Running content agents on a chosen model is mechanically supported today; only the selection layer is missing.
  • Prompt composition (deterministic order): command text → Feature directory: <dir> → skill directive (renderSkillDirective, only when a skill reference resolved) → extra prompt.
  • Signals available in-tool at selection time: command_path, checkpoint_step, phase, task_classification, agent, feature_dir, skill.
  • Delegation call sites: .opencode/commands/uf.unleash.md and .opencode/commands/uf.run-pipeline-plan.md only.
  • No pre-existing "model-matrix" references exist in .opencode/, .uf/, or internal/ — the namespace is clean.

Pattern to mirror: the review matrix

This feature deliberately mirrors the existing review-dispatch matrix trio:

  • .uf/review-matrix.yaml (v3): profiles (weight tiers with optional model+variant, 1–32 profiles), defaults per mode, always per-agent pins, runs, limits.
  • .uf/review-matrix.override.yaml: gitignored; whitelisted keys ONLY profiles.<name>.model and profiles.<name>.variant; any other key fails validation, fail-closed. Implementation precedent: validateOverride() / mergeOverride() in .opencode/plugins/review-dispatch/index.ts (~lines 1669 / 1729).
  • Schemas: .uf/schemas/review-matrix/ (README.md, samples/, vN.schema.json; closed input, additionalProperties: false).
  • Docs: docs/configuration.md (~line 274) documents the tracked/override pair.
  • Plugin code is mirrored into internal/scaffold/assets/opencode/plugins/ with drift tests enforcing byte-identity (internal/scaffold/scaffold_test.go, TestEmbeddedAssets_MatchSource).
  • Precedent OpenSpec changes to study: openspec/changes/review-council-multi-model-fanout/ (original matrix), openspec/changes/optional-profile-models/ (optional profile model → host fallback; override whitelist), openspec/changes/derive-per-run-timeout/.

Decisions already made with the stakeholder

These define the contract; do not re-litigate without cause.

Question Decision
Selection mechanism Hybrid: deterministic precedence chain by default; explicit params override
Agent scope All content agents (any non-divisor- agent)
Fallback Host model; missing matrix file = valid no-op
Config file .uf/model-matrix.yaml + gitignored .uf/model-matrix.override.yaml
Matrix shape Capability-named profiles + packs: mapping (pack → capability)
pack param Double duty: selects model AND renders a pack directive in the child prompt
Auto-derivation Classifier cascade (agent engine → LLM engine → static fallback)
Workflow tier OpenSpec tactical change, repo-first slice; hero-repo deployment deferred to slice 2

Selection precedence (contract semantics)

  1. explicit model (+variant) param
  2. explicit profile (capability) param
  3. explicit pack param (validated: pack file exists in .opencode/uf/packs/ AND has a matrix entry)
  4. agents: pin
  5. static defaults: by task kind (checkpoint_step plan/tasks → spec-authoring)
  6. classifier cascade for implement and unknown kinds: agent engine → LLM engine → static default
  7. host model (resolved profile lacks a model, or no matrix)

Side effect to preserve: when any matrix profile model resolves, host introspection is skipped entirely — delegation no longer fails on HOST_MODEL_UNAVAILABLE.

Classifier (auto-derivation)

Modeled on the auto-question plugin pattern (investigate-then-decide subagent with a JSON-only response contract, plus an LLM-engine fallback):

  • Agent engine: new hidden subagent (e.g. .opencode/agents/model-matrix-classifier.md; mode subagent, hidden, description "Internal to the model-matrix plugin"). It investigates the feature dir's spec/plan/tasks plus existing code/diff with tools, then responds with ONLY a JSON object — {"pack": "<name>", "confidence": <0.0-1.0>, "reasoning": "<optional>"} — no markdown fences, no prose, never asks questions. The child session inherits the model hierarchy (no endpoint config needed).
  • LLM engine: chat-completions POST, temperature: 0, response_format: {type: "json_object"} with a 400-retry without it (some endpoints reject the field), request timeout via AbortSignal, {env:VAR} environment interpolation for apiKey (established secrets pattern — never a literal key). Endpoint/model config lives only in the gitignored override file.
  • First valid, above-confidence-threshold, matrix-valid pack wins. Below threshold or any failure → static default. Classifier failure never blocks delegation. Cache classifier results (keyed by sha256 of feature_dir + prompt + agent, capped).
  • A classifier-selected pack also renders the pack directive (double duty).

Audit trail

The delegation success envelope and checkpoint data record selection_source (one of: explicit-model, explicit-profile, explicit-pack, agent-pin, default-kind, classifier-agent, classifier-llm, host), the selected pack/capability/model, and classifier confidence when applicable.

Recommended approach (starting point — adapt if circumstances demand)

Tracked matrix v1 shape:

version: 1
profiles:                 # capability-named model slots; model optional → host fallback
  spec-authoring: {}      #   filled per-developer by the override file
  code-writing: {}
  content-writing: {}
  mechanical: {}
packs:                    # pack name → capability (validated against .opencode/uf/packs/)
  meta-prompt: spec-authoring
  go: code-writing
  typescript: code-writing
  python: code-writing
  content: content-writing
defaults:                 # closed key set: task kind → capability
  plan: spec-authoring
  tasks: spec-authoring
  implement: code-writing
agents: {}                # per-agent capability pins
classifier:               # structure only — no model strings in tracked config
  enabled: true
  agent: model-matrix-classifier
  agent_timeout_ms: 45000
  llm: {}
  confidence_threshold: 0.6

Override whitelist (fail-closed): profiles.*.model, profiles.*.variant, classifier.llm.*. Anything else — including structural keys — fails validation with an error naming the whitelist.

Starter capability set (adjustable at spec review): spec-authoring, code-writing, content-writing, mechanical. Cross-cutting packs (severity, determinism, review-voice, default) get no matrix entries — they are never the primary capability of a task.

File map:

New: .uf/model-matrix.yaml · .uf/schemas/model-matrix/ (v1.schema.json + README + samples) · .opencode/agents/model-matrix-classifier.md · .opencode/lib/model-matrix.ts (loader, schema validation, override merge, precedence resolution, classifier engines; injectable dependencies.readText for tests, following loadPolicies) · .opencode/test/model-matrix*.test.ts · the OpenSpec change directory.

Modified: .opencode/plugins/uf-workflow/index.ts (new params, selection integration, pack directive) · internal/scaffold/assets/opencode/plugins/uf-workflow/index.ts (byte-identical mirror — drift test forces sync) · internal/scaffold/assets/opencode/lib/model-matrix.ts (mirror of the new lib module — REQUIRED: the mirrored plugin imports it; a missing mirror breaks plugin load in scaffolded hero repos) · internal/scaffold/scaffold.go (tool-owned asset enum += lib file name; gitignoreBlock += .uf/model-matrix.override.yaml) · .gitignore (+= .uf/model-matrix.override.yaml) · docs/configuration.md · CHANGELOG.md · .opencode/commands/uf.unleash.md (recommended: instruct passing pack on implement delegation when the task clearly names one; the classifier covers the rest).

Pack directive (prompt composition gains one tool-rendered section after the skill directive; golden-shape tested, never agent-reconstructed, mirroring renderSkillDirective): a short instruction to load .opencode/uf/packs/<pack>.md before writing — not the pack content inlined.

Acceptance criteria (the contract)

  1. A delegated task runs on a non-host model configured via .uf/model-matrix.yaml + override, proven by an integration test with a mocked child session.
  2. plan/tasks delegations resolve to the spec-authoring capability; implement/unknown kinds go through the classifier cascade with static fallback.
  3. Explicit model/profile/pack params override all automatic selection, in the documented precedence order.
  4. Missing .uf/model-matrix.yaml → behavior identical to today (host model, no errors).
  5. The override file accepts only whitelisted keys; anything else fails closed with a clear error naming the whitelist.
  6. The pack param renders a tool-generated pack directive in the child prompt (golden-shape test).
  7. Classifier failure, timeout, or low confidence never blocks delegation; falls back statically; the audit trail records it.
  8. Every selection records selection_source and the resolved model in the delegation envelope / checkpoint data.
  9. make check and make plugin-test pass (mirrors synced; 94% statement coverage floor held for the .opencode/ suite).
  10. docs/configuration.md documents the new config pair; a CHANGELOG entry exists.

Constraints (non-negotiable)

  • This issue is the originating issue for the OpenSpec change (originating_issue: <this issue number> in .openspec.yaml); spec artifacts are committed before implementation. Route via /uf.unleash #<N> or /opsx-propose — the OpenSpec change becomes the working contract once written.
  • Gatekeeping: no weakening of coverage floors, review limits, CI flags, or pinned dependency versions.
  • Phase boundaries: spec → implement → review; review-phase changes are fixes only.
  • CI parity: replicate CI checks locally (make check) before marking tasks complete.
  • Documentation gate: file a documentation issue for this user-facing change before PR merge.
  • Explicit staging only; never git add -A / git add ..
  • When implementation must deviate from the recommended approach above, preserve the contract semantics: precedence order, fail-closed override whitelist, host fallback, missing-matrix no-op, classifier-never-blocks, and the audit trail.

Dependencies and split work

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions