Apply model catalog overrides to history, notes, and context tools (#56313)

## What changed

- Read optional tool descriptions and parameter schemas for `history`, `notes`, `new_context`, and `get_context_remaining` from the acting model's catalog messages.
- Support catalog namespace descriptions for history and notes, preserving explicit empty and whitespace descriptions.
- Share catalog override handling across native tools and MCP resource helpers. Keep bundled schemas when overrides are invalid, preserve encrypted parameters, and leave tool identity and transport fields unchanged.

## Testing

Add coverage for sparse catalog serialization, schema fallback and encryption preservation, per-step tool definitions, and context tool updates when switching models. Extend outgoing-request tests to verify history and notes overrides while retaining history image attachments.

GitOrigin-RevId: 1adac8b5009f95c91adba491f20a4e2e2dc91475
This commit is contained in:
rhan-oai
2026-10-23 00:46:28 +00:00
committed by copyberry
parent 5b792948f9
commit e103bbc06f
35 changed files with 822 additions and 114 deletions
+16 -1
View File
@@ -35,6 +35,11 @@ use crate::protocol::MultiAgentVersion;
mod access_programs;
mod incremental_tools;
pub use incremental_tools::IncrementalToolMessages;
#[path = "openai_models/memento_v2.rs"]
mod memento_v2;
pub use memento_v2::ContextManagementToolMessages;
pub use memento_v2::HistoryToolMessages;
pub use memento_v2::NotesToolMessages;
#[path = "openai_models/guardian.rs"]
mod guardian;
pub use guardian::GuardianModelPolicy;
@@ -585,6 +590,15 @@ pub struct ConfirmationPolicies {
/// Model-owned tool messages and description prefixes.
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
pub struct ToolMessages {
/// Native Memento V2 history tool definitions, independent of runtime namespace aliases.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub history: Option<HistoryToolMessages>,
/// Native Memento V2 notes tool definitions.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub notes: Option<NotesToolMessages>,
/// Memento V2 context-window control tool definitions.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub context_management: Option<ContextManagementToolMessages>,
/// Optional wording for incremental catalog notices.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub incremental_tools: Option<IncrementalToolMessages>,
@@ -634,7 +648,8 @@ pub struct ToolMessage {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
/// Complete JSON Schema encoded as a string. Consumed by Multi-Agent V2 tools, Code Mode wait,
/// request_user_input_async (the send_user_message_async catalog key), and MCP resource helpers.
/// request_user_input_async (the send_user_message_async catalog key), MCP resource helpers,
/// and Memento V2 tools.
/// Uses the harness's supported schema subset; unrecognized keywords are ignored.
/// Missing, null, invalid or unsupported structures, or a root without `type: "object"`
/// retains the harness parameters. Schema semantics must remain API-compatible.
@@ -0,0 +1,52 @@
//! Sparse Memento V2 tool definitions. Runtime data remains with consumers.
use super::ToolMessage;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
use ts_rs::TS;
/// Model-owned history namespace and public tool definitions.
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
pub struct HistoryToolMessages {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub namespace_description: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub list_windows: Option<ToolMessage>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub list_items: Option<ToolMessage>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub read_item: Option<ToolMessage>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub search_contents: Option<ToolMessage>,
}
/// Model-owned notes namespace and public tool definitions.
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
pub struct NotesToolMessages {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub namespace_description: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub list_files_by_prefix: Option<ToolMessage>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub read_file: Option<ToolMessage>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub search_contents: Option<ToolMessage>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub append_to_file: Option<ToolMessage>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub write_file: Option<ToolMessage>,
}
/// Model-owned context-window control tool definitions.
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
pub struct ContextManagementToolMessages {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub new_context: Option<ToolMessage>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub get_context_remaining: Option<ToolMessage>,
}
#[cfg(test)]
#[path = "memento_v2_tests.rs"]
mod tests;
@@ -0,0 +1,18 @@
use crate::openai_models::ModelMessages;
use pretty_assertions::assert_eq;
use serde_json::json;
#[test]
fn memento_catalog_round_trip_preserves_sparse_tools_and_explicit_empty() {
for tools in [
json!({}),
json!({
"history": {"namespace_description": "", "read_item": {"description": "", "parameters": "not JSON"}},
"notes": {"read_file": {"parameters": "{}"}},
"context_management": {"new_context": {"description": "catalog"}}
}),
] {
let messages: ModelMessages = serde_json::from_value(json!({"tools": tools})).unwrap();
assert_eq!(serde_json::to_value(messages.tools).unwrap(), tools);
}
}