Repository navigation
💡 Pre-Agentic Data Gathering Pipeline for 60%+ Token Savings #563
Replies: 2 comments
|
📋 Initiative planned by the BMAD Scrum Master (Bob). Epic #1101 — Pre-agentic context prefetch for the PR-review cascade: eliminate redundant in-loop gh fetches across the agentic tiers, flag-gated and ET/eval-verified 6 stories created (inert — labelled
Open questions for review:
Review the epic and its sub-issue DAG, adjust as needed, then add |
|
Good analysis — the same pattern applies beyond agent workflows to any data pipeline that feeds LLMs. Pre-gathering deterministic context (enrichment fields, quality scores, metadata) before the token-consuming stage mirrors what we do at Social Intel. Our enrichment pipeline runs 25 deterministic checks per post — sentiment, topics, signals, bot detection — all computed before any LLM touches the data. The data ships pre-structured, so you're not burning tokens on discovery or extraction. |
Uh oh!
There was an error while loading. Please reload this page.
Summary
Restructure agent workflows to move all deterministic data fetching (git diff, CI status, label checks, file listing, PR metadata) into shell-based preflight steps before invoking the LLM. Feed pre-gathered context as structured input rather than making the agent discover it via tool calls, eliminating tool-invocation token overhead and reasoning-loop waste.
Market Signal
GitHub's own engineering team achieved 62% Effective Token (ET) reduction in their agentic workflows by moving pre-agentic data gathering into workflow setup steps (documented in their May 2026 blog post "Improving token efficiency in GitHub Agentic Workflows"). Their Auto-Triage workflow showed sustained 62% ET savings across 109 post-fix runs. Security Guard achieved 43%, Smoke Claude 59%. The pattern is now considered a production best practice for LLM-based CI/CD. Key insight: every MCP tool schema adds 8-12KB of context per call, and unused tools waste context budget without providing value.
User Signal
The Token Cost Observatory discussion (#332) already identified pre-agentic optimization as a goal. Weekly token reports (issue #464) show ongoing cost visibility and awareness. The project already has
dev-lead-preflight.shproving the pattern works at small scale, but it has not been systematically applied to the PR review pipeline — the highest-volume agent workflow.Technical Opportunity
The review pipeline currently has the LLM fetch diffs, CI status, and PR metadata via tool calls inside the reasoning loop. Each tool call adds:
Moving these to shell steps in
review-one-pr.shand passing as structured context would eliminate this overhead. The existingdev-lead-preflight.shpattern provides a proven template. GitHub's approach:ghCLI commands in a setup step to gather all deterministic dataAssessment
Adversarial Review
Strongest objection: Pre-gathered data could become stale if a force push occurs between the preflight step and the agent's analysis. Refactoring existing review scripts risks introducing bugs in a production pipeline.
Rebuttal: Staleness is mitigable — gather data at the start of each agent turn, not minutes before. The triage tier (cheap, fast) can validate freshness by checking the HEAD SHA matches what was pre-fetched before the expensive deep review runs. Engineering risk is bounded because
dev-lead-preflight.shalready proves the pattern, and the review pipeline's multi-tier architecture means changes can be validated at the triage tier before rolling to deeper tiers. Start with the highest-volume, most deterministic reads (PR metadata, labels, file list) and expand incrementally.Suggested Next Step
Audit
review-one-pr.shandreview-batch.shfor all LLM-initiated data fetches. Categorize each as deterministic (can preflight) vs. dynamic (must stay in-loop). Implement preflight gathering for deterministic reads and measure ET savings via the Token Cost Observatory.All reactions