Skip to content

feat(sdk,cli): thread contextTier through agent spawning pipeline - #1448

Merged
tamirdresher merged 2 commits into
devfrom
tamirdresher-microsoft-squad-1446-context-tier
Jul 5, 2026
Merged

feat(sdk,cli): thread contextTier through agent spawning pipeline#1448
tamirdresher merged 2 commits into
devfrom
tamirdresher-microsoft-squad-1446-context-tier

Conversation

@tamirdresher

Copy link
Copy Markdown
Collaborator

Summary

Threads a context tier (context-window) concept end-to-end through the Squad SDK + CLI, exactly mirroring the existing reasoningEffort plumbing (blueprint: merged PR #1148). The Copilot runtime exposes a per-spawn context_tier: "default" | "long_context" param — e.g. Opus 4.8 → 264K (default) vs 1M (long_context) — but Squad previously had no way to select it. Now it does, at both the model-default and per-agent-override levels.

Closes #1446

Adapter → runtime boundary (the CRITICAL FIRST STEP)

Verified packages/squad-sdk/src/adapter/client.ts before writing the spawn layer. createSession forwards the entire normalized SquadSessionConfig to the runtime via wholesale passthrough — so contextTier reaches the runtime automatically once it's a field on the config type. No client.ts spawn-mapping edit was required (this mirrors how reasoningEffort already flows). The only client.ts change is in listModels, where each model now advertises supportedContextTiers / defaultContextTier, inferred from billing.tokenPrices.longContext.

What changed (mirrors #1148 layering)

  • Types (adapter/types.ts): SquadContextTier = "default" | "long_context"; SquadSessionConfig.contextTier?; per-model supportedContextTiers? / defaultContextTier?.
  • Model catalog + resolvers (config/models.ts): defaultContextTier / agentContextTierOverrides config, VALID_CONTEXT_TIERS, and read/write/resolve/clamp helpers mirroring the effort resolvers. Unsupported tier clamps to the model default; unknown/unset treated as default.
  • Config schema (config/schema.ts): ModelConfig.defaultContextTier + agentContextTierOverrides; AgentConfig.contextTier.
  • Charter compiler (agents/charter-compiler.ts): parses ## Model**Context Tier:**.
  • Spawn pipeline (agents/lifecycle.ts, coordinator/fan-out.ts, coordinator/spawn-backend.ts): threads contextTier through spawn. Task backend uses camelCase contextTier; session-kickoff backend uses snake_case context_tier (the runtime param name).
  • Builders (builders/types.ts, builders/index.ts): contextTier on defaults + agent definitions, validated against VALID_CONTEXT_TIERS.
  • CLI (cli/commands/config.ts): squad config context-tier [<tier>] [--agent <name>] [--clear], parallel to squad config model.
  • Tests (test/model-preference.test.ts): new contextTier describe blocks. All 101 tests pass.
  • Changeset (.changeset/context-tier.md): @bradygaster/squad-sdk minor + @bradygaster/squad-cli minor.

Design notes

  • Context tier is a 2-value enum with fallback, not a ranked scale — so there is deliberately no EFFORT_RANK analog.
  • auto is a Squad-only stored sentinel meaning "not set" (write helpers accept it; resolveContextTier rejects it and falls through to the model/default). It is not part of the public SquadContextTier union.
  • Charter .md templates were not given a new session-param bullet, staying faithful to feat(sdk): thread reasoningEffort through agent spawning pipeline #1148 (which also left charters untouched). The compiler still honors a manually-added **Context Tier:** line.

⚠️ Coordinator-behavior change — maintainers must restart their session

This PR edits .github/agents/squad.agent.md (and the 4 mirrored templates) to add a ### Per-Agent Context Tier section analogous to the reasoning-effort guidance. Because squad.agent.md is the coordinator's own instruction file, any session running before this merges is on stale coordinator instructions — restart your Squad session after merge to pick up the new context-tier routing behavior.

Relationship to PR #1444

Orthogonal in concept (that PR refreshes the model-ID catalog / prunes dead fallback chains; this PR adds contextTier plumbing). There is minor file overlap in config/models.ts and config/schema.ts, but in disjoint regions, so conflict risk is low — whoever merges second should rebase. They're actually synergistic: #1444 adds claude-opus-4.8, which is the model that best demonstrates this feature (264K vs 1M).

Verification

  • npm run build -w packages/squad-sdk
  • npm run build -w packages/squad-cli
  • npx vitest run test/model-preference.test.ts101 passed

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

Adds a contextTier concept (default vs long_context / 1M context window)
threaded end-to-end through the SDK and CLI, mirroring the reasoningEffort
plumbing from #1148. Models expose supportedContextTiers/defaultContextTier;
requests validate and clamp against what a model supports. Adds the
'squad config context-tier' CLI subcommand and coordinator guidance.

Closes #1446

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tamirdresher
tamirdresher requested a review from bradygaster as a code owner July 5, 2026 11:13
Copilot AI review requested due to automatic review settings July 5, 2026 11:13
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

🛫 PR Readiness Check

ℹ️ This comment updates on each push. Last checked: commit 2bc2472

PR Scope: 📦🔧 Mixed (product + infrastructure)

⚠️ 3 item(s) to address before review

Status Check Details
Single commit 2 commits — consider squashing before review
Not in draft Ready for review
Branch up to date Up to date with dev
Copilot review No Copilot review yet — it may still be processing
Changeset present Changeset file found
Scope clean No .squad/ or docs/proposals/ files
No merge conflicts No merge conflicts
Copilot threads resolved 0 active Copilot thread(s) resolved (1 outdated skipped)
CI passing 1 check(s) failing: test

Files Changed (19 files, +1041 −9)

File +/−
.changeset/context-tier.md +15 −0
.github/agents/squad.agent.md +27 −0
.squad-templates/squad.agent.md +27 −0
packages/squad-cli/src/cli/commands/config.ts +99 −0
packages/squad-cli/templates/squad.agent.md.template +27 −0
packages/squad-sdk/src/adapter/client.ts +8 −0
packages/squad-sdk/src/adapter/types.ts +39 −0
packages/squad-sdk/src/agents/charter-compiler.ts +32 −1
packages/squad-sdk/src/agents/index.ts +5 −0
packages/squad-sdk/src/agents/lifecycle.ts +15 −2
packages/squad-sdk/src/builders/index.ts +7 −1
packages/squad-sdk/src/builders/types.ts +7 −1
packages/squad-sdk/src/config/models.ts +304 −1
packages/squad-sdk/src/config/schema.ts +3 −0
packages/squad-sdk/src/coordinator/fan-out.ts +20 −3
packages/squad-sdk/src/coordinator/spawn-backend.ts +4 −0
packages/squad-sdk/templates/squad.agent.md.template +27 −0
templates/squad.agent.md.template +27 −0
test/model-preference.test.ts +348 −0

Total: +1041 −9


This check runs automatically on every push. Fix any ❌ items and push again.
See CONTRIBUTING.md and PR Requirements for details.

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

🟠 Impact Analysis — PR #1448

Risk tier: 🟠 HIGH

📊 Summary

Metric Count
Files changed 19
Files added 1
Files modified 18
Files deleted 0
Modules touched 6
Critical files 2

🎯 Risk Factors

  • 19 files changed (6-20 → MEDIUM)
  • 6 modules touched (5-8 → HIGH)
  • Critical files touched: packages/squad-sdk/src/agents/index.ts, packages/squad-sdk/src/builders/index.ts

📦 Modules Affected

ci-workflows (1 file)
  • .github/agents/squad.agent.md
root (2 files)
  • .changeset/context-tier.md
  • templates/squad.agent.md.template
squad-cli (2 files)
  • packages/squad-cli/src/cli/commands/config.ts
  • packages/squad-cli/templates/squad.agent.md.template
squad-sdk (12 files)
  • packages/squad-sdk/src/adapter/client.ts
  • packages/squad-sdk/src/adapter/types.ts
  • packages/squad-sdk/src/agents/charter-compiler.ts
  • packages/squad-sdk/src/agents/index.ts
  • packages/squad-sdk/src/agents/lifecycle.ts
  • packages/squad-sdk/src/builders/index.ts
  • packages/squad-sdk/src/builders/types.ts
  • packages/squad-sdk/src/config/models.ts
  • packages/squad-sdk/src/config/schema.ts
  • packages/squad-sdk/src/coordinator/fan-out.ts
  • packages/squad-sdk/src/coordinator/spawn-backend.ts
  • packages/squad-sdk/templates/squad.agent.md.template
templates (1 file)
  • .squad-templates/squad.agent.md
tests (1 file)
  • test/model-preference.test.ts

⚠️ Critical Files

  • packages/squad-sdk/src/agents/index.ts
  • packages/squad-sdk/src/builders/index.ts

This report is generated automatically for every PR. See #733 for details.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Threads a new context tier (context window size) selection through Squad’s SDK + CLI, mirroring the existing reasoningEffort plumbing so callers can choose between "default" and "long_context" at the model-default and per-agent levels.

Changes:

  • Adds SquadContextTier + SquadSessionConfig.contextTier, and surfaces per-model supportedContextTiers / defaultContextTier (inferred from billing).
  • Threads contextTier through charter parsing/compilation, builders, lifecycle spawning, coordinator fan-out, and spawn backends (including runtime context_tier mapping where required).
  • Adds squad config context-tier ... CLI support, expands tests, and ships a changeset for SDK + CLI.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/model-preference.test.ts Adds coverage for reading/writing/resolving/clamping context tier preferences.
templates/squad.agent.md.template Documents per-agent context tier behavior for the coordinator template.
packages/squad-sdk/templates/squad.agent.md.template Mirrors coordinator guidance into SDK templates.
packages/squad-cli/templates/squad.agent.md.template Mirrors coordinator guidance into CLI templates.
.squad-templates/squad.agent.md Updates the source template with context-tier guidance.
.github/agents/squad.agent.md Updates the coordinator agent instructions with context-tier guidance.
packages/squad-sdk/src/coordinator/spawn-backend.ts Passes contextTier through task and session spawn backends (incl. context_tier).
packages/squad-sdk/src/coordinator/fan-out.ts Threads and validates contextTierOverride through fan-out spawn config.
packages/squad-sdk/src/config/schema.ts Extends config schema types with context tier defaults and per-agent overrides.
packages/squad-sdk/src/config/models.ts Adds VALID_CONTEXT_TIERS plus read/write/resolve/clamp helpers for context tier.
packages/squad-sdk/src/builders/types.ts Adds contextTier to defaults and agent definitions.
packages/squad-sdk/src/builders/index.ts Validates contextTier in defineAgent() / defineDefaults().
packages/squad-sdk/src/agents/lifecycle.ts Threads contextTierOverride into session config for lifecycle-managed spawns.
packages/squad-sdk/src/agents/index.ts Extends AgentCharter and compiler output to include contextTier.
packages/squad-sdk/src/agents/charter-compiler.ts Parses **Context Tier:** and compiles/resolves a context tier preference.
packages/squad-sdk/src/adapter/types.ts Adds the SquadContextTier type and session/model fields for context-tier support.
packages/squad-sdk/src/adapter/client.ts Infers supportedContextTiers from billing token pricing and sets defaultContextTier.
packages/squad-cli/src/cli/commands/config.ts Implements squad config context-tier subcommand (show/set/clear default + per-agent).
.changeset/context-tier.md Declares minor bumps for @bradygaster/squad-sdk and @bradygaster/squad-cli.

Comment thread packages/squad-sdk/src/config/models.ts Outdated
Comment on lines +1106 to +1110
requested: string | undefined,
supportedTiers: string[] | undefined,
modelDefault?: string,
): string | undefined {
if (requested === undefined || requested === null || requested === '') return undefined;
…rt (addresses PR review)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tamirdresher
tamirdresher merged commit f682ecb into dev Jul 5, 2026
13 of 14 checks passed
@tamirdresher

Copy link
Copy Markdown
Collaborator Author

Hey @bradygaster — this merged to dev (squash f682ecb), but you were the requested reviewer so I'd value your post-merge eyes.

What shipped: per-agent context tier selection (default vs long_context/1M window), threaded through SDK + CLI exactly like the existing reasoningEffort pipeline. New squad config context-tier command (show / set default / --agent pin / --clear), charter **Context Tier:** line support, and dynamic per-model tier inference from billing.tokenPrices.longContext (no static catalog dependency).

E2E-certified: 101/101 preference tests pass; full 11-item matrix verified with real CLI/SDK output across 17 live models. PRODUCTION-SOLID.

One honest caveat: squad-wide defaultContextTier is persistence-only in production today — written/shown/validated/clamped and honored by the layered resolver in tests, but the production fan-out path collapses to charter.contextTier because deps.resolveContextTier isn't injected in-repo. This is an exact mirror of the current reasoningEffort behavior, so it's working-as-designed, not a regression. Charter line + per-agent CLI override both thread correctly.

Optional one-liner if you want the squad-wide default to thread into real spawns: coordinator.buildSpawnConfigscontextTierOverride: perAgentTier ?? defaultContextTier (reasoningEffort would need the identical change to stay consistent). Happy to open a follow-up. Would love your feedback on the approach. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(sdk): expose context-window / context-tier selection (default vs long-context/1M) in config, charter, and spawn pipeline

3 participants