@@ -8,7 +8,9 @@ This guide covers common use cases for the Copilot SDK for Java. For complete AP
88
99- [ Basic Usage] ( #Basic_Usage )
1010- [ Handling Responses] ( #Handling_Responses )
11+ - [ Event Types Reference] ( #Event_Types_Reference )
1112- [ Streaming Responses] ( #Streaming_Responses )
13+ - [ Session Operations] ( #Session_Operations )
1214- [ Choosing a Model] ( #Choosing_a_Model )
1315- [ Session Management] ( #Session_Management )
1416
@@ -99,15 +101,83 @@ session.on(event -> {
99101| ` AssistantMessageDeltaEvent ` | Streaming chunk (when streaming enabled) |
100102| ` SessionIdleEvent ` | Session finished processing |
101103| ` SessionErrorEvent ` | An error occurred |
102- | ` SessionShutdownEvent ` | Session is shutting down (with reason and exit code) |
103- | ` ToolExecutionStartEvent ` | Tool invocation started |
104- | ` ToolExecutionCompleteEvent ` | Tool invocation completed |
105- | ` SkillInvokedEvent ` | A skill was invoked |
106- | ` SessionCompactionStartEvent ` | Context compaction started (infinite sessions) |
107- | ` SessionCompactionCompleteEvent ` | Context compaction completed |
108- | ` SessionUsageInfoEvent ` | Token usage information |
109104
110- See the [ events package Javadoc] ( apidocs/com/github/copilot/sdk/events/package-summary.html ) for all event types.
105+ For the complete list of all 33 event types, see [ Event Types Reference] ( #Event_Types_Reference ) below.
106+
107+ ---
108+
109+ ## Event Types Reference
110+
111+ The SDK supports 33 event types organized by category. All events extend ` AbstractSessionEvent ` .
112+
113+ ### Session Events
114+
115+ | Event | Type String | Description |
116+ | -------| -------------| -------------|
117+ | ` SessionStartEvent ` | ` session.start ` | Session has started |
118+ | ` SessionResumeEvent ` | ` session.resume ` | Session was resumed |
119+ | ` SessionIdleEvent ` | ` session.idle ` | Session finished processing, ready for input |
120+ | ` SessionErrorEvent ` | ` session.error ` | An error occurred in the session |
121+ | ` SessionInfoEvent ` | ` session.info ` | Informational message from the session |
122+ | ` SessionShutdownEvent ` | ` session.shutdown ` | Session is shutting down (includes reason and exit code) |
123+ | ` SessionModelChangeEvent ` | ` session.model_change ` | The model was changed mid-session |
124+ | ` SessionHandoffEvent ` | ` session.handoff ` | Session handed off to another agent |
125+ | ` SessionTruncationEvent ` | ` session.truncation ` | Context was truncated due to limits |
126+ | ` SessionSnapshotRewindEvent ` | ` session.snapshot_rewind ` | Session rewound to a previous snapshot |
127+ | ` SessionUsageInfoEvent ` | ` session.usage_info ` | Token usage information |
128+ | ` SessionCompactionStartEvent ` | ` session.compaction_start ` | Context compaction started (infinite sessions) |
129+ | ` SessionCompactionCompleteEvent ` | ` session.compaction_complete ` | Context compaction completed |
130+
131+ ### Assistant Events
132+
133+ | Event | Type String | Description |
134+ | -------| -------------| -------------|
135+ | ` AssistantTurnStartEvent ` | ` assistant.turn_start ` | Assistant began processing |
136+ | ` AssistantIntentEvent ` | ` assistant.intent ` | Assistant's detected intent |
137+ | ` AssistantReasoningEvent ` | ` assistant.reasoning ` | Full reasoning content (reasoning models) |
138+ | ` AssistantReasoningDeltaEvent ` | ` assistant.reasoning_delta ` | Streaming reasoning chunk |
139+ | ` AssistantMessageEvent ` | ` assistant.message ` | Complete assistant message |
140+ | ` AssistantMessageDeltaEvent ` | ` assistant.message_delta ` | Streaming message chunk |
141+ | ` AssistantTurnEndEvent ` | ` assistant.turn_end ` | Assistant finished processing |
142+ | ` AssistantUsageEvent ` | ` assistant.usage ` | Token usage for this turn |
143+
144+ ### Tool Events
145+
146+ | Event | Type String | Description |
147+ | -------| -------------| -------------|
148+ | ` ToolUserRequestedEvent ` | ` tool.user_requested ` | User requested a tool invocation |
149+ | ` ToolExecutionStartEvent ` | ` tool.execution_start ` | Tool execution started |
150+ | ` ToolExecutionProgressEvent ` | ` tool.execution_progress ` | Tool execution progress update |
151+ | ` ToolExecutionPartialResultEvent ` | ` tool.execution_partial_result ` | Partial result from tool |
152+ | ` ToolExecutionCompleteEvent ` | ` tool.execution_complete ` | Tool execution completed |
153+
154+ ### User Events
155+
156+ | Event | Type String | Description |
157+ | -------| -------------| -------------|
158+ | ` UserMessageEvent ` | ` user.message ` | User sent a message |
159+ | ` PendingMessagesModifiedEvent ` | ` pending_messages.modified ` | Pending message queue changed |
160+
161+ ### Subagent Events
162+
163+ | Event | Type String | Description |
164+ | -------| -------------| -------------|
165+ | ` SubagentStartedEvent ` | ` subagent.started ` | Subagent was spawned |
166+ | ` SubagentSelectedEvent ` | ` subagent.selected ` | Subagent was selected for task |
167+ | ` SubagentCompletedEvent ` | ` subagent.completed ` | Subagent completed its task |
168+ | ` SubagentFailedEvent ` | ` subagent.failed ` | Subagent failed |
169+
170+ ### Other Events
171+
172+ | Event | Type String | Description |
173+ | -------| -------------| -------------|
174+ | ` AbortEvent ` | ` abort ` | Operation was aborted |
175+ | ` HookStartEvent ` | ` hook.start ` | Hook execution started |
176+ | ` HookEndEvent ` | ` hook.end ` | Hook execution completed |
177+ | ` SystemMessageEvent ` | ` system.message ` | System-level message |
178+ | ` SkillInvokedEvent ` | ` skill.invoked ` | A skill was invoked |
179+
180+ See the [ events package Javadoc] ( apidocs/com/github/copilot/sdk/events/package-summary.html ) for detailed event data structures.
111181
112182---
113183
@@ -140,6 +210,76 @@ done.get();
140210
141211---
142212
213+ ## Session Operations
214+
215+ ### Get Conversation History
216+
217+ Retrieve all messages and events from a session using ` getMessages() ` :
218+
219+ ``` java
220+ List<AbstractSessionEvent > history = session. getMessages(). get();
221+
222+ for (AbstractSessionEvent event : history) {
223+ switch (event) {
224+ case UserMessageEvent user - >
225+ System . out. println(" User: " + user. getData(). getContent());
226+ case AssistantMessageEvent assistant - >
227+ System . out. println(" Assistant: " + assistant. getData(). getContent());
228+ case ToolExecutionCompleteEvent tool - >
229+ System . out. println(" Tool: " + tool. getData(). getToolName());
230+ default - > { }
231+ }
232+ }
233+ ```
234+
235+ This is useful for:
236+ - Displaying conversation history in a UI
237+ - Persisting conversations for later review
238+ - Debugging and logging session state
239+
240+ ### Abort Current Operation
241+
242+ Cancel a long-running operation using ` abort() ` :
243+
244+ ``` java
245+ // Start a potentially long operation
246+ var messageFuture = session. send(" Analyze this large codebase..." );
247+
248+ // User clicks cancel button
249+ session. abort(). get();
250+
251+ // The session will emit an AbortEvent
252+ session. on(AbortEvent . class, evt - > {
253+ System . out. println(" Operation was cancelled" );
254+ });
255+ ```
256+
257+ Use cases:
258+ - User-initiated cancellation in interactive applications
259+ - Timeout handling in automated pipelines
260+ - Graceful shutdown when application is closing
261+
262+ ### Custom Timeout
263+
264+ Use ` sendAndWait ` with a custom timeout for CI/CD pipelines:
265+
266+ ``` java
267+ try {
268+ // 30-second timeout
269+ var response = session. sendAndWait(
270+ new MessageOptions (). setPrompt(" Quick question" ),
271+ 30000 // timeout in milliseconds
272+ ). get();
273+ } catch (ExecutionException e) {
274+ if (e. getCause() instanceof TimeoutException ) {
275+ System . err. println(" Request timed out" );
276+ session. abort(). get();
277+ }
278+ }
279+ ```
280+
281+ ---
282+
143283## Choosing a Model
144284
145285### List Available Models
@@ -210,5 +350,6 @@ client.deleteSession(sessionId).get();
210350## Next Steps
211351
212352- 📖 ** [ Advanced Usage] ( advanced.html ) ** - Tools, BYOK, MCP Servers, System Messages, Infinite Sessions, Skills
353+ - 📖 ** [ Session Hooks] ( hooks.html ) ** - Intercept tool execution and session lifecycle events
213354- 📖 ** [ MCP Servers] ( mcp.html ) ** - Integrate external tools via Model Context Protocol
214355- 📖 ** [ API Javadoc] ( apidocs/index.html ) ** - Complete API reference
0 commit comments