Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions dotnet/src/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -663,15 +663,25 @@ await InvokeRpcAsync<object>(
/// The new model takes effect for the next message. Conversation history is preserved.
/// </summary>
/// <param name="model">Model ID to switch to (e.g., "gpt-4.1").</param>
/// <param name="reasoningEffort">Reasoning effort level (e.g., "low", "medium", "high", "xhigh").</param>
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <example>
/// <code>
/// await session.SetModelAsync("gpt-4.1");
/// await session.SetModelAsync("claude-sonnet-4.6", SessionModelSwitchToRequestReasoningEffort.High);
/// </code>
/// </example>
public async Task SetModelAsync(string model, CancellationToken cancellationToken = default)
public async Task SetModelAsync(string model, SessionModelSwitchToRequestReasoningEffort? reasoningEffort, CancellationToken cancellationToken = default)
{
await Rpc.Model.SwitchToAsync(model, cancellationToken: cancellationToken);
await Rpc.Model.SwitchToAsync(model, reasoningEffort, cancellationToken);
}

/// <summary>
/// Changes the model for this session.
/// </summary>
public Task SetModelAsync(string model, CancellationToken cancellationToken = default)
{
return SetModelAsync(model, reasoningEffort: null, cancellationToken);
}

/// <summary>
Expand Down
18 changes: 16 additions & 2 deletions go/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,12 @@ func (s *Session) Abort(ctx context.Context) error {
return nil
}

// SetModelOptions configures optional parameters for SetModel.
type SetModelOptions struct {
// ReasoningEffort sets the reasoning effort level for the new model (e.g., "low", "medium", "high", "xhigh").
ReasoningEffort rpc.ReasoningEffort
}

// SetModel changes the model for this session.
// The new model takes effect for the next message. Conversation history is preserved.
//
Expand All @@ -693,8 +699,16 @@ func (s *Session) Abort(ctx context.Context) error {
// if err := session.SetModel(context.Background(), "gpt-4.1"); err != nil {
// log.Printf("Failed to set model: %v", err)
// }
func (s *Session) SetModel(ctx context.Context, model string) error {
_, err := s.RPC.Model.SwitchTo(ctx, &rpc.SessionModelSwitchToParams{ModelID: model})
// if err := session.SetModel(context.Background(), "claude-sonnet-4.6", SetModelOptions{ReasoningEffort: "high"}); err != nil {
// log.Printf("Failed to set model: %v", err)
// }
func (s *Session) SetModel(ctx context.Context, model string, opts ...SetModelOptions) error {
params := &rpc.SessionModelSwitchToParams{ModelID: model}
if len(opts) > 0 && opts[0].ReasoningEffort != "" {
re := opts[0].ReasoningEffort
params.ReasoningEffort = &re
}
_, err := s.RPC.Model.SwitchTo(ctx, params)
if err != nil {
return fmt.Errorf("failed to set model: %w", err)
}
Expand Down
10 changes: 8 additions & 2 deletions nodejs/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
PermissionHandler,
PermissionRequest,
PermissionRequestResult,
ReasoningEffort,
SessionEvent,
SessionEventHandler,
SessionEventPayload,
Expand Down Expand Up @@ -684,14 +685,19 @@ export class CopilotSession {
* The new model takes effect for the next message. Conversation history is preserved.
*
* @param model - Model ID to switch to
* @param options - Optional settings for the new model
*
* @example
* ```typescript
* await session.setModel("gpt-4.1");
* await session.setModel("claude-sonnet-4.6", { reasoningEffort: "high" });
* ```
*/
async setModel(model: string): Promise<void> {
await this.rpc.model.switchTo({ modelId: model });
async setModel(
model: string,
options?: { reasoningEffort?: ReasoningEffort }
): Promise<void> {
await this.rpc.model.switchTo({ modelId: model, ...options });
}

/**
Expand Down
25 changes: 25 additions & 0 deletions nodejs/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,31 @@ describe("CopilotClient", () => {
spy.mockRestore();
});

it("sends reasoningEffort with session.model.switchTo when provided", async () => {
const client = new CopilotClient();
await client.start();
onTestFinished(() => client.forceStop());

const session = await client.createSession({ onPermissionRequest: approveAll });

const spy = vi
.spyOn((client as any).connection!, "sendRequest")
.mockImplementation(async (method: string, _params: any) => {
if (method === "session.model.switchTo") return {};
throw new Error(`Unexpected method: ${method}`);
});

await session.setModel("claude-sonnet-4.6", { reasoningEffort: "high" });

expect(spy).toHaveBeenCalledWith("session.model.switchTo", {
sessionId: session.sessionId,
modelId: "claude-sonnet-4.6",
reasoningEffort: "high",
});

spy.mockRestore();
});

describe("URL parsing", () => {
it("should parse port-only URL format", () => {
const client = new CopilotClient({
Expand Down
12 changes: 10 additions & 2 deletions python/copilot/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ async def abort(self) -> None:
"""
await self._client.request("session.abort", {"sessionId": self.session_id})

async def set_model(self, model: str) -> None:
async def set_model(self, model: str, *, reasoning_effort: str | None = None) -> None:
"""
Change the model for this session.

Expand All @@ -727,14 +727,22 @@ async def set_model(self, model: str) -> None:

Args:
model: Model ID to switch to (e.g., "gpt-4.1", "claude-sonnet-4").
reasoning_effort: Optional reasoning effort level for the new model
(e.g., "low", "medium", "high", "xhigh").

Raises:
Exception: If the session has been destroyed or the connection fails.

Example:
>>> await session.set_model("gpt-4.1")
>>> await session.set_model("claude-sonnet-4.6", reasoning_effort="high")
"""
await self.rpc.model.switch_to(SessionModelSwitchToParams(model_id=model))
await self.rpc.model.switch_to(
SessionModelSwitchToParams(
model_id=model,
reasoning_effort=reasoning_effort,
)
)

async def log(
self,
Expand Down
Loading