@@ -15,9 +15,11 @@ This guide covers advanced scenarios for extending and customizing your Copilot
1515- [ File Attachments] ( #File_Attachments )
1616- [ Bring Your Own Key (BYOK)] ( #Bring_Your_Own_Key_BYOK )
1717- [ Infinite Sessions] ( #Infinite_Sessions )
18+ - [ Manual Compaction] ( #Manual_Compaction )
1819 - [ Compaction Events] ( #Compaction_Events )
1920- [ MCP Servers] ( #MCP_Servers )
2021- [ Custom Agents] ( #Custom_Agents )
22+ - [ Programmatic Agent Selection] ( #Programmatic_Agent_Selection )
2123- [ Skills Configuration] ( #Skills_Configuration )
2224 - [ Loading Skills] ( #Loading_Skills )
2325 - [ Disabling Skills] ( #Disabling_Skills )
@@ -317,6 +319,14 @@ var session = client.createSession(
317319var workspace = session. getWorkspacePath();
318320```
319321
322+ ### Manual Compaction
323+
324+ Trigger compaction immediately when you want to reduce context usage before the automatic threshold is reached:
325+
326+ ``` java
327+ session. compact(). get();
328+ ```
329+
320330### Compaction Events
321331
322332When compaction occurs, the session emits events that you can listen for:
@@ -419,6 +429,24 @@ var session = client.createSession(
419429
420430See [ CustomAgentConfig] ( apidocs/com/github/copilot/sdk/json/CustomAgentConfig.html ) Javadoc for full details.
421431
432+ ### Programmatic Agent Selection
433+
434+ You can inspect and switch agents at runtime:
435+
436+ ``` java
437+ var available = session. listAgents(). get();
438+
439+ var current = session. getCurrentAgent(). get();
440+ if (current != null ) {
441+ System . out. println(" Current agent: " + current. name());
442+ }
443+
444+ var selected = session. selectAgent(" reviewer" ). get();
445+ System . out. println(" Selected: " + selected. name());
446+
447+ session. deselectAgent(). get(); // Return to the default agent
448+ ```
449+
422450---
423451
424452## Skills Configuration
0 commit comments