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,32 @@ 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 forwards
191+ * verbatim to the runtime. The keys are not part of the stable public API; the
192+ * runtime may recognize specific keys to inform host-specific behavior.
193+ *
194+ * @param name
195+ * the unique name of the tool
196+ * @param description
197+ * a description of what the tool does
198+ * @param schema
199+ * the JSON Schema as a {@code Map}
200+ * @param handler
201+ * the handler function to execute when invoked
202+ * @param metadata
203+ * the opaque metadata map forwarded to the runtime
204+ * @return a new tool definition with the metadata set
205+ * @since 1.0.7
206+ */
207+ public static ToolDefinition createWithMetadata (String name , String description , Map <String , Object > schema ,
208+ ToolHandler handler , Map <String , Object > metadata ) {
209+ return new ToolDefinition (name , description , schema , handler , null , null , null , metadata );
180210 }
181211
182212 /**
@@ -247,7 +277,7 @@ public static List<ToolDefinition> fromClass(Class<?> clazz) {
247277 */
248278 @ CopilotExperimental
249279 public ToolDefinition overridesBuiltInTool (boolean value ) {
250- return new ToolDefinition (name , description , parameters , handler , value , skipPermission , defer );
280+ return new ToolDefinition (name , description , parameters , handler , value , skipPermission , defer , metadata );
251281 }
252282
253283 /**
@@ -261,7 +291,7 @@ public ToolDefinition overridesBuiltInTool(boolean value) {
261291 */
262292 @ CopilotExperimental
263293 public ToolDefinition skipPermission (boolean value ) {
264- return new ToolDefinition (name , description , parameters , handler , overridesBuiltInTool , value , defer );
294+ return new ToolDefinition (name , description , parameters , handler , overridesBuiltInTool , value , defer , metadata );
265295 }
266296
267297 /**
@@ -275,7 +305,23 @@ public ToolDefinition skipPermission(boolean value) {
275305 */
276306 @ CopilotExperimental
277307 public ToolDefinition defer (ToolDefer value ) {
278- return new ToolDefinition (name , description , parameters , handler , overridesBuiltInTool , skipPermission , value );
308+ return new ToolDefinition (name , description , parameters , handler , overridesBuiltInTool , skipPermission , value ,
309+ 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.7
320+ */
321+ @ CopilotExperimental
322+ public ToolDefinition metadata (Map <String , Object > value ) {
323+ return new ToolDefinition (name , description , parameters , handler , overridesBuiltInTool , skipPermission , defer ,
324+ value );
279325 }
280326
281327 // ------------------------------------------------------------------
@@ -319,7 +365,7 @@ public static <R> ToolDefinition from(String name, String description, Supplier<
319365 R result = handler .get ();
320366 return CompletableFuture .completedFuture (formatResult (result , mapper ));
321367 };
322- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
368+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
323369 }
324370
325371 /**
@@ -361,7 +407,7 @@ public static <T1, R> ToolDefinition from(String name, String description, Param
361407 R result = handler .apply (arg1 );
362408 return CompletableFuture .completedFuture (formatResult (result , mapper ));
363409 };
364- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
410+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
365411 }
366412
367413 /**
@@ -409,7 +455,7 @@ public static <T1, T2, R> ToolDefinition from(String name, String description, P
409455 R result = handler .apply (arg1 , arg2 );
410456 return CompletableFuture .completedFuture (formatResult (result , mapper ));
411457 };
412- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
458+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
413459 }
414460
415461 // ------------------------------------------------------------------
@@ -458,7 +504,7 @@ public static <R> ToolDefinition fromAsync(String name, String description,
458504 }
459505 return future .thenApply (result -> formatResult (result , mapper ));
460506 };
461- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
507+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
462508 }
463509
464510 /**
@@ -506,7 +552,7 @@ public static <T1, R> ToolDefinition fromAsync(String name, String description,
506552 }
507553 return future .thenApply (result -> formatResult (result , mapper ));
508554 };
509- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
555+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
510556 }
511557
512558 /**
@@ -551,7 +597,7 @@ public static <T1, T2, R> ToolDefinition fromAsync(String name, String descripti
551597 }
552598 return future .thenApply (result -> formatResult (result , mapper ));
553599 };
554- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
600+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
555601 }
556602
557603 // ------------------------------------------------------------------
@@ -594,7 +640,7 @@ public static <R> ToolDefinition fromWithToolInvocation(String name, String desc
594640 R result = handler .apply (invocation );
595641 return CompletableFuture .completedFuture (formatResult (result , mapper ));
596642 };
597- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
643+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
598644 }
599645
600646 /**
@@ -640,7 +686,7 @@ public static <T1, R> ToolDefinition fromWithToolInvocation(String name, String
640686 R result = handler .apply (arg1 , invocation );
641687 return CompletableFuture .completedFuture (formatResult (result , mapper ));
642688 };
643- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
689+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
644690 }
645691
646692 // ------------------------------------------------------------------
@@ -689,7 +735,7 @@ public static <R> ToolDefinition fromAsyncWithToolInvocation(String name, String
689735 }
690736 return future .thenApply (result -> formatResult (result , mapper ));
691737 };
692- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
738+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
693739 }
694740
695741 /**
@@ -741,7 +787,7 @@ public static <T1, R> ToolDefinition fromAsyncWithToolInvocation(String name, St
741787 }
742788 return future .thenApply (result -> formatResult (result , mapper ));
743789 };
744- return new ToolDefinition (name , description , schema , toolHandler , null , null , null );
790+ return new ToolDefinition (name , description , schema , toolHandler , null , null , null , null );
745791 }
746792
747793 // ------------------------------------------------------------------
0 commit comments