Repository navigation
feat: TOON-lite compact context + memory warn threshold #31847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
haibaoliu
wants to merge
5
commits into
NousResearch:main
Choose a base branch
from
haibaoliu:feat/toon-lite-compact-context
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
30c0545
feat: TOON-lite compact context encoding for system prompt
MacBook d904706
fix: address Copilot review comments for PR #31847
MacBook 3d6e4fc
feat(memory): add memory_warn_pct config for proactive trimming
MacBook e9cb397
chore: ruff format fix
MacBook bb450c9
feat: api_key_command + skill routing table
MacBook File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| """Skill routing table — compact intent→skill mapping for system prompt. | ||
|
|
||
| Replaces the full ``<available_skills>`` block with a routing-oriented format | ||
| that maps categories to skill names. Skill names are self-describing | ||
| (e.g. ``github-code-review``, ``systematic-debugging``) so the model can pick | ||
| the closest match and load the full skill with ``skill_view(name)``. | ||
|
|
||
| Savings vs full listing: ~75 % fewer tokens (~800 vs ~3100 for a typical | ||
| 60-skill installation). | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Dict, List, Tuple | ||
|
|
||
|
|
||
| def _derive_routing_hints( | ||
| skills_by_category: Dict[str, List[Tuple[str, str]]], | ||
| category_descriptions: Dict[str, str], | ||
| ) -> Dict[str, str]: | ||
| """Derive brief routing hints (3-6 words) from category descriptions. | ||
|
|
||
| Truncates long descriptions and falls back to representative skill names | ||
| when the description is missing or irrelevant.""" | ||
| hints: Dict[str, str] = {} | ||
| for category, skills in sorted(skills_by_category.items()): | ||
| if not skills: | ||
| continue | ||
| names = [name for name, _ in skills] | ||
|
|
||
| cat_desc = (category_descriptions.get(category) or "").strip().strip("'\"") | ||
|
|
||
| if cat_desc: | ||
| # Try to extract the most meaningful fragment | ||
| # Category descriptions follow pattern: "Skills for X — ..." or "X skills: ..." | ||
| # We want just the core domain description | ||
| for prefix in ("Skills for ", "Knowledge and Tools for "): | ||
| if cat_desc.startswith(prefix): | ||
| cat_desc = cat_desc[len(prefix):] | ||
| break | ||
| # Take first ~50 chars or up to first period/semicolon | ||
| if len(cat_desc) > 50: | ||
| cut = max(cat_desc[:50].rfind(" "), cat_desc[:50].rfind(","), 30) | ||
| cat_desc = cat_desc[:cut] if cut > 0 else cat_desc[:50] | ||
| hints[category] = cat_desc | ||
| elif len(names) <= 3: | ||
| hints[category] = ", ".join(names) | ||
| else: | ||
| sample = names[:2] | ||
| hints[category] = f"{', '.join(sample)} +{len(names)-2} more" | ||
|
|
||
| return hints | ||
|
|
||
|
|
||
| def format_skills_routing_table( | ||
| skills_by_category: Dict[str, List[Tuple[str, str]]], | ||
| category_descriptions: Dict[str, str] | None = None, | ||
| ) -> str: | ||
| """Build a compact routing table from the skill index. | ||
|
|
||
| Format:: | ||
|
|
||
| ## Skill Router | ||
| category: skill1, skill2, skill3 # routing hint | ||
|
|
||
| The model scans for a matching category, picks a skill name, and calls | ||
| ``skill_view(name)`` for the full instructions. | ||
|
|
||
| Returns empty string if no skills. | ||
| """ | ||
| if not skills_by_category: | ||
| return "" | ||
|
|
||
| category_descriptions = category_descriptions or {} | ||
| hints = _derive_routing_hints(skills_by_category, category_descriptions) | ||
|
|
||
| lines: List[str] = [ | ||
| "## Skill Router", | ||
| "Scan for matching category, load with skill_view(name).", | ||
| "Skill names are descriptive — pick the closest match.", | ||
| "", | ||
| ] | ||
|
|
||
| for category in sorted(skills_by_category.keys()): | ||
| skills = skills_by_category[category] | ||
| if not skills: | ||
| continue | ||
|
|
||
| # Deduplicate and sort | ||
| skill_names = sorted(set(name for name, _ in skills)) | ||
| names_str = ", ".join(skill_names) | ||
| hint = hints.get(category, category) | ||
| lines.append(f" {category}: {names_str} # {hint}") | ||
|
|
||
| lines.append("") | ||
| lines.append( | ||
| "Only proceed without loading a skill if genuinely none are relevant." | ||
| ) | ||
|
|
||
| return "\n".join(lines) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compact branch removes
<available_skills>, buthermes_cli/prompt_size.pyandagent/context_breakdown.pyidentify the skills section only with that tag pair. Update those consumers and add compact-mode accounting tests so diagnostics do not report zero skill usage.