Reduce memory overhead in tool JSON schemas (#54754)

## Why

Schema strings and sequences do not grow after construction, and most schema nodes do not contain maps. Retaining collection capacity and inline optional maps adds unnecessary memory overhead.

## What changed

Store `JsonSchema` strings and sequences as boxed strings and slices, and box optional property and definition maps. Adapt constructors, schema consumers, and existing test expectations to the new representation while preserving the serialized JSON Schema format.

GitOrigin-RevId: 0a249b1ae32932cbbfe3c575c32bfd20b060c303
This commit is contained in:
Charlie Marsh
2026-10-17 01:08:30 +00:00
committed by copyberry
parent 5009a99dfc
commit e16b631d08
7 changed files with 97 additions and 94 deletions
@@ -64,8 +64,8 @@ fn spawn_agent_tool_v2_requires_task_name() {
);
assert!(!properties.contains_key("service_tier"));
assert_eq!(
parameters.required.as_ref(),
Some(&vec!["task_name".to_string(), "message".to_string()])
parameters.required.as_deref(),
Some(["task_name".to_string(), "message".to_string()].as_slice())
);
assert_eq!(
output_schema.expect("spawn_agent output schema").to_value()["required"],
@@ -274,8 +274,8 @@ fn send_message_tool_requires_message_and_has_no_output_schema() {
Some("Relative or canonical task name to message (from spawn_agent).")
);
assert_eq!(
parameters.required.as_ref(),
Some(&vec!["target".to_string(), "message".to_string()])
parameters.required.as_deref(),
Some(["target".to_string(), "message".to_string()].as_slice())
);
assert_eq!(output_schema, None);
}
@@ -315,8 +315,8 @@ fn followup_task_tool_requires_message_and_has_no_output_schema() {
);
assert!(!properties.contains_key("items"));
assert_eq!(
parameters.required.as_ref(),
Some(&vec!["target".to_string(), "message".to_string()])
parameters.required.as_deref(),
Some(["target".to_string(), "message".to_string()].as_slice())
);
assert_eq!(output_schema, None);
}
@@ -262,7 +262,7 @@ fn create_approval_parameters(
let mut additional_permissions = permission_profile_schema();
additional_permissions.description = Some(
"Sandboxed filesystem or network access for this command; only with `sandbox_permissions: \"with_additional_permissions\"`."
.to_string(),
.into(),
);
properties.insert("additional_permissions".to_string(), additional_permissions);
}
@@ -279,7 +279,7 @@ fn permission_profile_schema() -> JsonSchema {
/*required*/ None,
Some(false.into()),
);
schema.description = Some("Filesystem or network access request.".to_string());
schema.description = Some("Filesystem or network access request.".into());
schema
}
@@ -294,7 +294,7 @@ fn network_permissions_schema() -> JsonSchema {
/*required*/ None,
Some(false.into()),
);
schema.description = Some("Network access request.".to_string());
schema.description = Some("Network access request.".into());
schema
}
@@ -325,7 +325,7 @@ fn file_system_permissions_schema() -> JsonSchema {
/*required*/ None,
Some(false.into()),
);
schema.description = Some("Filesystem access request.".to_string());
schema.description = Some("Filesystem access request.".into());
schema
}
+1 -1
View File
@@ -30,7 +30,7 @@ pub(super) fn multi_agent_v2_handler(
&& let Some(properties) = tool.parameters.properties
{
// Argument transport requires these markers even without server encryption config.
for (name, schema) in properties {
for (name, schema) in *properties {
if schema.encrypted == Some(true) {
let property = parameters
.properties