Add session.setModel() for mid-session model switching#621
Add session.setModel() for mid-session model switching#621SteveSandersonMS merged 4 commits intomainfrom
Conversation
Allows changing the model mid-session without destroying it.
The new model takes effect for the next message while preserving
conversation history.
Node.js: session.setModel(model: string): Promise<void>
Python: session.set_model(model: str) -> None
Go: session.SetModel(ctx, model string) error
.NET: session.SetModelAsync(model, cancellationToken): Task
All send the 'session.setModel' JSON-RPC method with
{ sessionId, model } params.
Tests added for all 4 languages:
- Node.js: mocked sendRequest verifies correct RPC params (25/25 pass)
- Python: mocked request verifies sessionId + model (unit test)
- Go: JSON marshaling test for request type (pass)
- .NET: e2e test creating session, calling SetModelAsync
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a cross-language SDK API for switching the selected AI model mid-session without destroying the session, by forwarding a new session.setModel JSON-RPC call.
Changes:
- Node.js: add
CopilotSession.setModel(model)and a unit test validating the JSON-RPC request. - Python: add
CopilotSession.set_model(model)and a unit test validating request forwarding. - Go / .NET: add
SetModel/SetModelAsyncmethods plus request types and basic tests.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| python/test_client.py | Adds a unit test asserting session.setModel is sent with sessionId + model. |
| python/copilot/session.py | Adds set_model() that forwards session.setModel JSON-RPC with {sessionId, model}. |
| nodejs/test/client.test.ts | Adds a unit test verifying session.setModel RPC method/params. |
| nodejs/src/session.ts | Adds setModel() to CopilotSession that calls connection.sendRequest("session.setModel", ...). |
| go/types.go | Adds sessionSetModelRequest struct for marshaling session.setModel params. |
| go/session.go | Adds Session.SetModel() that sends session.setModel request and wraps errors. |
| go/client_test.go | Adds JSON marshaling test for sessionSetModelRequest. |
| dotnet/test/SessionTests.cs | Adds E2E test exercising SetModelAsync then sending a message afterward. |
| dotnet/src/Session.cs | Adds SetModelAsync() + SetModelRequest record and registers it for source-gen JSON serialization. |
✅ Cross-SDK Consistency ReviewI've reviewed this PR for consistency across all four SDK implementations (Node.js/TypeScript, Python, Go, and .NET). Excellent work! This PR maintains strong feature parity and follows language-specific conventions appropriately. Summary of ConsistencyAll four SDKs implement the
Consistency Highlights✅ API Signatures
✅ Documentation
✅ Error Handling
✅ Type Safety
✅ Testing Coverage
Placement ConsistencyAll SDKs place No Issues FoundThis PR successfully maintains cross-SDK consistency while respecting language-specific idioms. No changes are needed from a consistency perspective. 🎉
|
|
@copilot Can you update this to be a thin wrapper around |
dotnet/test/SessionTests.cs
Outdated
| // Session should still be usable after model change | ||
| await session.SendAsync(new MessageOptions { Prompt = "What is 1+1?" }); | ||
| var assistantMessage = await TestHelper.GetFinalAssistantMessageAsync(session); | ||
| Assert.NotNull(assistantMessage); |
There was a problem hiding this comment.
@copilot Can you find some way to make this test show the model was changed?
There was a problem hiding this comment.
Done in b91f69c. The test now subscribes for SessionModelChangeEvent before calling SetModelAsync, then asserts modelChanged.Data.NewModel == "gpt-4.1". This uses the existing TestHelper.GetNextEventOfTypeAsync infrastructure.
Note: the test will still fail if the CLI doesn't emit session.model_change in response to session.model.switchTo. The CLI-side handler is a pre-existing gap (same reason RpcTests.Should_Call_Session_Rpc_Model_SwitchTo is skipped). Without a working server-side handler, there's no way to verify the model was changed using existing test infrastructure.
…To() Co-authored-by: SteveSandersonMS <1101362+SteveSandersonMS@users.noreply.github.com>
Done in 6936cce. All four implementations now delegate to the generated RPC layer:
Also removed the now-unused Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
| } | ||
|
|
||
| return nil | ||
| } |
There was a problem hiding this comment.
Test coverage gap: The Go SDK is missing a test for SetModel(), while Node.js, Python, and .NET all have tests for this new method.
Consider adding a test in go/client_test.go (for unit testing with mocks) or go/internal/e2e/session_test.go (for E2E testing) to match the test coverage in the other SDKs.
Example pattern (based on Python/Node.js tests):
func TestSession_SetModel(t *testing.T) {
// Mock the RPC call and verify session.model.switchTo is called
// with correct sessionId and modelId parameters
}This would ensure cross-SDK test parity and prevent regressions.
AI generated by SDK Consistency Review Agent for #621
Cross-SDK Consistency Review ✅I've reviewed PR #621 for consistency across all four SDK implementations (Node.js, Python, Go, .NET). ✅ Implementation ConsistencyAll four SDKs correctly implement the new model switching feature:
✅ API Design Consistency
|
|
@copilot Fix: [xUnit.net 00:01:16.46] --- End of stack trace from previous location --- -- Run npm run lint
/Users/runner/work/copilot-sdk/copilot-sdk/nodejs/test/client.test.ts -- The Go SDK is missing a test for SetModel() while the other three SDKs all have tests: |
…skipped Go test Co-authored-by: SteveSandersonMS <1101362+SteveSandersonMS@users.noreply.github.com>
Fixed in b91f69c:
|
✅ Cross-SDK Consistency ReviewThis PR maintains excellent consistency across all four SDK implementations (Node.js, Python, Go, and .NET). SummaryThe
No consistency issues found. Great work maintaining feature parity! 🎉
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
✅ Cross-SDK Consistency Review: ExcellentThis PR adds the Consistent Implementation Across SDKsAPI Surface:
All naming follows proper language conventions (camelCase, snake_case, PascalCase) while maintaining semantic equivalence. Documentation:
Test Coverage:
Underlying RPC: SummaryThis is a textbook example of how to add a feature across a multi-language SDK repository. The implementation maintains complete feature parity while respecting each language's idioms and conventions. No consistency issues found. 🎉
|
params→_paramsin Node.js testSessionModelChangeEventcheck (no snapshot needed, shows model was changed)SetModelinrpc_test.gousing existing infrastructure💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.