7575 * controls whether the tool may be deferred (loaded lazily via tool
7676 * search) rather than always pre-loaded; {@code null} lets the
7777 * runtime decide
78+ * @param metadata
79+ * opaque, host-defined metadata forwarded verbatim to the runtime;
80+ * keys are namespaced and not part of the stable public API;
81+ * {@code null} when unset
7882 * @see SessionConfig#setTools(java.util.List)
7983 * @see ToolHandler
8084 * @since 1.0.0
8387public record ToolDefinition (@ JsonProperty ("name" ) String name , @ JsonProperty ("description" ) String description ,
8488 @ JsonProperty ("parameters" ) Object parameters , @ JsonIgnore ToolHandler handler ,
8589 @ JsonProperty ("overridesBuiltInTool" ) Boolean overridesBuiltInTool ,
86- @ JsonProperty ("skipPermission" ) Boolean skipPermission , @ JsonProperty ("defer" ) ToolDefer defer ) {
90+ @ JsonProperty ("skipPermission" ) Boolean skipPermission , @ JsonProperty ("defer" ) ToolDefer defer ,
91+ @ JsonProperty ("metadata" ) Map <String , Object > metadata ) {
8792
8893 /**
8994 * Creates a tool definition with a JSON schema for parameters.
@@ -103,7 +108,7 @@ public record ToolDefinition(@JsonProperty("name") String name, @JsonProperty("d
103108 */
104109 public static ToolDefinition create (String name , String description , Map <String , Object > schema ,
105110 ToolHandler handler ) {
106- return new ToolDefinition (name , description , schema , handler , null , null , null );
111+ return new ToolDefinition (name , description , schema , handler , null , null , null , null );
107112 }
108113
109114 /**
@@ -127,7 +132,7 @@ public static ToolDefinition create(String name, String description, Map<String,
127132 */
128133 public static ToolDefinition createOverride (String name , String description , Map <String , Object > schema ,
129134 ToolHandler handler ) {
130- return new ToolDefinition (name , description , schema , handler , true , null , null );
135+ return new ToolDefinition (name , description , schema , handler , true , null , null , null );
131136 }
132137
133138 /**
@@ -150,7 +155,7 @@ public static ToolDefinition createOverride(String name, String description, Map
150155 */
151156 public static ToolDefinition createSkipPermission (String name , String description , Map <String , Object > schema ,
152157 ToolHandler handler ) {
153- return new ToolDefinition (name , description , schema , handler , null , true , null );
158+ return new ToolDefinition (name , description , schema , handler , null , true , null , null );
154159 }
155160
156161 /**
@@ -176,7 +181,33 @@ public static ToolDefinition createSkipPermission(String name, String descriptio
176181 */
177182 public static ToolDefinition createWithDefer (String name , String description , Map <String , Object > schema ,
178183 ToolHandler handler , ToolDefer defer ) {
179- return new ToolDefinition (name , description , schema , handler , null , null , defer );
184+ return new ToolDefinition (name , description , schema , handler , null , null , defer , null );
185+ }
186+
187+ /**
188+ * Creates a tool definition with opaque, host-defined metadata.
189+ * <p>
190+ * Use this factory method to attach namespaced metadata that the SDK
191+ * forwards verbatim to the runtime. The keys are not part of the stable
192+ * public API; the runtime may recognize specific keys to inform
193+ * host-specific behavior.
194+ *
195+ * @param name
196+ * the unique name of the tool
197+ * @param description
198+ * a description of what the tool does
199+ * @param schema
200+ * the JSON Schema as a {@code Map}
201+ * @param handler
202+ * the handler function to execute when invoked
203+ * @param metadata
204+ * the opaque metadata map forwarded to the runtime
205+ * @return a new tool definition with the metadata set
206+ * @since 1.0.0
207+ */
208+ public static ToolDefinition createWithMetadata (String name , String description , Map <String , Object > schema ,
209+ ToolHandler handler , Map <String , Object > metadata ) {
210+ return new ToolDefinition (name , description , schema , handler , null , null , null , metadata );
180211 }
181212
182213 /**
@@ -247,7 +278,7 @@ public static List<ToolDefinition> fromClass(Class<?> clazz) {
247278 */
248279 @ CopilotExperimental
249280 public ToolDefinition overridesBuiltInTool (boolean value ) {
250- return new ToolDefinition (name , description , parameters , handler , value , skipPermission , defer );
281+ return new ToolDefinition (name , description , parameters , handler , value , skipPermission , defer , metadata );
251282 }
252283
253284 /**
@@ -261,7 +292,7 @@ public ToolDefinition overridesBuiltInTool(boolean value) {
261292 */
262293 @ CopilotExperimental
263294 public ToolDefinition skipPermission (boolean value ) {
264- return new ToolDefinition (name , description , parameters , handler , overridesBuiltInTool , value , defer );
295+ return new ToolDefinition (name , description , parameters , handler , overridesBuiltInTool , value , defer , metadata );
265296 }
266297
267298 /**
@@ -275,7 +306,21 @@ public ToolDefinition skipPermission(boolean value) {
275306 */
276307 @ CopilotExperimental
277308 public ToolDefinition defer (ToolDefer value ) {
278- return new ToolDefinition (name , description , parameters , handler , overridesBuiltInTool , skipPermission , value );
309+ return new ToolDefinition (name , description , parameters , handler , overridesBuiltInTool , skipPermission , value , metadata );
310+ }
311+
312+ /**
313+ * Returns a copy with the opaque {@code metadata} bag set.
314+ *
315+ * @param value
316+ * the opaque, host-defined metadata forwarded verbatim to the
317+ * runtime; keys are namespaced and not part of the stable public API
318+ * @return a new {@code ToolDefinition} with the metadata applied
319+ * @since 1.0.6
320+ */
321+ @ CopilotExperimental
322+ public ToolDefinition metadata (Map <String , Object > value ) {
323+ return new ToolDefinition (name , description , parameters , handler , overridesBuiltInTool , skipPermission , defer , value );
279324 }
280325
281326 // ------------------------------------------------------------------
@@ -319,7 +364,7 @@ public static <R> ToolDefinition from(String name, String description, Supplier<
319364 R result = handler .get ();
320365 return CompletableFuture .completedFuture (formatResult (result , mapper ));
321366 };
322- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
367+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
323368 }
324369
325370 /**
@@ -361,7 +406,7 @@ public static <T1, R> ToolDefinition from(String name, String description, Param
361406 R result = handler .apply (arg1 );
362407 return CompletableFuture .completedFuture (formatResult (result , mapper ));
363408 };
364- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
409+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
365410 }
366411
367412 /**
@@ -409,7 +454,7 @@ public static <T1, T2, R> ToolDefinition from(String name, String description, P
409454 R result = handler .apply (arg1 , arg2 );
410455 return CompletableFuture .completedFuture (formatResult (result , mapper ));
411456 };
412- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
457+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
413458 }
414459
415460 // ------------------------------------------------------------------
@@ -458,7 +503,7 @@ public static <R> ToolDefinition fromAsync(String name, String description,
458503 }
459504 return future .thenApply (result -> formatResult (result , mapper ));
460505 };
461- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
506+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
462507 }
463508
464509 /**
@@ -506,7 +551,7 @@ public static <T1, R> ToolDefinition fromAsync(String name, String description,
506551 }
507552 return future .thenApply (result -> formatResult (result , mapper ));
508553 };
509- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
554+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
510555 }
511556
512557 /**
@@ -551,7 +596,7 @@ public static <T1, T2, R> ToolDefinition fromAsync(String name, String descripti
551596 }
552597 return future .thenApply (result -> formatResult (result , mapper ));
553598 };
554- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
599+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
555600 }
556601
557602 // ------------------------------------------------------------------
@@ -594,7 +639,7 @@ public static <R> ToolDefinition fromWithToolInvocation(String name, String desc
594639 R result = handler .apply (invocation );
595640 return CompletableFuture .completedFuture (formatResult (result , mapper ));
596641 };
597- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
642+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
598643 }
599644
600645 /**
@@ -640,7 +685,7 @@ public static <T1, R> ToolDefinition fromWithToolInvocation(String name, String
640685 R result = handler .apply (arg1 , invocation );
641686 return CompletableFuture .completedFuture (formatResult (result , mapper ));
642687 };
643- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
688+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
644689 }
645690
646691 // ------------------------------------------------------------------
@@ -689,7 +734,7 @@ public static <R> ToolDefinition fromAsyncWithToolInvocation(String name, String
689734 }
690735 return future .thenApply (result -> formatResult (result , mapper ));
691736 };
692- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
737+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
693738 }
694739
695740 /**
@@ -741,7 +786,7 @@ public static <T1, R> ToolDefinition fromAsyncWithToolInvocation(String name, St
741786 }
742787 return future .thenApply (result -> formatResult (result , mapper ));
743788 };
744- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
789+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
745790 }
746791
747792 // ------------------------------------------------------------------
0 commit comments