Skip to content

Commit 63a79ba

Browse files
committed
Expose context tier in SDK set model APIs
1 parent 13abec9 commit 63a79ba

26 files changed

Lines changed: 260 additions & 250 deletions

File tree

dotnet/src/Generated/Rpc.cs

Lines changed: 5 additions & 129 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dotnet/src/Session.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,14 +1576,40 @@ public async Task AbortAsync(CancellationToken cancellationToken = default)
15761576
/// <code>
15771577
/// await session.SetModelAsync("gpt-4.1");
15781578
/// await session.SetModelAsync("claude-sonnet-4.6", "high");
1579+
/// await session.SetModelAsync("gpt-4.1", new SetModelOptions { ContextTier = ContextTier.LongContext });
15791580
/// </code>
15801581
/// </example>
1581-
public async Task SetModelAsync(string model, string? reasoningEffort, ModelCapabilitiesOverride? modelCapabilities = null, CancellationToken cancellationToken = default)
1582+
public Task SetModelAsync(string model, string? reasoningEffort, ModelCapabilitiesOverride? modelCapabilities = null, CancellationToken cancellationToken = default)
1583+
{
1584+
return SetModelAsync(
1585+
model,
1586+
new SetModelOptions
1587+
{
1588+
ReasoningEffort = reasoningEffort,
1589+
ModelCapabilities = modelCapabilities,
1590+
},
1591+
cancellationToken);
1592+
}
1593+
1594+
/// <summary>
1595+
/// Changes the model for this session.
1596+
/// The new model takes effect for the next message. Conversation history is preserved.
1597+
/// </summary>
1598+
/// <param name="model">Model ID to switch to (e.g., "gpt-4.1").</param>
1599+
/// <param name="options">Settings for the new model.</param>
1600+
/// <param name="cancellationToken">Optional cancellation token.</param>
1601+
public async Task SetModelAsync(string model, SetModelOptions options, CancellationToken cancellationToken = default)
15821602
{
15831603
ArgumentNullException.ThrowIfNull(model);
15841604
ThrowIfDisposed();
15851605

1586-
await Rpc.Model.SwitchToAsync(model, reasoningEffort, reasoningSummary: null, modelCapabilities: modelCapabilities, cancellationToken: cancellationToken);
1606+
await Rpc.Model.SwitchToAsync(
1607+
model,
1608+
options.ReasoningEffort,
1609+
options.ReasoningSummary,
1610+
options.ModelCapabilities,
1611+
options.ContextTier,
1612+
cancellationToken);
15871613
}
15881614

15891615
/// <summary>
@@ -1593,7 +1619,7 @@ public Task SetModelAsync(string model, CancellationToken cancellationToken = de
15931619
{
15941620
ThrowIfDisposed();
15951621

1596-
return SetModelAsync(model, reasoningEffort: null, modelCapabilities: null, cancellationToken);
1622+
return SetModelAsync(model, new SetModelOptions(), cancellationToken);
15971623
}
15981624

15991625
/// <summary>

dotnet/src/Types.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,6 +2449,33 @@ public override void Write(Utf8JsonWriter writer, ContextTier value, JsonSeriali
24492449
}
24502450
}
24512451

2452+
/// <summary>
2453+
/// Optional settings for <see cref="CopilotSession.SetModelAsync(string, SetModelOptions, CancellationToken)"/>.
2454+
/// </summary>
2455+
public struct SetModelOptions
2456+
{
2457+
/// <summary>
2458+
/// Reasoning effort level for the new model.
2459+
/// </summary>
2460+
public string? ReasoningEffort { get; set; }
2461+
2462+
/// <summary>
2463+
/// Reasoning summary mode for models that support configurable reasoning summaries.
2464+
/// </summary>
2465+
/// <remarks>
2466+
/// Use <see cref="ReasoningSummary.None"/> to suppress summary output regardless of whether reasoning is enabled.
2467+
/// </remarks>
2468+
public ReasoningSummary? ReasoningSummary { get; set; }
2469+
2470+
/// <summary>
2471+
/// Context window tier for models that support it.
2472+
/// </summary>
2473+
public ContextTier? ContextTier { get; set; }
2474+
2475+
/// <summary>Per-property overrides for model capabilities, deep-merged over runtime defaults.</summary>
2476+
public ModelCapabilitiesOverride? ModelCapabilities { get; set; }
2477+
}
2478+
24522479
/// <summary>
24532480
/// Shared configuration properties for creating or resuming a Copilot session.
24542481
/// Use <see cref="SessionConfig"/> when creating a new session, or
@@ -3556,6 +3583,7 @@ public sealed class SystemMessageTransformRpcResponse
35563583
[JsonSerializable(typeof(SessionListFilter))]
35573584
[JsonSerializable(typeof(SectionOverride))]
35583585
[JsonSerializable(typeof(SessionMetadata))]
3586+
[JsonSerializable(typeof(SetModelOptions))]
35593587
[JsonSerializable(typeof(SetForegroundSessionResponse))]
35603588
[JsonSerializable(typeof(SystemMessageConfig))]
35613589
[JsonSerializable(typeof(ToolBinaryResult))]

