Skip to content

Commit 044a272

Browse files
committed
feat: add Connection State & Diagnostics and Message Delivery Mode sections to documentation
1 parent 49f2dcd commit 044a272

2 files changed

Lines changed: 149 additions & 0 deletions

File tree

src/site/markdown/advanced.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This guide covers advanced scenarios for extending and customizing your Copilot
1515
- [Infinite Sessions](#Infinite_Sessions)
1616
- [Compaction Events](#Compaction_Events)
1717
- [MCP Servers](#MCP_Servers)
18+
- [Custom Agents](#Custom_Agents)
1819
- [Skills Configuration](#Skills_Configuration)
1920
- [Loading Skills](#Loading_Skills)
2021
- [Disabling Skills](#Disabling_Skills)
@@ -236,6 +237,65 @@ var session = client.createSession(
236237

237238
---
238239

240+
## Custom Agents
241+
242+
Extend the base Copilot assistant with specialized agents that have their own tools, prompts, and behavior. Users can invoke agents using the `@agent-name` mention syntax in messages.
243+
244+
```java
245+
var reviewer = new CustomAgentConfig()
246+
.setName("code-reviewer")
247+
.setDisplayName("Code Reviewer")
248+
.setDescription("Reviews code for best practices and security")
249+
.setPrompt("You are a code review expert. Focus on security, performance, and maintainability.")
250+
.setTools(List.of("read_file", "search_code"));
251+
252+
var session = client.createSession(
253+
new SessionConfig()
254+
.setCustomAgents(List.of(reviewer))
255+
).get();
256+
257+
// The user can now mention @code-reviewer in messages
258+
session.send("@code-reviewer Review src/Main.java").get();
259+
```
260+
261+
### Configuration Options
262+
263+
| Option | Type | Description |
264+
|--------|------|-------------|
265+
| `name` | String | Unique identifier used for `@mentions` (alphanumeric and hyphens) |
266+
| `displayName` | String | Human-readable name shown to users |
267+
| `description` | String | Describes the agent's capabilities |
268+
| `prompt` | String | System prompt that defines the agent's behavior |
269+
| `tools` | List<String> | Tool names available to this agent |
270+
| `mcpServers` | Map | MCP servers available to this agent |
271+
| `infer` | Boolean | Whether the agent can be auto-selected based on context |
272+
273+
### Multiple Agents
274+
275+
Register multiple agents for different tasks:
276+
277+
```java
278+
var agents = List.of(
279+
new CustomAgentConfig()
280+
.setName("reviewer")
281+
.setDescription("Code review")
282+
.setPrompt("You review code for issues."),
283+
new CustomAgentConfig()
284+
.setName("documenter")
285+
.setDescription("Documentation writer")
286+
.setPrompt("You write clear documentation.")
287+
.setInfer(true) // Auto-select when appropriate
288+
);
289+
290+
var session = client.createSession(
291+
new SessionConfig().setCustomAgents(agents)
292+
).get();
293+
```
294+
295+
See [CustomAgentConfig](apidocs/com/github/copilot/sdk/json/CustomAgentConfig.html) Javadoc for full details.
296+
297+
---
298+
239299
## Skills Configuration
240300

241301
Load custom skills from directories to extend the AI's capabilities with domain-specific knowledge.

src/site/markdown/documentation.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ This guide covers common use cases for the Copilot SDK for Java. For complete AP
1212
- [Streaming Responses](#Streaming_Responses)
1313
- [Session Operations](#Session_Operations)
1414
- [Choosing a Model](#Choosing_a_Model)
15+
- [Connection State & Diagnostics](#Connection_State__Diagnostics)
16+
- [Message Delivery Mode](#Message_Delivery_Mode)
1517
- [Session Management](#Session_Management)
1618

1719
---
@@ -310,6 +312,93 @@ var session = client.createSession(
310312

311313
---
312314

315+
## Connection State & Diagnostics
316+
317+
### Checking Connection State
318+
319+
Query the client's connection state at any time without making a server call:
320+
321+
```java
322+
ConnectionState state = client.getState();
323+
switch (state) {
324+
case CONNECTED -> System.out.println("Ready");
325+
case CONNECTING -> System.out.println("Starting up...");
326+
case DISCONNECTED -> System.out.println("Not connected");
327+
case ERROR -> System.out.println("Connection failed");
328+
}
329+
```
330+
331+
The four states are:
332+
333+
| State | Description |
334+
|-------|-------------|
335+
| `DISCONNECTED` | Client has not been started yet |
336+
| `CONNECTING` | `start()` was called but hasn't completed |
337+
| `CONNECTED` | Client is connected and ready |
338+
| `ERROR` | Connection failed (check logs for details) |
339+
340+
### Server Status
341+
342+
Get CLI version and protocol information:
343+
344+
```java
345+
var status = client.getStatus().get();
346+
System.out.println("CLI version: " + status.getVersion());
347+
System.out.println("Protocol version: " + status.getProtocolVersion());
348+
```
349+
350+
### Authentication Status
351+
352+
Check whether the current connection is authenticated and how:
353+
354+
```java
355+
var auth = client.getAuthStatus().get();
356+
if (auth.isAuthenticated()) {
357+
System.out.println("Logged in as: " + auth.getLogin());
358+
System.out.println("Auth type: " + auth.getAuthType());
359+
System.out.println("Host: " + auth.getHost());
360+
} else {
361+
System.out.println("Not authenticated: " + auth.getStatusMessage());
362+
}
363+
```
364+
365+
### Ping
366+
367+
Verify server connectivity:
368+
369+
```java
370+
var pong = client.ping("hello").get();
371+
System.out.println("Server responded, protocol version: " + pong.protocolVersion());
372+
```
373+
374+
See [ConnectionState](apidocs/com/github/copilot/sdk/ConnectionState.html), [GetStatusResponse](apidocs/com/github/copilot/sdk/json/GetStatusResponse.html), and [GetAuthStatusResponse](apidocs/com/github/copilot/sdk/json/GetAuthStatusResponse.html) Javadoc for details.
375+
376+
---
377+
378+
## Message Delivery Mode
379+
380+
Control how messages are delivered to the session:
381+
382+
```java
383+
// Default: message is enqueued for processing
384+
session.send(new MessageOptions()
385+
.setPrompt("Analyze this codebase")
386+
).get();
387+
388+
// Immediate: process the message right away
389+
session.send(new MessageOptions()
390+
.setPrompt("Quick question")
391+
.setMode("immediate")
392+
).get();
393+
```
394+
395+
| Mode | Description |
396+
|------|-------------|
397+
| `"enqueue"` | Queue the message for processing (default) |
398+
| `"immediate"` | Process the message immediately |
399+
400+
---
401+
313402
## Session Management
314403

315404
### Multiple Concurrent Sessions

0 commit comments

Comments
 (0)