Skip to content

Commit 098ae66

Browse files
Copilotedburns
andauthored
Add documentation for mode handler APIs
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
1 parent 6f509f0 commit 098ae66

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

src/site/markdown/advanced.md

Lines changed: 69 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,72 @@ All `getUi()` methods throw `IllegalStateException` if the host does not support
12671270

12681271
---
12691272

1273+
## Mode Handlers
1274+
1275+
Mode handlers allow your application to respond to agent requests for plan-mode transitions and automatic model switching.
1276+
1277+
### Exit Plan Mode Handler
1278+
1279+
Register a handler to receive exit-plan-mode requests when the agent wants to transition out of plan mode:
1280+
1281+
```java
1282+
var config = new SessionConfig()
1283+
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
1284+
.setOnExitPlanMode((request, invocation) -> {
1285+
System.out.println("Plan summary: " + request.getSummary());
1286+
System.out.println("Available actions: " + request.getActions());
1287+
// Approve the transition and select an action
1288+
return CompletableFuture.completedFuture(
1289+
new ExitPlanModeResult()
1290+
.setApproved(true)
1291+
.setSelectedAction("interactive")
1292+
);
1293+
});
1294+
```
1295+
1296+
The `ExitPlanModeRequest` includes:
1297+
1298+
- `summary` — Summary of the plan or proposed next step
1299+
- `planContent` — Full plan content, when available
1300+
- `actions` — Available actions the user can select
1301+
- `recommendedAction` — The action recommended by the runtime (default: `"autopilot"`)
1302+
1303+
When no handler is registered, the SDK automatically approves the exit with default settings.
1304+
1305+
See [ExitPlanModeHandler](apidocs/com/github/copilot/sdk/json/ExitPlanModeHandler.html) Javadoc for more details.
1306+
1307+
### Auto Mode Switch Handler
1308+
1309+
Register a handler to respond when the agent encounters a rate limit and wants to switch to a different model:
1310+
1311+
```java
1312+
var config = new SessionConfig()
1313+
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
1314+
.setOnAutoModeSwitch((request, invocation) -> {
1315+
System.out.println("Rate limited: " + request.getErrorCode());
1316+
System.out.println("Retry after: " + request.getRetryAfterSeconds() + "s");
1317+
// Approve the model switch
1318+
return CompletableFuture.completedFuture(AutoModeSwitchResponse.YES);
1319+
});
1320+
```
1321+
1322+
The `AutoModeSwitchRequest` includes:
1323+
1324+
- `errorCode` — The rate-limit error code that triggered the request
1325+
- `retryAfterSeconds` — Seconds until the rate limit resets, when known
1326+
1327+
The `AutoModeSwitchResponse` enum provides three options:
1328+
1329+
- `YES` — Approve the switch for this rate-limit cycle
1330+
- `YES_ALWAYS` — Approve and remember the choice for this session
1331+
- `NO` — Decline the switch
1332+
1333+
When no handler is registered, the SDK declines the switch by default.
1334+
1335+
See [AutoModeSwitchHandler](apidocs/com/github/copilot/sdk/json/AutoModeSwitchHandler.html) Javadoc for more details.
1336+
1337+
---
1338+
12701339
## Getting Session Metadata by ID
12711340

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

0 commit comments

Comments
 (0)