dotnet/test/Unit/SerializationTests.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void SendMessageRequest_CanSerializeRequestHeaders_WithSdkOptions()
8787
("Mode", "enqueue"),
8888
("RequestHeaders", new Dictionary<string, string> { ["X-Trace"] = "trace-value" }));
8989

90-
var json = JsonSerializer.Serialize(request, requestType, options);
90+
var json = JsonSerializer.Serialize(request, requestType!, options);
9191
using var document = JsonDocument.Parse(json);
9292
var root = document.RootElement;
9393
Assert.Equal("session-id", root.GetProperty("sessionId").GetString());
@@ -221,6 +221,25 @@ public void SessionRequests_CanSerializeContextTier_WithSdkOptions()
221221
Assert.Equal("default", resumeDocument.RootElement.GetProperty("contextTier").GetString());
222222
}
223223

224+
[Fact]
225+
public void ModelSwitchToRequest_CanSerializeContextTier_WithSdkOptions()
226+
{
227+
var options = GetSerializerOptions();
228+
var requestType = typeof(CopilotClient).Assembly.GetType("GitHub.Copilot.Rpc.ModelSwitchToRequest");
229+
Assert.NotNull(requestType);
230+
var request = CreateInternalRequest(
231+
requestType!,
232+
("ModelId", "gpt-4.1"),
233+
("ReasoningSummary", ReasoningSummary.Detailed),
234+
("ContextTier", ContextTier.LongContext));
235+
236+
var json = JsonSerializer.Serialize(request, requestType, options);
237+
using var document = JsonDocument.Parse(json);
238+
Assert.Equal("gpt-4.1", document.RootElement.GetProperty("modelId").GetString());
239+
Assert.Equal("detailed", document.RootElement.GetProperty("reasoningSummary").GetString());
240+
Assert.Equal("long_context", document.RootElement.GetProperty("contextTier").GetString());
241+
}
242+
224243
[Fact]
225244
public void SessionRequests_CanSerializePluginDirectoriesAndLargeOutput_WithSdkOptions()
226245
{

go/rpc/zrpc.go

Lines changed: 6 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/session.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,9 @@ type SetModelOptions struct {
14951495
// ReasoningSummary sets the reasoning summary mode for the new model.
14961496
// Use ReasoningSummaryNone to suppress summary output regardless of whether reasoning is enabled.
14971497
ReasoningSummary *ReasoningSummary
1498+
// ContextTier pins the session to a context window tier for models that support it.
1499+
// Use ContextTierDefault or ContextTierLongContext for the currently known tiers.
1500+
ContextTier *ContextTier
14981501
// ModelCapabilities overrides individual model capabilities resolved by the runtime.
14991502
// Only non-nil fields are applied over the runtime-resolved capabilities.
15001503
ModelCapabilities *rpc.ModelCapabilitiesOverride
@@ -1516,6 +1519,7 @@ func (s *Session) SetModel(ctx context.Context, model string, opts *SetModelOpti
15161519
if opts != nil {
15171520
params.ReasoningEffort = opts.ReasoningEffort
15181521
params.ReasoningSummary = opts.ReasoningSummary
1522+
params.ContextTier = opts.ContextTier
15191523
params.ModelCapabilities = opts.ModelCapabilities
15201524
}
15211525
_, err := s.RPC.Model.SwitchTo(ctx, params)

0 commit comments

Comments
 (0)