Add a configurable skill catalog token budget (#38978)

## What changed

- Add `[skills].max_context_tokens` to override the token budget used to render the available-skills catalog.
- Require a positive value and cap configured budgets at 10,000 tokens.
- Preserve the existing default of 2% of the model context window when the option is unset.

## Testing

- Cover configuration parsing, override behavior, the 10,000-token cap, and catalog rendering within the configured budget.

GitOrigin-RevId: f29ddcb57fc2d800c0006d03e1c33cbe3ab6272d
This commit is contained in:
jif authored and copyberry committed 2026-08-17 10:01:59 +00:00
1 parent c6058ccaa9
commit 632e35ce8d
19 files changed
+126 -7

No files matched your search

+13 -3
View File
@@ -194,17 +194,27 @@ fn description_selection_follows_render_policy() {
#[test]
fn catalog_budget_uses_context_percentage_or_character_fallback() {
assert_eq!(
skill_metadata_budget(Some(100_000)),
skill_metadata_budget(Some(100_000), /*max_context_tokens*/ None),
SkillMetadataBudget::Tokens(2_000)
);
assert_eq!(
skill_metadata_budget(Some(400_000)),
skill_metadata_budget(Some(400_000), /*max_context_tokens*/ None),
SkillMetadataBudget::Tokens(8_000)
);
assert_eq!(
skill_metadata_budget(/*context_window*/ None),
skill_metadata_budget(
/*context_window*/ None, /*max_context_tokens*/ None
),
SkillMetadataBudget::Characters(8_000)
);
assert_eq!(
skill_metadata_budget(Some(100_000), NonZeroUsize::new(5_000)),
SkillMetadataBudget::Tokens(5_000)
);
assert_eq!(
skill_metadata_budget(/*context_window*/ None, NonZeroUsize::new(50_000)),
SkillMetadataBudget::Tokens(10_000)
);
}
#[test]