Why Context Matters for AI Agents: Giving the Right Information Beats Giving Less
The article analyses how CodeGraph and RTK tools affect token consumption in multi‑agent AI workflows, showing that reducing local output does not always lower total cost and that optimal context delivery—when, to whom, and for how long—is crucial for efficient agent performance.
Background
Tencent Cloud LightWeight Cloud provides a multi‑agent workflow called Devflow . A medium‑size task (adding a comment section to the SkillHub platform) consumed about 24.8 million tokens (≈ 202 CNY), slightly higher than the original run.
Evaluation Framework
Both CodeGraph and RTK were examined using three questions:
Local output: How much does the tool reduce the content sent to the model?
Action path: After shortening the output, which steps does the Agent skip or add?
Overall result: Does the entire task consume fewer tokens, less time, or lower cost?
1. CodeGraph – a code‑map tool
CodeGraph returns structural clues (callers, impact range) for a given symbol, aiming to replace manual rg, grep, find, nl, sed searches.
Local output : Non‑cached input dropped from 195,311 to 125,926 tokens (‑35.5 %). Total input fell only from 732,783 to 728,806 tokens (‑0.5 %).
Action path : The map helps locate entry files and callers, but Agents still need to verify details in the source code.
Overall result :
When the task revolves around a single symbol, two structure queries replace many text searches and total tokens drop by 80 % .
For a full call‑chain task, the map only provides navigation; total tokens increase by 95.8 % because the original searches remain and the map adds extra queries.
Conclusion: CodeGraph reduces the “find‑the‑road” cost but does not guarantee end‑to‑end token savings.
2. RTK – terminal output compressor
RTK rewrites commands such as rg, test runners, and logs to produce a shorter summary.
Local output : Terminal characters fell from 7,917,979 to 4,735,635 (‑40.19 %).
Overall result : Across 12 real coding tasks (24 pair runs), total tokens rose from 42,258,331 to 44,045,370 (+4.23 %). Normalized per task, RTK increased tokens by 5.84 % on average. Thirteen pairs were more expensive, eleven cheaper.
Process metrics showed command events grew from 345 to 441, file‑change events from 110 to 133, test events from 92 to 126, and test failures from 31 to 56. Over 98 % of the extra tokens came from the input side.
In a “prevent sync downgrade” case, RTK reduced terminal output by 48.47 % but overall cost rose only 1.24 % while variance increased 2.36×. Manual inspection revealed that RTK filtered out all marked key clues (158 → 0), confirming that compression can discard essential information.
Conclusion: Shorter terminal output does not automatically translate to lower total cost.
3. Context Optimizations Beyond Tools
To avoid repeatedly moving large reports between agents, handoff information was split into:
Brief notes: Summaries, decisions, and artifact paths passed between roles.
Full artifacts: Stored under artifacts/ and referenced by path only.
CodeGraph maps are generated once during analysis and reused by downstream agents, preventing each role from re‑searching the code base.
RTK is enabled per scenario via a hook ( rtk rewrite). The hook classifies commands into three suitability levels and aborts RTK‑based search if expected clues are missing, falling back to the original command.
The workflow is orchestrated by a state‑management script ( devflow_state.py) and automatic dispatch hooks, keeping the model focused on design, implementation, and review while the program handles state transitions, deduplication, and routing.
4. Final Insights
Token savings depend on delivering the right context at the right moment to the right agent and on how long that context remains in the model window.
Context information density = (truly relevant, executable, verifiable information) ÷ (all context entering the model window)
Three guiding questions emerged:
When should information be provided?
Who should see it?
How long should it be retained?
Key takeaways:
Identify stages that consume most tokens – reasoning vs. history movement.
Check whether tool outputs are repeatedly carried forward or trigger extra searches.
Replace long contents with “short summary + artifact path” where possible, and let a state machine handle fixed actions.
Overall conclusion: “Give the right context” matters more than merely reducing the amount of context.
Repository: https://github.com/tencent/loopforge
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Tencent Cloud Developer
Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
