Home›GitHub Copilot›🚀 AIエージェントに渡すHTMLを97.5%圧縮する「Skill設計パターン」

🚀 AIエージェントに渡すHTMLを97.5%圧縮する「Skill設計パターン」This article explains a Skill design pattern for AI agents that strips raw HTML…

元記事を読むRead original articlezenn.dev(新しいタブで開きます)(opens in a new tab)
AI要点サマリSummary highlight

AIエージェントにWebスクレイピングを任せる際、生HTMLをそのまま渡すとトークン消費が膨大になる問題を、専用Skillを設計して構造化データのみを返す手法で90%以上削減できることを解説した記事。

This article explains a Skill design pattern for AI agents that strips raw HTML noise before processing, reducing token consumption by over 90% and cutting API costs when performing web scraping tasks.

本ページの本文と要約は AI による自動生成です。日本語版と英語版は言語ごとに独立して生成されるため、表現や詳しさが異なる場合があります。正確性は元記事 (zenn.dev) をご確認ください。The body and summaries are AI-generated independently for each language, so wording and detail may differ. Verify accuracy at the original source (zenn.dev).

要約と収集メタデータに基づく AI 解説。元記事全文の転載・翻訳ではありません。AI explainer based on the summaries and collected metadata, not a copy or translation of the full source article.

生成AIを使ったコーディング支援ツールにWebスクレイピングを任せると、思わぬコスト増や動作の不安定さに悩まされることがある。Zennのcopilotカテゴリで公開された記事は、専用の「Skill」を設計して構造化データのみを返す手法により、トークン消費を90%以上削減できるとする設計パターンを解説している。なお、同記事はAIを使って執筆されたものである。

記事が問題視するのは、「Claude Code」や「Antigravity CLI」、「Cursor」といったAIエージェントにデータ収集を依頼した際に生じる非効率だ。数万トークンにおよぶ生のHTMLをそのまま読み込ませると、APIコストが一気に膨らむ。加えて、大量のdivやspan、広告コードといった「ノイズ」に肝心のデータが埋もれ、目的の情報を取り出しにくくなる。結果として「DOM要素が見つかりません」といったエラーが頻発し、エージェントが試行錯誤を繰り返すことで、無駄な通信や時間が発生するという。

こうした課題への対処として提案されるのが、HTMLのノイズを事前に取り除き、構造化されたデータだけをエージェントに渡す「Skill」の設計だ。処理前に不要な要素を削ぎ落とすことで、扱うトークン量を大幅に圧縮し、APIコストの削減につなげるという考え方である。生HTMLを直接処理させる場合と比べ、90%以上のトークン削減が見込めると説明されている。

背景として、AIエージェントの利用が広がるなか、入力トークンに応じて課金される料金体系のもとでは、いかに無駄な情報を渡さないかがコスト管理の要点になりつつある。前処理でデータを整形してからモデルに渡すアプローチは、スクレイピングに限らず、長大なドキュメントやログの解析など幅広い場面で有効となる可能性がある。今回のSkill設計パターンは、その具体的な適用例のひとつと位置づけられるだろう。

When AI coding agents such as Claude Code, Antigravity CLI, and Cursor are asked to perform web scraping or data collection, they often ingest raw HTML directly. A single page can carry tens of thousands of tokens, and feeding that unfiltered markup into a model quickly inflates API costs while burying the data that actually matters. A recently published Zenn article, authored with AI assistance, outlines a "Skill design pattern" that addresses this problem by returning only structured data to the agent, reportedly cutting token consumption by more than 90 percent.

The core issue is familiar to anyone who has delegated scraping tasks to a large language model. Modern web pages are dense with navigation menus, inline scripts, tracking snippets, advertising code, and deeply nested DOM elements. When an agent loads this content verbatim, most of the tokens it processes are noise rather than signal. Beyond the raw cost, the article notes a second failure mode: agents frequently stumble with errors like "DOM element not found," then loop through repeated trial-and-error attempts. Each retry consumes additional API calls and time, compounding both expense and latency.

The proposed remedy is to insert a dedicated Skill between the agent and the target website, rather than letting the model reason over unprocessed HTML. In this framing, a Skill is a reusable, task-specific capability that handles the messy extraction work deterministically and hands back a clean, structured result. Instead of asking the model to parse a full page, the pipeline strips out extraneous markup first and delivers only the relevant fields, so the agent receives compact, predictable input. Because the payload shrinks dramatically, the token count and associated cost fall in proportion, which is where the reported reduction of over 90 percent comes from.

