feat: reduce agent token usage by 84% per deployment#10
Merged
raghavyuva merged 1 commit intomainfrom Apr 8, 2026
Merged
Conversation
- Add TokenLimiterProcessor (128K) and ToolResultPruner to strip search_tools/load_tool noise from conversation context - Introduce queryKeys in tool-factory for correct param routing, fixing add_application_domain error→retry loops - Move createProject and generateRandomSubdomain to core tools, embed domain/monitoring rules in system prompt - Fix workspace-factory SKILLS_SOURCE path via import.meta.url so skills load correctly in both dev and Docker - Add recursive compaction in compact-output for nested objects - Consolidate agent architecture: single delegateTool, instruction skills, trimmed workspace tools - Default log level to info in production Reduces simple deploy from 724K to 113K input tokens ($0.89→$0.13).
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
delegateTool, instruction skills loaded on demand, trimmed workspace toolsChanges
Context pruning (biggest win)
TokenLimiterProcessor(128K cap) to prevent unbounded context growth within a runToolResultPrunerprocessor to strip transientsearch_tools/load_toolresults from conversation historyTool routing fixes
queryKeysintool-factory.tsto correctly routeidas a query param instead of body, fixingadd_application_domain400 errors that caused retry spiralscreateProjectandgenerateRandomSubdomainto core tools so they're always available without search/load overheadSkill loading fix
SKILLS_SOURCEpath inworkspace-factory.tsusingimport.meta.urlinstead ofprocess.cwd()— resolves correctly in both dev (tsx) and production (Docker bundled.mjs)Response compaction
compact-output.tswith recursive nested object flattening (e.g. GitHubownerobjects)Production logging
infoin production,debugin developmentTest plan
mastra build)import.meta.urlresolves correctly in Docker layout (/app/.mastra/output/→../../skills→/app/skills/)hasSkills: truein workspace logs)add_application_domainneeded)