research-agent-optimization
調査エージェントの性能を向上させ、API利用効率やウェブ検索の連携を改善し、進捗状況の詳細な更新や情報源の明示によって、より快適な情報収集体験を提供するSkill。
📜 元の英語説明(参考)
Optimize the research agent for rate limit handling, API call efficiency, web search integration fixes, and improved streaming UX with granular progress updates and source attribution.
🇯🇵 日本人クリエイター向け解説
調査エージェントの性能を向上させ、API利用効率やウェブ検索の連携を改善し、進捗状況の詳細な更新や情報源の明示によって、より快適な情報収集体験を提供するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o research-agent-optimization.zip https://jpskill.com/download/17504.zip && unzip -o research-agent-optimization.zip && rm research-agent-optimization.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/17504.zip -OutFile "$d\research-agent-optimization.zip"; Expand-Archive "$d\research-agent-optimization.zip" -DestinationPath $d -Force; ri "$d\research-agent-optimization.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
research-agent-optimization.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
research-agent-optimizationフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Research Agent Optimization
範囲
- プロジェクトルート:
/home/bender/classwork/Thesis - バックエンド:
backend/news_research_agent.py,backend/app/api/routes/research.py,backend/app/services/news_research.py - フロントエンド:
frontend/app/search/page.tsx,frontend/lib/api.ts - 設定:
backend/app/core/config.py
問題提起
- レート制限: Gemini API が調査および記事分析中に 429 quota exceeded エラーを発生させる
- ウェブ検索: DuckDuckGo ツール統合に命名の問題がある (適切に初期化されていない)
- 不明確な進捗: 研究ストリーミングが、特定のツール呼び出しではなく、汎用的な "Still working..." を表示する
- レスポンス内の JSON: 結果が、フォーマットされたソースカードではなく、生の JSON ブロックを表示する
- 冗長な API 呼び出し: キャッシュ/重複排除なしに、複数の内部検索呼び出しが行われる
必要な成果
- 指数バックオフとクォータ監視による、優雅なレート制限処理
- 適切な DuckDuckGo 初期化による、動作するウェブ検索ツール
- 実際のツール実行 (web_search, news_search, internal_news_search) を示す、詳細なストリーミングイベント
- インラインソースカード (JSON ブロックではない) でレンダリングされた研究結果
- 最適化された API 呼び出し: バッチ検索、セマンティック結果のキャッシュ、内部知識ベースの再利用
- クォータを超過した場合の明確なエラーメッセージ
ワークフロー
1. API 呼び出しの最適化
search_internal_newsツールにリクエストバッチ処理を実装する- セマンティック検索結果にキャッシュレイヤーを追加する (5 分以内の重複クエリを回避する)
- web_search + news_search を単一の結果セットに結合する
- セッションごとの API 呼び出し数を追跡し、クォータ枯渇前に警告する
- 指数バックオフ再試行ロジックを追加する (1 秒、2 秒、4 秒、最大 8 秒)
ファイル:
backend/news_research_agent.py- ツールとキャッシュbackend/app/services/news_research.py- リクエストバッチ処理ヘルパー
2. レート制限とクォータ処理
- Gemini 呼び出しの周りに try/catch ラッパーを追加する
- 429 エラーを検出し、ユーザーフレンドリーなメッセージ ("API Rate Limit: ...please wait a moment...") を返す
- クォータが低い場合に、記事分析のためにオプションの
--skip-gemini-analysisモードを追加する - クォータ使用量と残りのトークンをログに記録する
- モデルを
gemini-2.0-flash-expではなくgemini-2.0-flash(より高速、より低いトークンコスト) に設定する
ファイル:
backend/app/core/config.py- エラー処理ラッパー、モデル選択backend/app/api/routes/research.py- HTTP エラーレスポンスbackend/news_research_agent.py- LLM 呼び出しエラー処理
3. ウェブ検索ツールの修正
- DuckDuckGo インポートを確認する:
from duckduckgo_search import DDGS(ddgsまたはDuckDuckGoではない) web_searchおよびnews_searchツールが LLM に適切にバインドされていることを確認する- ウェブ検索が失敗した場合に、内部検索へのフォールバックを追加する
- クエリと結果数でツール実行をログに記録する
ファイル:
backend/news_research_agent.py- ツールの定義とエラー処理exa-codeを使用して、現在の DuckDuckGo API パターンを確認する
4. ストリーミング進捗の明確化
- SSE イベントタイプを拡張する:
tool_startにはツール名 + クエリパラメータが含まれる - ツールイベントをユーザーフレンドリーなメッセージにマッピングする:
web_search("climate change")→ "Searching web for: climate change..."news_search(keywords="COP30")→ "Searching news for: COP30..."search_internal_news(query)→ "Searching internal knowledge base..."fetch_article_content(url)→ "Reading article: [title/domain]..."
- タイムスタンプとツール実行期間を追加する
- ツールアクティビティがない場合は、3〜5 秒ごとにステータスアップデートを発行する
ファイル:
backend/news_research_agent.py- ストリーミングジェネレーターbackend/app/api/routes/research.py- SSE フォーマット
5. フロントエンドの結果レンダリング
- レスポンステキストから JSON ブロックを削除する
- 参照された記事を、回答の下の「Sources」セクションにレンダリングする
- 記事カードを使用する: タイトル、ソース、日付、画像のサムネイル
- カードをクリック可能にして、記事詳細モーダルを開く
- ソースを検索方法 (セマンティック、ウェブ検索、内部) でグループ化する
ファイル:
frontend/app/search/page.tsx- メッセージレンダリングとソースグリッドfrontend/lib/api.ts- レスポンスパース
6. エラー処理とユーザーフィードバック
- 以下を検出して処理する:
- 429 クォータ超過 → "API Rate Limit: The AI service has reached its rate limit. Please wait a moment and try again."
- 接続タイムアウト → "Request Timeout: The research took too long. Try a simpler query."
- ツール実行の失敗 → "Tool [name] failed: [reason]. Continuing with alternative search..."
- エラー時に再試行プロンプトを追加する (自動ではなく、ユーザーが選択する)
- デバッグのために、すべてのエラーをリクエスト ID と共にログに記録する
ファイル:
backend/app/api/routes/research.py- エラーフォーマットfrontend/app/search/page.tsx- エラー UI と再試行ロジック
チェック
API 最適化
- セマンティック検索結果がキャッシュされていることを確認する (重複呼び出しがない)
- web_search と news_search が結果を返すことを確認する (空ではない)
- ツールの実行ログに、繰り返されたクエリのキャッシュヒットが表示されることを確認する
レート制限処理
- 429 エラーをトリガーし、優雅なフォールバックメッセージが表示されることを確認する
- スタックトレースがユーザーに表示されないことを確認する
- ログにクォータステータスと再試行タイミングが表示されることを確認する
ウェブ検索
- "climate change" をクエリし、web_search が 5 つ以上の結果を返すことを確認する
- DuckDuckGo DDGS クラスが適切にインスタンス化されていることを確認する
- news_search が最近のニュース記事を返すことを確認する
ストリーミングの明確さ
- クエリの詳細を含む tool_start の SSE イベントを監視する
- タイムスタンプが正しくインクリメントされることを確認する
- "Still working..." メッセージが 30 秒間非アクティブになった後にのみ表示されることを確認する
フロントエンドレンダリング
- 研究の回答がプレーンテキストであることを確認する (JSON ではない)
- 「Sources」セクションが記事カードと共に表示されることを確認する
- カードのクリックで記事詳細モーダルが開くことを確認する
- 重複するソースがないことを確認する (重複排除が機能している)
エラーシナリオ
- 無効なクエリを送信し、クラッシュしないことを確認する
- ネットワーク切断でテストし、タイムアウトメッセージを確認する
- クォータ超過 (403) をシミュレートし、ユーザーがレート制限メッセージを表示することを確認する
実装チェックリスト
- [ ] 指数バックオフを持つ再試行デコレータを Gemini クライアントに追加する
- [ ] 5 分の TTL で
search_internal_newsにリクエストキャッシュを実装する - [ ] DuckDuckGo ツールを修正する
(原文がここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Research Agent Optimization
Scope
- Project root:
/home/bender/classwork/Thesis - Backend:
backend/news_research_agent.py,backend/app/api/routes/research.py,backend/app/services/news_research.py - Frontend:
frontend/app/search/page.tsx,frontend/lib/api.ts - Configuration:
backend/app/core/config.py
Problem Statement
- Rate Limiting: Gemini API hits 429 quota exceeded errors during research and article analysis
- Web Search: DuckDuckGo tool integration has naming issues (not properly initialized)
- Unclear Progress: Research streaming shows generic "Still working..." instead of specific tool calls
- JSON in Response: Results show raw JSON blocks instead of formatted source cards
- Redundant API Calls: Multiple internal search calls without caching/deduplication
Required Outcomes
- Graceful rate limit handling with exponential backoff and quota monitoring
- Working web search tool with proper DuckDuckGo initialization
- Verbose streaming events showing real tool execution (web_search, news_search, internal_news_search)
- Research results rendered with inline source cards (not JSON blocks)
- Optimized API calls: batch searches, cache semantic results, reuse internal knowledge base
- Clear error messages when quota is exceeded
Workflow
1. API Call Optimization
- Implement request batching in
search_internal_newstool - Add caching layer for semantic search results (avoid duplicate queries within 5min window)
- Combine web_search + news_search into single result set
- Track API call counts per session and warn before quota exhaustion
- Add exponential backoff retry logic (1s, 2s, 4s, 8s max)
Files:
backend/news_research_agent.py- tools and cachingbackend/app/services/news_research.py- request batching helpers
2. Rate Limit & Quota Handling
- Add try/catch wrapper around Gemini calls
- Detect 429 errors and return user-friendly message ("API Rate Limit: ...please wait a moment...")
- Add optional
--skip-gemini-analysismode for article analysis when quota is low - Log quota usage and remaining tokens
- Set model to
gemini-2.0-flash(faster, lower token cost) instead ofgemini-2.0-flash-exp
Files:
backend/app/core/config.py- error handling wrapper, model selectionbackend/app/api/routes/research.py- HTTP error responsesbackend/news_research_agent.py- LLM call error handling
3. Web Search Tool Fix
- Verify DuckDuckGo import:
from duckduckgo_search import DDGS(notddgsorDuckDuckGo) - Ensure
web_searchandnews_searchtools are properly bound to LLM - Add fallback to internal search if web search fails
- Log tool execution with query and result count
Files:
backend/news_research_agent.py- tool definitions and error handling- Use
exa-codeto verify current DuckDuckGo API patterns
4. Streaming Progress Clarity
- Expand SSE event types:
tool_startincludes tool name + query parameters - Map tool events to user-friendly messages:
web_search("climate change")→ "Searching web for: climate change..."news_search(keywords="COP30")→ "Searching news for: COP30..."search_internal_news(query)→ "Searching internal knowledge base..."fetch_article_content(url)→ "Reading article: [title/domain]..."
- Add timestamps and tool execution duration
- Emit status updates every 3-5 seconds if no tool activity
Files:
backend/news_research_agent.py- streaming generatorbackend/app/api/routes/research.py- SSE formatting
5. Frontend Result Rendering
- Remove JSON blocks from response text
- Render referenced articles in a "Sources" section below the answer
- Use article cards: title, source, date, image thumbnail
- Make cards clickable to open article detail modal
- Group sources by retrieval method (semantic, web search, internal)
Files:
frontend/app/search/page.tsx- message rendering and sources gridfrontend/lib/api.ts- response parsing
6. Error Handling & User Feedback
- Detect and handle:
- 429 quota exceeded → "API Rate Limit: The AI service has reached its rate limit. Please wait a moment and try again."
- Connection timeout → "Request Timeout: The research took too long. Try a simpler query."
- Tool execution failure → "Tool [name] failed: [reason]. Continuing with alternative search..."
- Add retry prompt on error (not automatic, user chooses)
- Log all errors with request ID for debugging
Files:
backend/app/api/routes/research.py- error formattingfrontend/app/search/page.tsx- error UI and retry logic
Checks
API Optimization
- Verify semantic search results are cached (no duplicate calls)
- Check web_search and news_search return results (not empty)
- Confirm tool execution logs show cache hits for repeated queries
Rate Limit Handling
- Trigger 429 error and verify graceful fallback message displays
- Confirm no stack traces shown to user
- Check logs show quota status and retry timing
Web Search
- Query "climate change" and verify web_search returns 5+ results
- Confirm DuckDuckGo DDGS class is properly instantiated
- Check news_search returns recent news articles
Streaming Clarity
- Monitor SSE events for tool_start with query details
- Verify timestamps increment correctly
- Confirm "Still working..." message only shows after 30s inactivity
Frontend Rendering
- Verify research answer is plain text (no JSON)
- Check "Sources" section appears with article cards
- Confirm card click opens article detail modal
- Verify no duplicate sources (de-duplication working)
Error Scenarios
- Submit invalid query and verify doesn't crash
- Test with network disconnect and check timeout message
- Simulate quota exceeded (403) and verify user sees rate limit message
Implementation Checklist
- [ ] Add retry decorator with exponential backoff to Gemini client
- [ ] Implement request cache in
search_internal_newswith 5min TTL - [ ] Fix DuckDuckGo tool initialization (verify DDGS import)
- [ ] Update
research_stream()to emit granular tool start/result events - [ ] Map tool events to human-readable status messages in API endpoint
- [ ] Remove JSON block from final answer text
- [ ] Add "Sources" section with article cards to frontend
- [ ] Update error handling for 429 quota exceeded
- [ ] Add streaming status animation to UI
- [ ] Write tests for quota handling and web search integration