Skip to content

Add ADR-005: Ergonomic tool definition via annotation processor#1684

Merged
edburns merged 1 commit into
mainfrom
edburns/1682-java-improve-tool-calling
Jun 15, 2026
Merged

Add ADR-005: Ergonomic tool definition via annotation processor#1684
edburns merged 1 commit into
mainfrom
edburns/1682-java-improve-tool-calling

Conversation

@edburns

@edburns edburns commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Introduces an Architecture Decision Record documenting the plan to add a langchain4j-style annotation-on-method API for defining Copilot tools in Java.

Problem

The current ToolDefinition.create() API requires manually constructing JSON Schema parameter objects—verbose and error-prone compared to the ergonomic patterns available in other Java AI frameworks (langchain4j @Tool/@P, Spring AI @Tool/@ToolParam).

Decision

Adopt Option 3 (annotation-on-method) with a JSR 269 annotation processor:

  • @CopilotTool on methods defines tools; method name → tool name, Javadoc/annotation attribute → description.
  • @Param on parameters provides descriptions and constraints; the processor reads source-level parameter names at compile time, eliminating the need for the -parameters javac flag.
  • A compile-time annotation processor generates ToolDefinition instances and JSON Schema from annotated methods—no runtime reflection required.
  • The new API surface is gated behind @CopilotExperimental (ADR-004) until stabilized.
  • The existing ToolDefinition.create() / CopilotTools.define() APIs remain unchanged and fully supported.

Scope

This ADR captures the design decision only. Implementation will follow in a separate PR tracked by #1682.

Related: #1682

Introduces an Architecture Decision Record documenting the plan to add a
langchain4j-style annotation-on-method API for defining Copilot tools in Java.

## Problem

The current `ToolDefinition.create()` API requires manually constructing JSON
Schema parameter objects—verbose and error-prone compared to the ergonomic
patterns available in other Java AI frameworks (langchain4j `@Tool`/`@P`,
Spring AI `@Tool`/`@ToolParam`).

## Decision

Adopt Option 3 (annotation-on-method) with a JSR 269 annotation processor:

- `@CopilotTool` on methods defines tools; method name → tool name,
  Javadoc/annotation attribute → description.
- `@Param` on parameters provides descriptions and constraints; the processor
  reads source-level parameter names at compile time, eliminating the need for
  the `-parameters` javac flag.
- A compile-time annotation processor generates `ToolDefinition` instances and
  JSON Schema from annotated methods—no runtime reflection required.
- The new API surface is gated behind `@CopilotExperimental` (ADR-004) until
  stabilized.
- The existing `ToolDefinition.create()` / `CopilotTools.define()` APIs remain
  unchanged and fully supported.

## Scope

This ADR captures the design decision only. Implementation will follow in a
separate PR tracked by #1682.

Related: #1682

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@edburns edburns requested a review from a team as a code owner June 15, 2026 23:21
Copilot AI review requested due to automatic review settings June 15, 2026 23:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.

@edburns edburns merged commit cf88dcf into main Jun 15, 2026
10 checks passed
@edburns edburns deleted the edburns/1682-java-improve-tool-calling branch June 15, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants