|
6 | 6 |
|
7 | 7 | import java.util.Map; |
8 | 8 |
|
| 9 | +import com.fasterxml.jackson.annotation.JsonIgnore; |
9 | 10 | import com.fasterxml.jackson.annotation.JsonInclude; |
10 | 11 | import com.fasterxml.jackson.annotation.JsonProperty; |
11 | 12 |
|
|
39 | 40 | * }); |
40 | 41 | * }</pre> |
41 | 42 | * |
| 43 | + * @param name |
| 44 | + * the unique name of the tool |
| 45 | + * @param description |
| 46 | + * a description of what the tool does |
| 47 | + * @param parameters |
| 48 | + * the JSON Schema defining the tool's parameters |
| 49 | + * @param handler |
| 50 | + * the handler function to execute when invoked |
42 | 51 | * @see SessionConfig#setTools(java.util.List) |
43 | 52 | * @see ToolHandler |
44 | 53 | * @since 1.0.0 |
45 | 54 | */ |
46 | 55 | @JsonInclude(JsonInclude.Include.NON_NULL) |
47 | | -public class ToolDefinition { |
48 | | - |
49 | | - @JsonProperty("name") |
50 | | - private String name; |
51 | | - |
52 | | - @JsonProperty("description") |
53 | | - private String description; |
54 | | - |
55 | | - @JsonProperty("parameters") |
56 | | - private Object parameters; |
57 | | - |
58 | | - private transient ToolHandler handler; |
59 | | - |
60 | | - /** |
61 | | - * Creates an empty tool definition. |
62 | | - * <p> |
63 | | - * Use the setter methods to configure the tool. |
64 | | - */ |
65 | | - public ToolDefinition() { |
66 | | - } |
67 | | - |
68 | | - /** |
69 | | - * Creates a tool definition with all properties. |
70 | | - * |
71 | | - * @param name |
72 | | - * the unique name of the tool |
73 | | - * @param description |
74 | | - * a description of what the tool does |
75 | | - * @param parameters |
76 | | - * the JSON Schema defining the tool's parameters |
77 | | - * @param handler |
78 | | - * the handler function to execute when invoked |
79 | | - */ |
80 | | - public ToolDefinition(String name, String description, Object parameters, ToolHandler handler) { |
81 | | - this.name = name; |
82 | | - this.description = description; |
83 | | - this.parameters = parameters; |
84 | | - this.handler = handler; |
85 | | - } |
86 | | - |
87 | | - /** |
88 | | - * Gets the tool name. |
89 | | - * |
90 | | - * @return the unique name of the tool |
91 | | - */ |
92 | | - public String getName() { |
93 | | - return name; |
94 | | - } |
95 | | - |
96 | | - /** |
97 | | - * Sets the tool name. |
98 | | - * <p> |
99 | | - * The name should be unique within a session and follow naming conventions |
100 | | - * similar to function names (e.g., "get_user", "search_files"). |
101 | | - * |
102 | | - * @param name |
103 | | - * the unique name of the tool |
104 | | - * @return this tool definition for method chaining |
105 | | - */ |
106 | | - public ToolDefinition setName(String name) { |
107 | | - this.name = name; |
108 | | - return this; |
109 | | - } |
110 | | - |
111 | | - /** |
112 | | - * Gets the tool description. |
113 | | - * |
114 | | - * @return the description of what the tool does |
115 | | - */ |
116 | | - public String getDescription() { |
117 | | - return description; |
118 | | - } |
119 | | - |
120 | | - /** |
121 | | - * Sets the tool description. |
122 | | - * <p> |
123 | | - * The description helps the AI understand when and how to use the tool. Be |
124 | | - * clear and specific about the tool's purpose and any constraints. |
125 | | - * |
126 | | - * @param description |
127 | | - * the description of what the tool does |
128 | | - * @return this tool definition for method chaining |
129 | | - */ |
130 | | - public ToolDefinition setDescription(String description) { |
131 | | - this.description = description; |
132 | | - return this; |
133 | | - } |
134 | | - |
135 | | - /** |
136 | | - * Gets the parameter schema. |
137 | | - * |
138 | | - * @return the JSON Schema for the tool's parameters |
139 | | - */ |
140 | | - public Object getParameters() { |
141 | | - return parameters; |
142 | | - } |
143 | | - |
144 | | - /** |
145 | | - * Sets the parameter schema. |
146 | | - * <p> |
147 | | - * The schema should follow JSON Schema format and define the structure of |
148 | | - * arguments the tool accepts. This is typically a {@code Map} with "type", |
149 | | - * "properties", and "required" fields. |
150 | | - * |
151 | | - * @param parameters |
152 | | - * the JSON Schema for the tool's parameters |
153 | | - * @return this tool definition for method chaining |
154 | | - */ |
155 | | - public ToolDefinition setParameters(Object parameters) { |
156 | | - this.parameters = parameters; |
157 | | - return this; |
158 | | - } |
159 | | - |
160 | | - /** |
161 | | - * Gets the tool handler. |
162 | | - * |
163 | | - * @return the handler function that executes when the tool is invoked |
164 | | - */ |
165 | | - public ToolHandler getHandler() { |
166 | | - return handler; |
167 | | - } |
168 | | - |
169 | | - /** |
170 | | - * Sets the tool handler. |
171 | | - * <p> |
172 | | - * The handler is called when the assistant invokes this tool. It receives a |
173 | | - * {@link ToolInvocation} with the arguments and should return a |
174 | | - * {@code CompletableFuture} with the result. |
175 | | - * |
176 | | - * @param handler |
177 | | - * the handler function |
178 | | - * @return this tool definition for method chaining |
179 | | - * @see ToolHandler |
180 | | - */ |
181 | | - public ToolDefinition setHandler(ToolHandler handler) { |
182 | | - this.handler = handler; |
183 | | - return this; |
184 | | - } |
| 56 | +public record ToolDefinition(@JsonProperty("name") String name, @JsonProperty("description") String description, |
| 57 | + @JsonProperty("parameters") Object parameters, @JsonIgnore ToolHandler handler) { |
185 | 58 |
|
186 | 59 | /** |
187 | 60 | * Creates a tool definition with a JSON schema for parameters. |
|
0 commit comments