Use case · AI agents · Measured

Give your AI agent the right 4,000 tokens — not 140,000

An AI agent asked to change one function doesn't need your whole codebase. It needs the verified neighborhood of its task — smaller, cheaper, and correct by construction. We measured it on a real project.

97% fewer tokens 35× more signal per token $2.04 saved per Opus 5 task 100% verified
Quick start (3 commands): AI_CONTEXT.md →  ·  py-code-visualizer context . --task "describe your task" --budget-tokens 4000  then paste the output into your AI.

Measured on httpx — a real open-source Python project

1,076 functions · 976 call edges · fixed a real bug (NO_PROXY IPv6 handling). Reproduce: git clone https://github.com/encode/httpx && py-code-visualizer context . --task "..."

97%
fewer tokens than the full source
35×
more relevant code per token vs the full source
<1 s
to build the context pack
Token count, cost and signal density by context-selection approach on httpx
Approach Tokens Claude Opus 5 cost Signal/1k tokens
Feed the full source 139,697 $2.10
Keyword grep (3 matched files) 24,652 $0.37
pyvisualizer --task ~4,000 $0.06 35×

Costs use publicly listed input-token pricing (~$15/1M for Claude Opus 5). Signal = function-recall per 1,000 tokens; measured by comparing the pack's functions against the functions touched by the actual bug fix.

An AI agent navigating your codebase from scratch re-derives the architecture on every task — paying for thousands of tokens to reconstruct facts it could have looked up, and still getting them wrong. A context pack flips that: the structure is already parsed, every edge is real, and the pack is 97% smaller.

1

Describe the task. Get a focused pack.

You don't need to know the function name. Describe what you're about to fix — pyvisualizer maps the prose onto seed functions (symbols you name are highest priority, then lexical matches) and expands through the verified call graph:

$ py-code-visualizer context . --task "orders must be audited before persisting" --budget-tokens 4000
# Context Pack — yourproject - Task: orders must be audited before persisting - Strategy: hybrid - Included functions: 9 (omitted 0 under budget) - Estimated size: ~365 tokens (pack) vs ~54,000 tokens (full source) — ~99.3% smaller ## Seeds (task → code, best first) - `core.persist` — 165.7 · symbol - `service.audit` — 78.2 · bm25 ## Function bodies (top-ranked) ### `core.persist` ```python def persist(record): audit(record) db.write(record) ``` ## Functions - `core.persist(record)` — core.py:7 _(full source above)_ - `service.place_order(order)` — service.py:7 … ## Verified calls (caller → callee · confidence · provenance) - `service.place_order` → `core.persist` · resolved · service.py:8 - `core.persist` → `service.audit` · resolved · core.py:9 … ## Circular dependencies touching this area - `persist → audit → persist`

Every function is real, every call edge is parsed from the AST with a file:line. Full source is included for top-ranked functions while the budget allows; the agent opens the cited line for the rest. Circular dependencies are surfaced automatically.

Already know the function name? Use --focus:

$ py-code-visualizer context . --focus core.persist --budget-tokens 4000
2

The saving is model-agnostic — the dollar amount scales with price

97% fewer tokens means 97% cheaper context for every model. With frontier models, the absolute savings per task are significant:

Input-token cost per task with and without a context pack, by model
Model Without pack With pack Saved / task Team of 5 (20 tasks/day/month)
Claude Opus 5 $2.10 $0.06 $2.04 $6,100 / mo
Claude Sonnet 5 $0.42 $0.01 $0.41 $1,200 / mo
GPT-4o $0.70 $0.02 $0.68 $2,000 / mo
Gemini 1.5 Pro $0.17 $0.005 $0.17 $500 / mo

Input-token cost only, using publicly listed pricing. Full-source cost: 139,697 tokens (httpx baseline). Pack cost: ~4,000 tokens. Output tokens (model response) are the same either way.

3

Make sure the agent actually uses it

A pack only helps if the agent reaches for it. export writes the verified graph and injects a section into AGENTS.md — the file Claude Code, Copilot, and Cursor all read automatically — telling the agent to query the verified graph before deriving architecture from source.

$ py-code-visualizer export --for-ai .
Wrote ARCHITECTURE.json, ARCHITECTURE.md and AGENTS.md

Wire it into CI with py-code-visualizer export --check so a PR fails if the committed ground truth goes stale — the agent always reads current facts.

Prefer the agent to query mid-task? Run the MCP server — Claude Code, Cursor, or any MCP client gets search_code, context_pack, and impact against the live verified graph:

$ pip install 'py-code-visualizer[mcp]' && pyvisualizer-mcp .

What you got. Your agents consume a verified, task-scoped slice of the architecture — 97% smaller than raw source, 35× more signal per token than reading everything, with a file:line on every fact and not a single guessed edge. On a team of 5 developers running 20 AI tasks per day, that is $1,200–$6,100 per month back in your budget depending on your model.

Methodology — how the numbers were measured

Codebase: httpx v0.23.x commit 7d7c4f15 (pre-fix), 60 Python files, 1,076 functions, 976 call edges.

Task: Fix the NO_PROXY IPv6 bug (issue #2660). Ground truth: the 3 functions touched or needed to understand the fix — get_environment_proxies, urlparse, encode_host.

Metric: function-recall-per-1,000-tokens. Recall = (ground-truth functions in pack) ÷ 3. Token count = pack content characters ÷ 4 (standard estimate).

Conditions tested: full source (all .py files), keyword grep (files matching NO_PROXY/IPv6 keywords), pyvisualizer --strategy text (BM25-only), --strategy hybrid (BM25 + graph expansion). Two task descriptions: one naming functions explicitly, one using symptom-level prose only.

Best result: --strategy text, symptom-only description: recall = 1.00, 4,076 tokens, recall/1k = 0.245. All 3 ground-truth functions found.

Reproducibility: Commands are deterministic — same repo, same task, same output every run.

Built by Syed Mohd Haider Rizvi · LinkedIn · Source code

← All use cases