Package com.github.copilot.sdk.json
Record Class ToolDefinition
java.lang.Object
java.lang.Record
com.github.copilot.sdk.json.ToolDefinition
- Record Components:
name- the unique name of the tooldescription- a description of what the tool doesparameters- the JSON Schema defining the tool's parametershandler- the handler function to execute when invoked
public record ToolDefinition(String name, String description, Object parameters, ToolHandler handler)
extends Record
Defines a tool that can be invoked by the AI assistant.
Tools extend the assistant's capabilities by allowing it to call back into your application to perform actions or retrieve information. Each tool has a name, description, parameter schema, and a handler function that executes when the tool is invoked.
Example Usage
// Define a record for your tool's arguments
record WeatherArgs(String location) {
}
var tool = ToolDefinition.create("get_weather", "Get the current weather for a location",
Map.of("type", "object", "properties",
Map.of("location", Map.of("type", "string", "description", "City name")), "required",
List.of("location")),
invocation -> {
// Type-safe access with records (recommended)
WeatherArgs args = invocation.getArgumentsAs(WeatherArgs.class);
return CompletableFuture.completedFuture(getWeatherData(args.location()));
// Or use Map-based access
// Map<String, Object> args = invocation.getArguments();
// String location = (String) args.get("location");
});
- Since:
- 1.0.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionToolDefinition(String name, String description, Object parameters, ToolHandler handler) Creates an instance of aToolDefinitionrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic ToolDefinitionCreates a tool definition with a JSON schema for parameters.Returns the value of thedescriptionrecord component.final booleanIndicates whether some other object is "equal to" this one.handler()Returns the value of thehandlerrecord component.final inthashCode()Returns a hash code value for this object.name()Returns the value of thenamerecord component.Returns the value of theparametersrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
ToolDefinition
Creates an instance of aToolDefinitionrecord class.- Parameters:
name- the value for thenamerecord componentdescription- the value for thedescriptionrecord componentparameters- the value for theparametersrecord componenthandler- the value for thehandlerrecord component
-
-
Method Details
-
create
public static ToolDefinition create(String name, String description, Map<String, Object> schema, ToolHandler handler) Creates a tool definition with a JSON schema for parameters.This is a convenience factory method for creating tools with a
Map-based parameter schema.- Parameters:
name- the unique name of the tooldescription- a description of what the tool doesschema- the JSON Schema as aMaphandler- the handler function to execute when invoked- Returns:
- a new tool definition
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
name
Returns the value of thenamerecord component.- Returns:
- the value of the
namerecord component
-
description
Returns the value of thedescriptionrecord component.- Returns:
- the value of the
descriptionrecord component
-
parameters
Returns the value of theparametersrecord component.- Returns:
- the value of the
parametersrecord component
-
handler
Returns the value of thehandlerrecord component.- Returns:
- the value of the
handlerrecord component
-