Open
Conversation
4423b67 to
5eb699e
Compare
Refactor Read tool to use token counting instead of line/character limits for better context management. This provides more accurate control over content size sent to LLMs. Changes: - Replace read_line_limit and line_character_limit config with read_max_tokens (default 25,000) - Add token_safeguard method to Read tool for enforcing token limits - Update ReadTracker to consistently read file content matching Read tool behavior - Improve tool detection in ContextManager using system reminder patterns - Update documentation and all related tests
5eb699e to
8d038e4
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR introduces token-based safeguards for file reading to prevent AI agents from accidentally consuming their entire context window with large files. By enforcing a strict token limit, we force agents to use pagination (reading in subsets) or search tools when dealing with large files, ensuring they maintain enough context for reasoning and other tasks.
Key Changes
🛡️ Token Safeguards
read_line_limit(2000 lines) andline_character_limit(2000 chars/line) withread_max_tokens(default 25,000 tokens).Readtool now checks token count before returning content. If the content exceeds the limit, it rejects the request with a helpful error guiding the agent to:offsetandlimitparameters to read file in chunksGreptool to search for specific content📖 Read Tool Overhaul
Readtool output. Now returns raw file content, simplifying editing and copy-pasting.ReadTrackernow reads files the same way asReadtool (UTF-8 first, fall back to binary).🧠 Memory & Skills
separator). Now returns raw content.🔧 Tool Detection & Descriptions
Readoutput by system reminder instead of line numbers (which are now removed).EditandMultiEditdescriptions to remove references to line number prefixes.Configuration Updates
SwarmSDK.config.read_max_tokens(default: 25,000 tokens)SwarmSDK.config.read_line_limit(was 2000 lines)SwarmSDK.config.line_character_limit(was 2000 chars)Documentation Updates
read_max_tokensparameterTest Coverage
Readtool tests updated for raw output and token safeguardsMemoryReadtests updated for raw output formatLoadSkilltests updated for raw output formatScratchpadReadtests updated (implicit via integration)Configtests updated for new parameterContextManagertests updated for new tool detectionReadTrackerfunctionality preserved with consistent file reading