Add history and notes tools for token-budget sessions (#39827)

## Why

Token-budget sessions need a way to recover prior conversation context and preserve working state across context-window transitions.

## What changed

- Add direct-model `history` tools for listing windows and items, reading items, and searching conversation contents.
- Add direct-model `notes` tools for listing, reading, searching, appending, and writing persistent notes.
- Route tool calls through the configured Codex backend with trusted session and agent context, bounded request arguments, and truncation-aware output handling.
- Expose the extension when `features.token_budget.use_history_notes_history` is enabled with an OpenAI provider and Codex backend authentication.

## Testing

- Cover tool registration, configuration changes, provider and authentication requirements, backend request context, encrypted output preservation, and request and response limits.

GitOrigin-RevId: 43b259f01014ba3f30803dd7cd5634942407a9bb
This commit is contained in:
pmccrary-oai authored and copyberry committed 2026-08-21 01:24:52 +00:00
1 parent f20b63e85c
commit daa48072f4
21 files changed
+1232 -6

No files matched your search

+14 -5
View File
@@ -13,11 +13,16 @@ pub(super) fn has_explicit_settings(config: &Config) -> bool {
.get("features")
.and_then(|features| features.get("token_budget"))
.and_then(|token_budget| token_budget.as_table())
.is_some_and(|settings| settings.keys().any(|key| key != "enabled"))
|| config
.token_budget
.as_ref()
.is_some_and(|token_budget| token_budget != &TokenBudgetConfig::default())
.is_some_and(|settings| {
settings
.keys()
.any(|key| !matches!(key.as_str(), "enabled" | "use_history_notes_history"))
})
|| config.token_budget.as_ref().is_some_and(|token_budget| {
let mut settings = token_budget.clone();
settings.use_history_notes_history = false;
settings != TokenBudgetConfig::default()
})
}
pub(super) fn apply_model_defaults(config: &mut Config, model_info: &ModelInfo) {
@@ -34,6 +39,10 @@ pub(super) fn apply_model_defaults(config: &mut Config, model_info: &ModelInfo)
};
let token_budget = TokenBudgetConfig {
use_history_notes_history: config
.token_budget
.as_ref()
.is_some_and(|token_budget| token_budget.use_history_notes_history),
reminder_threshold_tokens: Some(model_defaults.reminder_threshold_tokens),
reminder_message_template: model_defaults.reminder_message_template.clone(),
guidance_message: Some(model_defaults.guidance_message.clone()),