This approach aligns with a broader industry pattern often described as pre-processing or tool-augmented retrieval. Rather than treating the language model as a universal parser, developers increasingly offload well-defined, mechanical tasks to conventional code and reserve the model's context window for genuine reasoning. Established libraries for HTML cleanup and content extraction, such as readability-style parsers, DOM sanitizers, and markup-to-Markdown converters, embody the same principle, and the Skill design pattern appears to formalize that habit into a repeatable interface an agent can call.

The concept also sits within the growing ecosystem of agentic tooling. Claude Code, Cursor, and similar CLI-based assistants are designed to operate with external tools and defined skills, and many now interoperate with emerging standards for connecting models to data sources and utilities. Presenting a scraper as a first-class Skill fits neatly into that model: the agent decides when to invoke it, but the underlying extraction logic remains fixed and testable. That separation is likely to improve reliability, since deterministic parsing code does not hallucinate selectors or drift between runs the way a model prompted to read raw HTML might.

For readers considering this technique, a few prerequisite ideas help clarify why it works. Token consumption in most commercial LLM APIs is billed per input and output token, so reducing the size of what the model reads directly lowers cost. Structured output, typically JSON or another schema-bound format, is also easier for downstream code to validate and consume, reducing the ambiguity that triggers retry loops. And because a well-scoped Skill returns consistent shapes, it can be cached, unit-tested, and reused across projects, benefits that ad hoc prompting rarely provides.

It is worth treating the headline figure with appropriate caution. The claimed savings will vary with the target site, the volume of boilerplate on each page, and how aggressively the extraction step trims content. Pages that are already lean may see smaller gains, while heavily instrumented commercial sites could see even larger ones. The article is explicitly an AI-assisted blog post rather than a formal benchmark, so the 90 percent figure is best read as an illustrative result from the author's own workflow rather than a guaranteed outcome.

Even so, the underlying guidance is sound and broadly applicable. As agentic workflows move from experiments into production, controlling token spend and improving determinism become practical necessities rather than optimizations. Encapsulating scraping and data collection behind a purpose-built Skill that emits structured data is a concrete way to pursue both, and the pattern generalizes to other tasks where raw, noisy inputs would otherwise flood an agent's context.

ポコとTECHガイドPoko & TECH Guide

ポコと当サイトのTECHガイドが、記事の要約と収集した情報から読みどころを語るAI生成の対話です。Poko and TECH Dashboard's own TECH Guide discuss the article's highlights in an AI-generated conversation based on its summary and collected source details.

  1. ポコPoko生HTMLを97.5%圧縮する「Skill」って何? 普通の圧縮とは違うの?What’s a “Skill” that compresses raw HTML by 97.5%? Is that different from regular compression?
  2. TECHガイドTECH Guide簡単に言うと、広告コードなどのノイズを除き、必要な構造化データだけ返す専用の仕組みじゃな。記事では90%以上削減できるとしておる。Put simply, it’s a dedicated process that removes noise like ad code and returns only the needed structured data. The article says this can cut token use by over 90%.
  3. ポコPokoそれって何が嬉しいの? 小さくなる以外にも効果がある?What’s the real benefit? Does it help with anything besides making the input smaller?
  4. TECHガイドTECH Guide記事によれば、トークン消費とAPIコストを抑え、肝心なデータを取り出しやすくするのが利点じゃよ。無駄な再試行や通信を減らす狙いもある。According to the article, it lowers token use and API costs while making key data easier to extract. It also aims to reduce wasted retries and network requests.
  5. ポコPokoなるほど! HTMLを丸ごと読ませず、必要な情報だけAIエージェントに渡すのがポイントなんだね。Got it! The key is to give the AI agent only the useful information instead of making it read the entire HTML page.
  6. TECHガイドTECH Guideその通りじゃ。必要なデータをどう構造化して返すかというSkill設計と、実際の削減効果が見どころじゃな。Exactly. The key things to watch are how the Skill structures the needed data and how much token reduction it actually achieves.
記事情報・収集記録Article details & collection record
出典Source
Zenn GitHub CopilotコミュニティCommunity
公開日時 (JST)Published (JST)
収集日時 (JST)Collected (JST)
配信形式Format
ブログBlog
原文言語Source language
JA
重要度の位置づけImportance in this lane
MediumMedium priority(GitHub Copilot 218件中、同等以上 166件)(166 of 218 GitHub Copilot entries are equal or higher)
出典の平均重要度(掲載直近 30 件・最大 30 件)Source average (last 30 listed, up to 30)
2.0 / 31=情報 · 2=中 · 3=高1=Info · 2=Medium · 3=High
情報の寿命Half-life
中期 (チュートリアル)Medium-term (tutorial)

🧠GitHub Copilot の他の記事More from GitHub Copilotもっと見る →View more →

ページ上部へScroll to top