feat: add opt-in GCF output format for 62% fewer tokens on tool responses#1290
Open
blackwell-systems wants to merge 1 commit into
Open
feat: add opt-in GCF output format for 62% fewer tokens on tool responses#1290blackwell-systems wants to merge 1 commit into
blackwell-systems wants to merge 1 commit into
Conversation
…nses Add CGC_OUTPUT_FORMAT=gcf environment variable to encode tool responses using GCF (Graph Compact Format) instead of JSON. Measured on CodeGraphContext's own data shapes: - find_callers (12 results): 63.9% fewer tokens - find_dead_code (15 functions): 60.2% fewer tokens - Cypher query (20 records): 61.5% fewer tokens - complex_functions (10 results): 66.7% fewer tokens - class_hierarchy (8 classes): 60.6% fewer tokens - Overall: 62.5% reduction GCF is an optional dependency (pip install gcf-python). Falls back to JSON silently if not installed. Zero behavior change without the env var.
|
@blackwell-systems is attempting to deploy a commit to the shashankss1205's projects Team on Vercel. A member of the Team first needs to authorize it. |
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
CGC_OUTPUT_FORMAT=gcfenv var to encode tool responses using GCF instead of JSONpip install gcf-python); falls back to JSON silently if not installedWhy this matters for CodeGraphContext
Code graph query results (symbols, callers, callees, complexity, class hierarchies) are pure structured data with consistent schemas and repeated field names. This is the exact data shape where GCF saves the most tokens: keys declared once in a header, values pipe-delimited per row.
Measured savings (on CGC data shapes)
Measured with tiktoken (cl100k_base) on response shapes matching
analyze_code_relationships,find_dead_code,execute_cypher_query,find_most_complex_functions, and class hierarchy queries.Comprehension: LLMs read GCF better than JSON
GCF doesn't just use fewer tokens; models understand it more accurately:
No format instructions or primers needed. The model reads GCF natively.
Full eval methodology: eval/README.md
What is GCF?
GCF (Graph Compact Format) encodes structured data with positional fields: keys declared once in the header, values pipe-delimited per row.
GCF was originally extracted from a code intelligence engine (knowing) with the same graph-structured data patterns as CodeGraphContext.
Changes
src/codegraphcontext/utils/gcf_encoder.pysrc/codegraphcontext/server.pyencode_response()instead ofjson.dumps()pyproject.tomlgcf-pythonadded as optional dependency (pip install codegraphcontext[gcf])README.mdtests/unit/tools/test_gcf_encoder.pyUsage
Test plan
Adoption
GCF is already in production at OmniRoute (6.1K stars), NetClaw (556 stars), NeuroNest (commercial IDE), Open Data Products SDK (Linux Foundation), and ctx (510 stars). Full adopter list: gcformat.com/ecosystem/adopters
Notes
Happy to refactor the implementation however you see fit. If you'd prefer a different config surface (CLI flag, config file setting, per-tool toggle), just let me know and I'll adjust.