Skip to content

Add Copilot SDK Java instructions file#13

Merged
brunoborges merged 6 commits intomainfrom
add-copilot-sdk-java-instructions
Mar 17, 2026
Merged

Add Copilot SDK Java instructions file#13
brunoborges merged 6 commits intomainfrom
add-copilot-sdk-java-instructions

Conversation

@brunoborges
Copy link
Collaborator

Adds instructions/copilot-sdk-java.instructions.md — a comprehensive guide for building Java applications with the Copilot SDK.

Modeled after the C# equivalent at github/awesome-copilot, adapted to Java idioms:

  • Client initialization with CopilotClient and CopilotClientOptions
  • Session management including create, resume, list, delete
  • Event handling with typed on() subscriptions and pattern matching
  • Streaming with delta and final event handling
  • Custom tools via ToolDefinition.create() with type-safe argument deserialization
  • Permission & user input handlers
  • System message customization (append/replace modes)
  • BYOK provider configuration (OpenAI, Azure)
  • Common patterns — query-response, multi-turn, session hooks
  • Best practices — try-with-resources, CompletableFuture usage, error handling

The frontmatter applyTo targets **.java and **/pom.xml files.

Add instructions/copilot-sdk-java.instructions.md modeled after the
C# equivalent in github/awesome-copilot. Covers client initialization,
session management, event handling, streaming, custom tools, BYOK,
permissions, and common usage patterns for Java developers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 17, 2026 07:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Copilot instruction file intended to guide Java developers in using copilot-sdk-java, covering client/session setup, event handling, streaming, tools, hooks, and BYOK provider configuration.

Changes:

  • Introduces instructions/copilot-sdk-java.instructions.md with end-to-end usage patterns for the SDK.
  • Documents key SDK APIs (client options, session config, events, tools, permissions, user input, etc.).
  • Includes copy/paste code samples for common workflows (streaming, tools, hooks, BYOK).
Comments suppressed due to low confidence (5)

instructions/copilot-sdk-java.instructions.md:31

  • Gradle example uses the wrong groupId (com.github.copilot). It should match the published coordinates used by this project (groupId com.github, artifactId copilot-sdk-java).
```groovy
implementation 'com.github.copilot:copilot-sdk-java:LATEST'
**instructions/copilot-sdk-java.instructions.md:760**
* `SessionHooks.setOnPostToolUse(...)` also takes `(input, invocation)` and returns `CompletableFuture<PostToolUseHookOutput>` (nullable). The one-parameter lambda in this snippet won’t compile; update it to match the handler signature.
    .setOnPostToolUse(hook -> {
        System.out.println("Tool execution complete: " + hook);
        return CompletableFuture.completedFuture(null);
    }))
**instructions/copilot-sdk-java.instructions.md:242**
* `setEventErrorHandler` expects an `EventErrorHandler` with signature `(event, exception) -> { ... }`, not a single-parameter lambda. Update the sample to accept both the event being dispatched and the thrown exception.

// Set a custom error handler
session.setEventErrorHandler(ex -> {
logger.error("Event handler error", ex);
});

**instructions/copilot-sdk-java.instructions.md:394**
* The permission result kind string in this example ("user-denied") doesn’t match the well-known kinds used elsewhere in this SDK/tests (e.g., "denied-interactively-by-user" or `PermissionRequestResultKind.DENIED_INTERACTIVELY_BY_USER`). Using the well-known values (or the `PermissionRequestResultKind` constants) avoids interoperability issues with the CLI.
    if ("dangerous-action".equals(request.getKind())) {
        return CompletableFuture.completedFuture(
            new PermissionRequestResult().setKind("user-denied")
        );
    }
**instructions/copilot-sdk-java.instructions.md:531**
* This Azure BYOK example won’t compile against the current SDK: `AzureOptions` only supports `setApiVersion(...)`, and the tested provider type is `"azure-openai"` with `ProviderConfig.setBaseUrl(...)` + `setApiKey(...)` (see `ProviderConfigTest`). Please update the snippet to match the actual `ProviderConfig`/`AzureOptions` API so users can copy/paste it successfully.

var session = client.createSession(new SessionConfig()
.setProvider(new ProviderConfig()
.setType("azure")
.setAzure(new AzureOptions()
.setEndpoint("https://my-resource.openai.azure.com")
.setDeployment("gpt-4"))

</details>



---

You can also share your feedback on Copilot code review. [Take the survey](https://www.surveymonkey.com/r/XP6L3XJ).

brunoborges and others added 5 commits March 17, 2026 09:11
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@brunoborges brunoborges merged commit afb849c into main Mar 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants