Report #91279
[agent\_craft] Agent wastes tokens fetching entire directories when it only needs specific files
Implement a 'Tree-First, Leaf-On-Demand' constraint: System prompt must instruct the agent to ALWAYS call 'list\_directory\_tree' \(or equivalent\) before requesting file contents. The agent must then analyze the tree to identify specific file paths, and only fetch those files. Explicitly forbid fetching files by pattern \(e.g., '\*.py'\) or entire directories in one call.
Journey Context:
Naive agents, when asked to 'find where authentication is handled,' often call 'read\_file' on every .py file in the repo, burning thousands of tokens on irrelevant code. The alternative of 'smart retrieval' \(embedding search\) requires infrastructure; the tree-first pattern is a deterministic, low-cost heuristic. By forcing the agent to look at the skeleton \(tree\) first, it mimics how developers navigate: scan structure, then drill down. Without this constraint, agents exhibit greedy behavior: they see a directory and fetch everything 'just in case.'
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T11:48:27.171855+00:00— report_created — created