feat(java): Add ToolDefinition.fromObject() and fromClass() registration API#1779
Draft
Copilot wants to merge 2 commits into
Draft
feat(java): Add ToolDefinition.fromObject() and fromClass() registration API#1779Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
…thods Adds static methods that load processor-generated $$CopilotToolMeta classes and return List<ToolDefinition> with fully working tool definitions (schema + invocation handlers). - fromObject(Object): discovers tools from an instance with @copilotTool methods - fromClass(Class<?>): discovers tools from a class with static @copilotTool methods - Private getConfiguredMapper(): provides ObjectMapper matching JsonRpcClient config - Throws IllegalStateException with helpful message if generated class not found - Both methods annotated with @CopilotExperimental Includes comprehensive test suite (ToolDefinitionFromObjectTest) covering: - Basic discovery and schema verification - Handler invocation for String, void, and CompletableFuture returns - Argument coercion with primitives, String, boolean, and enums - Default value handling when arguments are omitted - Error case for missing generated class - java.time argument deserialization (validates JavaTimeModule contract) - Override tool flag propagation - ToolDefer.NONE → null mapping (defer absent from JSON output) Closes #1761 Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add ToolDefinition registration API methods
feat(java): Add ToolDefinition.fromObject() and fromClass() registration API
Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the runtime registration API that loads processor-generated
$$CopilotToolMetacompanion classes and returnsList<ToolDefinition>with fully working handlers. This is task 4.4 in the tool ergonomics epic.Changes
ToolDefinition.java— two new@CopilotExperimentalstatic methods:fromObject(Object)— for instance methods annotated with@CopilotToolfromClass(Class<?>)— for static@CopilotToolmethods (passesnullinstance)loadDefinitions()usesClass.forNamewith the target classloader,setAccessible(true), and passes a configuredObjectMapperConfiguredMapperHolder— lazy-init mapper matchingJsonRpcClient.createObjectMapper()(JavaTimeModule, lenient unknown-props, ISO dates, NON_NULL)IllegalStateExceptionwith actionable message if$$CopilotToolMetanot found — no reflection fallbackToolDefinitionFromObjectTest.java— 13 gating tests with hand-written meta fixtures covering: tool discovery, schema validation, handler invocation (String/void/CompletableFuture), argument coercion (primitives + enum), default values, missing-class error,java.timedeserialization via ObjectMapper contract, override flag, andToolDefer.NONE→nullJSON omissionUsage