Skip to content

add schema attribute to @CopilotToolParam and inline tools for custom type schema override #2068

Description

@edburns

Supercedes #1999

Closes #1794

Summary

Adds an optional schema attribute to @CopilotToolParam that allows users to explicitly specify the JSON Schema for a tool parameter. This enables support for custom/third-party types that the SchemaGenerator cannot automatically map.

Example

@CopilotTool("Schedule a deployment")
public String scheduleDeployment(
        @CopilotToolParam(value = "Deployment time in ISO-8601",
            schema = "{\"type\":\"string\",\"format\":\"date-time\"}")
        com.acme.internal.AcmeDateTime deployTime) {
    return "Scheduled for " + deployTime;
}

Changes

CopilotToolParam.java

  • Added String schema() default "" annotation attribute with Javadoc

CopilotToolProcessor.java

  • In generateSchemaWithParamMetadata(): when schema is non-empty, use it instead of auto-generated schema
  • Added compile-time validation: schema + defaultValue conflict emits error
  • Added compile-time validation: invalid JSON (not starting/ending with braces) emits error
  • Added jsonToMapOfSource() — a minimal recursive-descent JSON parser that converts JSON strings to Map.of(...) source code expressions at compile time (no external JSON library needed)

Param.java

  • Added schema field, fluent schema() mutator, and getter for lambda API parity
  • Updated equals(), hashCode() to include schema

CopilotToolProcessorTest.java (4 new tests)

  1. Schema override — custom schema appears in generated code
  2. Schema + defaultValue conflict — produces compile error
  3. Invalid JSON — produces compile error
  4. Empty schema — falls through to normal type-based generation

Testing

  • All 4 new tests pass
  • The only failing test (generatesNullMetadata_whenAbsent) is a pre-existing failure on main unrelated to this PR

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions