Skip to content

Add dynamic per-task model selection during execution#31

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-dynamic-model-switching
Draft

Add dynamic per-task model selection during execution#31
Copilot wants to merge 2 commits intomainfrom
copilot/add-dynamic-model-switching

Conversation

Copy link
Contributor

Copilot AI commented Mar 4, 2026

Tasks execute using a single global model today. This adds per-task model overrides so cheap/fast models handle simple work while capable models are reserved for complex tasks.

Changes

Schema

  • Task.model?: string — optional per-task model ID; omit to fall back to the global model

Execution (executor.ts)

  • executeTask() passes task.model to sendPromptSync, which threads it through to session creation (model ?? currentModel)
  • New exported suggestModel(task) heuristic:
    • claude-sonnet-4 — >2 dependencies, description >200 chars, or >3 acceptance criteria
    • gpt-5-mini — everything else

Task Editor (task-editor.tsx)

  • Added Model field; free-text input, blank = global default, hint shows gpt-5-mini / claude-sonnet-4 / gpt-4.1

Execute Screen (execute.tsx)

  • Tasks with a custom model render the model ID in dimmed magenta next to the task title

sendPrompt / sendPromptSync (copilot.ts)

  • Added model?: string option; overrides currentModel at session creation—no session reuse required

Example

import { suggestModel } from './services/executor.js';

const task = createTask({
  id: 'auth',
  title: 'Implement OAuth2 flow',
  description: '...',          // long
  dependsOn: ['db', 'session', 'config'],
});

task.model = suggestModel(task); // → 'claude-sonnet-4'
Original prompt

This section details on the original issue you should resolve

<issue_title>[enhancement] Add dynamic model switching during task execution</issue_title>
<issue_description>## Background

The Copilot SDK v0.1.30 (released March 3, 2026) introduces session.setModel() for mid-session model switching, implemented by Patrick Nikoletich in commit bd98e3a.

This new API allows changing the model mid-conversation without destroying the session, preserving conversation history while taking advantage of different model capabilities.

Proposal

Implement dynamic model selection during the Execute phase to optimize cost and performance:

  1. Add model configuration to Task schema - Allow users to specify which model to use per task (e.g., gpt-4.1 for complex planning, gpt-5-mini for simple file operations)

  2. Implement model switching in executor.ts - Before dispatching each task, call session.setModel(task.model) to switch to the appropriate model for that specific task

  3. Add UI controls in Refine screen - Allow users to assign models to tasks during the refinement phase (similar to how dependencies are edited)

  4. Smart defaults - Automatically suggest models based on task complexity:

    • Complex tasks (with many dependencies, long descriptions) → gpt-4.1 or claude-sonnet-4
    • Simple tasks (single file edits, basic operations) → gpt-5-mini
    • Parallel batch optimization → use faster models for independent simple tasks

Benefit

  • Cost optimization: Use cheaper/faster models for simple tasks, reserve expensive models for complex planning
  • Performance improvement: Faster model = quicker execution for straightforward tasks
  • Flexibility: Users can fine-tune the model selection strategy for their specific workload
  • Session preservation: No need to recreate sessions when switching models, maintains conversation context

Acceptance Criteria

  • Task model in src/models/plan.ts includes optional model?: string field
  • src/services/executor.ts calls session.setModel() before dispatching tasks with custom models
  • Task editor in src/screens/refine.tsx allows selecting model from dropdown
  • Default model selection logic suggests appropriate models based on task complexity heuristics
  • Session events display model_change events in the Execute screen
  • Tests verify model switching behavior in src/services/executor.test.ts
  • Documentation in README explains model selection strategy

AI generated by Weekly Enhancement Suggestions

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: colindembovsky <1932561+colindembovsky@users.noreply.github.com>
Copilot AI changed the title [WIP] Add dynamic model switching during task execution Add dynamic per-task model selection during execution Mar 4, 2026
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.

[enhancement] Add dynamic model switching during task execution

2 participants