Skip to content

Replace Literal model type with string in Python SessionConfig#325

Merged
friggeri merged 2 commits intomainfrom
copilot/update-sessionconfig-model-validation
Feb 2, 2026
Merged

Replace Literal model type with string in Python SessionConfig#325
friggeri merged 2 commits intomainfrom
copilot/update-sessionconfig-model-validation

Conversation

Copy link
Contributor

Copilot AI commented Feb 2, 2026

Python SDK's SessionConfig.model used a hardcoded Literal type that becomes stale as model availability changes. Node.js SDK uses string with runtime validation by the CLI server.

Changes

  • python/copilot/types.py: Changed model field from Literal["gpt-5", "claude-sonnet-4", "claude-sonnet-4.5", "claude-haiku-4.5"] to str
  • Added inline documentation pointing users to list_models() for discovering available models

Impact

# Before: Only specific models allowed by type system
config: SessionConfig = {"model": "gpt-5"}  # OK
config: SessionConfig = {"model": "gpt-4"}  # Type error

# After: Any string accepted, validated at runtime by CLI
config: SessionConfig = {"model": "gpt-5"}   # OK
config: SessionConfig = {"model": "gpt-4"}   # OK
config: SessionConfig = {"model": "new-model"}  # OK

Aligns Python SDK with Node.js SDK's flexible approach. Model validation occurs at session creation time by the CLI server.

Original prompt

SessionConfig in python has model: Literal["gpt-5", "claude-sonnet-4", "claude-sonnet-4.5", "claude-haiku-4.5"] but that's not the right approach, this field should be an optional string, and then we should do runtime validation based on listModels, similar to how the nodejs sdk does it.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: friggeri <106686+friggeri@users.noreply.github.com>
Copilot AI changed the title [WIP] Update SessionConfig model field to optional string with validation Replace Literal model type with string in Python SessionConfig Feb 2, 2026
Copilot AI requested a review from friggeri February 2, 2026 17:35
@friggeri friggeri marked this pull request as ready for review February 2, 2026 19:50
@friggeri friggeri requested a review from a team as a code owner February 2, 2026 19:50
Copilot AI review requested due to automatic review settings February 2, 2026 19:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Python SDK's SessionConfig.model type to match the Node.js SDK's flexible approach, allowing any string value instead of hardcoded model names that quickly become stale.

Changes:

  • Changed model field type from Literal with specific model names to str
  • Added inline documentation directing users to list_models() for discovering available models

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@friggeri friggeri enabled auto-merge February 2, 2026 20:21
@friggeri friggeri disabled auto-merge February 2, 2026 20:25
@friggeri friggeri merged commit 258ce73 into main Feb 2, 2026
16 of 21 checks passed
@friggeri friggeri deleted the copilot/update-sessionconfig-model-validation branch February 2, 2026 20:25
@stomde
Copy link

stomde commented Feb 2, 2026

Great 😁😁 okay

@stomde
Copy link

stomde commented Feb 2, 2026

Shitty coins

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.

3 participants