Skip to content

Commit 1fc2ce5

Browse files
Copilotedburns
andauthored
Add mode handler documentation and run finish script
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
1 parent 473cee0 commit 1fc2ce5

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

src/site/markdown/advanced.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ This guide covers advanced scenarios for extending and customizing your Copilot
5353
- [Incoming Elicitation Handler](#Incoming_Elicitation_Handler)
5454
- [Session Capabilities](#Session_Capabilities)
5555
- [Outgoing Elicitation via session.getUi()](#Outgoing_Elicitation_via_session.getUi)
56+
- [Mode Handlers](#Mode_Handlers)
57+
- [Exit Plan Mode Handler](#Exit_Plan_Mode_Handler)
58+
- [Auto Mode Switch Handler](#Auto_Mode_Switch_Handler)
5659
- [Getting Session Metadata by ID](#Getting_Session_Metadata_by_ID)
5760

5861
---
@@ -1267,6 +1270,59 @@ All `getUi()` methods throw `IllegalStateException` if the host does not support
12671270

12681271
---
12691272

1273+
## Mode Handlers
1274+
1275+
Mode handlers let the host respond to runtime requests for switching between agent modes (plan, interactive, autopilot).
1276+
1277+
### Exit Plan Mode Handler
1278+
1279+
Register an `ExitPlanModeHandler` to handle requests from the agent to exit plan mode. The handler receives a summary of the plan, available actions, and a recommended action. If no handler is registered, exit-plan-mode requests are auto-approved.
1280+
1281+
```java
1282+
var session = client.createSession(
1283+
new SessionConfig()
1284+
.setOnExitPlanMode((request, invocation) -> {
1285+
System.out.println("Plan summary: " + request.getSummary());
1286+
System.out.println("Available actions: " + request.getActions());
1287+
// Approve and select an action
1288+
return CompletableFuture.completedFuture(
1289+
new ExitPlanModeResult()
1290+
.setApproved(true)
1291+
.setSelectedAction("autopilot"));
1292+
})
1293+
).get();
1294+
```
1295+
1296+
See [ExitPlanModeHandler](apidocs/com/github/copilot/sdk/json/ExitPlanModeHandler.html) Javadoc for more details.
1297+
1298+
### Auto Mode Switch Handler
1299+
1300+
Register an `AutoModeSwitchHandler` to handle requests to switch to an alternative model when a rate limit is encountered. If no handler is registered, auto-mode-switch requests are declined by default.
1301+
1302+
```java
1303+
var session = client.createSession(
1304+
new SessionConfig()
1305+
.setOnAutoModeSwitch((request, invocation) -> {
1306+
System.out.println("Rate limited: " + request.getErrorCode());
1307+
System.out.println("Retry after: " + request.getRetryAfterSeconds() + "s");
1308+
// Approve the switch for this rate-limit cycle
1309+
return CompletableFuture.completedFuture(AutoModeSwitchResponse.YES);
1310+
})
1311+
).get();
1312+
```
1313+
1314+
Available responses:
1315+
1316+
| Response | Description |
1317+
|---|---|
1318+
| `AutoModeSwitchResponse.YES` | Approve the switch for this rate-limit cycle |
1319+
| `AutoModeSwitchResponse.YES_ALWAYS` | Approve and remember the choice for this session |
1320+
| `AutoModeSwitchResponse.NO` | Decline the switch |
1321+
1322+
See [AutoModeSwitchHandler](apidocs/com/github/copilot/sdk/json/AutoModeSwitchHandler.html) Javadoc for more details.
1323+
1324+
---
1325+
12701326
## Getting Session Metadata by ID
12711327

12721328
Retrieve metadata for a specific session without listing all sessions:

0 commit comments

Comments
 (0)