0. はじめに
今回は CrewAI を使って、実際に「ニュースリーダーエージェント」を開発してみました。
この記事では、
SerperDevTool APIを利用してニュース記事を自動検索し、CrewAIのマルチエージェント構造で
「ニュース収集 → 要約 → 編集・統合」までを一気通貫で行う仕組みを構築しました。
テーマとしては、ドジャースの2025年ワールドシリーズ制覇に関するニュースを自動で収集・要約・編集する AI エージェントを設計しています。
1. CrewAIとは?
CrewAIで超簡単な翻訳エージェントを作ってみたの記事をご覧ください
2. エージェントの構成
以下のような構成になっています👇
| エージェント名 | 役割(Role) | 主なツール | タスク |
|---|---|---|---|
news_hunter_agent |
ニュース収集担当(検索・記事抽出) | SerperDevTool / scrape_tool | content_harvesting_task |
summarizer_agent |
ニュース要約担当(見出し・要点・全文要約) | scrape_tool | summarization_task |
curator_agent |
編集担当(最終記事の編集・整形) | なし | final_report_assembly_task |
3. main.py の仕組み
main.py では、CrewAI の基本構造を定義しています。
@CrewBase クラス内にエージェントとタスクを定義し、
それらを組み合わせて Crew() を構築します。
from crewai import Crew, Agent, Task
from crewai.project import CrewBase, agent, task, crew
from tools import search_tool, scrape_tool
@CrewBase
class NewsReaderAgent:
@agent
def news_hunter_agent(self):
return Agent(
config=self.agents_config["news_hunter_agent"],
tools=[search_tool, scrape_tool],
)
@agent
def summarizer_agent(self):
return Agent(
config=self.agents_config["summarizer_agent"],
tools=[scrape_tool],
)
@agent
def curator_agent(self):
return Agent(
config=self.agents_config["curator_agent"],
)
@task
def content_harvesting_task(self):
return Task(config=self.tasks_config["content_harvesting_task"])
@task
def summarization_task(self):
return Task(config=self.tasks_config["summarization_task"])
@task
def final_report_assembly_task(self):
return Task(config=self.tasks_config["final_report_assembly_task"])
@crew
def crew(self):
return Crew(
tasks=self.tasks,
agents=self.agents,
verbose=True,
)
result = NewsReaderAgent().crew().kickoff(inputs={"topic": "dodgers ws wins 2025"})
4. tools.py の仕組み
tools.py では、CrewAIのエージェントが外部操作を行うための「ツール」を定義しています。
今回のニュースリーダープロジェクトでは 2種類のツール を実装しました。
-
SerperDevTool(リンク)
用途:Web上のニュース記事を検索する
仕組み:SerperDevのAPIを介して、Google検索のようにキーワード検索
上位 n_results=10 件までの検索結果を取得
重要ポイント:- エージェントは検索結果のURLから実際の記事を判断
- topic/tagページやランキングページは除外し、記事ページのみ収集
-
crape_tool(記事本文抽出用)
用途: 記事URLから本文を抽出
仕組み:- Playwrightでページをレンダリング
- BeautifulSoupで不要なタグを除去
import time
from crewai.tools import tool
from crewai_tools import SerperDevTool
from playwright.sync_api import sync_playwright
from bs4 import BeautifulSoup
search_tool = SerperDevTool(
n_results=10,
)
@tool
def scrape_tool(url: str):
"""
Use this when you need to read the content of a website.
Returns the content of a website, in case the website is not available, it returns 'No content'.
Input should be a `url` string. for example (https://www.reuters.com/world/asia-pacific/cambodia-thailand-begin-talks-malaysia-amid-fragile-ceasefire-2025-08-04/)
"""
print(f"Scrapping URL: {url}")
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
page.goto(url)
time.sleep(5)
html = page.content()
browser.close()
soup = BeautifulSoup(html, "html.parser")
for tag in soup.find_all(unwanted_tags):
tag.decompose()
content = soup.get_text(separator=" ")
unwanted_tags = [
"header",
"footer",
"nav",
"aside"
]
return content if content != "" else "No content"
5. agents.yamlの概要
- news_hunter_agent: ニュース記事の収集担当
- summarizer_agent: 収集記事の要約担当
- curator_agent: 要約記事を統合し、最終レポートを作成
各エージェントには以下の属性を設定しています:
| 属性名 | 説明 |
|---|---|
| role | エージェントの役割・職種 |
| goal | エージェントが達成すべき目標 |
| backstory | エージェントの背景や専門性、行動指針 |
| verbose | 実行時の詳細ログを表示するか |
| inject_date | 出力にタイムスタンプを自動挿入するか |
6. tasks.yamlの概要
タスクはニュース収集から最終レポート作成まで段階的に構成されます。
| タスク | 説明 |
|---|---|
| content_harvesting_task | 検索ツールを用いて最新ニュース記事を収集し、信頼性・関連性を評価 |
| summarization_task | 各記事をヘッドライン、エグゼクティブサマリー、詳細サマリーの3階層で要約 |
| final_report_assembly_task | 全記事を統合し、プロのニュースブリーフィングとして完成させる |
7. uv run main.py 実行時の流れ
uv run main.py を実行すると、ニュースリーダーエージェントが以下の順序で動作します。
| ステップ | エージェント / タスク | 処理内容 | 出力例 |
|---|---|---|---|
| 1 | Crew起動 | CrewBaseクラスからCrewインスタンスを生成。verbose=Trueで詳細ログを表示。 | Crew Execution Started |
| 2 | content_harvesting_task |
news_hunter_agent が search_tool を使用して記事URLを検索 |
検索結果URLリスト |
| 3 |
scrape_tool を使用して各URLの本文を取得 |
記事本文テキスト | |
| 4 | 信頼性・関連性をスコアリング | クリティカルスコア・関連性スコア | |
| 5 | summarization_task |
summarizer_agent が各記事を3階層で要約 ・ヘッドライン(Tweet風) ・エグゼクティブサマリー(150-200 words) ・詳細サマリー(500-700 words) |
summary.md |
| 6 | final_report_assembly_task |
curator_agent が全記事を統合し、最終ニュースブリーフを生成 |
final_report.md |
| 7 | Crew完了 | 全タスク完了後、最終出力を表示 | 出力ファイル一覧: content_harvest.md, summary.md, final_report.md |
summary.mdの例
# News Summaries: dodgers ws wins 2025 **Summary Report Overview** - Total articles processed: 3 - Summary generation date: 2025-11-12Article 1: Dodgers win 2025 World Series
Source: MLB.com
Date: November 3, 2025
Original URL: https://www.mlb.com/news/dodgers-win-2025-world-series
📱 Headline Summary (Tweet-length)
Dodgers win thrilling 2025 World Series Game 7 in 11 innings, becoming first repeat champs since 2000 Yankees. Will Smith’s historic go-ahead HR and MVP Yoshinobu Yamamoto's clutch pitching seal Dodgers’ 5-4 comeback over Blue Jays. #WorldSeries
📋 Executive Summary
The Los Angeles Dodgers clinched the 2025 World Series title with a dramatic 5-4 comeback win over the Toronto Blue Jays in an 11-inning Game 7, marking the first repeat championship in 25 years. The Series was one of the most intense in recent memory, featuring an 18-inning marathon and relentless competition. Key moments included Miguel Rojas’ game-tying homer in the ninth inning and Will Smith’s go-ahead historic extra-inning home run — the first ever in a winner-take-all World Series game. Pitcher Yoshinobu Yamamoto, pitching on zero days’ rest, earned the World Series MVP for his extraordinary stamina and effectiveness. This victory was the Dodgers’ third title in six years and ninth overall, cementing their status as a modern baseball dynasty. The Blue Jays fought valiantly, highlighted by Bo Bichette’s three-run homer and strong pitching and defense, but fell two outs short of securing Canada’s first World Series crown in decades.
📖 Comprehensive Summary
The 2025 World Series concluded with one of the most memorable Game 7s in MLB history, as the Los Angeles Dodgers defeated the Toronto Blue Jays 5-4 in a rollercoaster 11-inning thriller at Rogers Centre. The Dodgers, aiming to repeat as champions for the first time since the 1998-2000 Yankees, delivered a masterclass in resilience and timely hitting, overcoming several deficits throughout the series and the epic final game. The Blue Jays had edged close to a sensational victory, with Bo Bichette’s three-run blast giving Toronto a crucial 3-0 lead early in the game and the team’s excellent defense frustrating Los Angeles. Veteran Max Scherzer, the oldest pitcher to start a World Series Game 7, battled hard while Toronto’s pitching held off many Dodger rallies.
The momentum shifted late, however, when Miguel Rojas, often an underrated role player for the Dodgers, homered in the ninth to tie the game 4-4 off Toronto closer Jeff Hoffman. The game-tying shot was a dramatic moment that saved the Dodgers from elimination and set the stage for extra innings. In the 11th inning, Toronto appeared poised to win with Vladimir Guerrero Jr. at the plate and runners on the corners, but clutch defense and pitching by World Series MVP Yoshinobu Yamamoto kept the game alive.
Will Smith then delivered an unforgettable moment, swinging at a 2-2 slider to hit the first extra-inning home run in a deciding World Series game’s history, giving the Dodgers a 5-4 lead. Toronto’s last rally fell short as Smith’s heroics proved decisive. The Dodgers’ victory not only marked three titles in six years but demonstrated their depth, strength, and grit in a season where the team slumbered through the regular season but surged in October.
Manager Dave Roberts praised the team’s toughness and viewed the game as one for the ages. The Blue Jays, despite heartbreak, earned respect for pushing the reigning champions to the limit. The 2025 World Series confirmed the Dodgers as MLB’s premier franchise of the modern era, capable of sustained success amid an expanded and competitive playoff format.
Summary Quality Metrics:
- Recommended audience: Sports professionals, baseball fans, MLB analysts
- Key topics covered: 2025 World Series Game 7 recap, player highlights, historic context
- Important statistics: Game 7 length (4h7m), Dodgers’ ninth overall title, first repeat champs since 2000
- Notable quotes: “It’s going to go down as one for the ages.” — Dave Roberts
Article 2: 2025 World Series: Game 7 win cements Dodgers' dynasty
Source: ESPN
Date: November 2, 2025
Original URL: https://www.espn.com/mlb/story/_/id/46796786/world-series-2025-los-angeles-dodgers-champions-repeat-dynasty
📱 Headline Summary (Tweet-length)
Dodgers’ Game 7 extra-inning win over Blue Jays crowns historic back-to-back champions — capping an era with Clayton Kershaw’s farewell and cementing a dynasty fueled by stars like Ohtani, Betts & Freeman. #DodgersDynasty
📋 Executive Summary
The Los Angeles Dodgers secured the 2025 World Series championship by defeating the Toronto Blue Jays 5-4 in extra innings of Game 7, becoming the first MLB team in 25 years to repeat as champions. This victory marked the culmination of Clayton Kershaw’s final season, a legendary Dodger who retires as one of baseball’s all-time greats. The Dodgers’ organizational strategy emphasizing elite scouting, player development, and free agent acquisitions — including marquee talents like Shohei Ohtani, Mookie Betts, and Freddie Freeman — has established them as a modern dynasty. This era, a seismic shift from the franchise’s past decades of mediocrity, reflects sustained dominance with multiple NL pennants and World Series titles over more than a decade. The Dodgers remain a model of consistency, innovation, and star power in Major League Baseball, with strong prospects of continued success.
📖 Comprehensive Summary
The 2025 World Series Game 7 victory by the Los Angeles Dodgers over the Toronto Blue Jays was much more than a title clincher — it was a defining moment in what many consider one of baseball’s greatest modern dynasties. The Dodgers closed out the best-of-seven series 4-3 with a 5-4 win in 11 innings, a game full of drama and clutch performances. Central to the narrative was the farewell of Clayton Kershaw, who announced his retirement late in the season. Kershaw’s career has been intertwined with the franchise’s success, and he finished with his third World Series championship, closing out an illustrious career as a one-team Hall of Famer. Though a future Hall of Famer, Kershaw contributed significantly to Dodger’s late postseason success, notably stopping a critical bases-loaded threat in the 18-inning Game 3.
The Dodgers themselves evolved over years from a talented but inconsistent team into one of the sport’s most formidable organizations under the ownership of the Guggenheim group and baseball executive Andrew Friedman, who arrived in 2014. Since then, the team has maintained a top-five payroll and consistently strong farm system. Their scouting and development programs have been industry-leading, allowing them to supplement star acquisitions like Ohtani, Betts, and Freeman — all MVPs — with talented role players.
The Dodgers represent an all-encompassing baseball powerhouse — excelling in scouting, analytics, player development, free agency, and major league performance. Players express deep loyalty to the franchise, citing communication and respect as hallmarks. The team’s cultural identity, built around winning expectations and innovative management, sets an example in the professional sports landscape.
With the end of the Kershaw era, the Dodgers remain loaded with star talent and a pipeline of prospects that ESPN prospect analyst Kiley McDaniel recently ranked as the best in baseball. The Dodgers are already heavy favorites for 2026, highlighting an expected continuation of this dominant period. Their multiyear success reflects characteristics of MLB’s greatest dynasties like the Yankees from the early to mid-20th century, sustained by strong leadership, resources, and player loyalty.
Summary Quality Metrics:
- Recommended audience: Baseball historians, sports executives, MLB analysts
- Key topics covered: Dodgers’ dynasty formation, Kershaw retirement, organizational excellence
- Important statistics: 13 consecutive postseason appearances, 5 NL pennants, 3 World Series titles (recent)
- Notable quotes: “You see free agents... they want to be a part of something built to last.” — Clayton Kershaw
Article 3: Did MLB place LA Dodgers' 2025 World Series win under review?
Source: Snopes
Date: November 7, 2025
Original URL: https://www.snopes.com/fact-check/dodgers-world-series-review-mlb/
📱 Headline Summary (Tweet-length)
No, MLB did NOT place the Dodgers’ 2025 World Series win under review—rumors claiming suspension are debunked fake news from ad-driven sites. MLB affirms championship stands with full integrity. #FactCheck #MLB
📋 Executive Summary
After the Dodgers’ 2025 World Series victory, rumors claiming Major League Baseball had placed the title under review with potential suspension circulated online. These claims, propagated by unofficial sources like advertisement-heavy Facebook pages and dubious websites, were thoroughly investigated and found to be baseless. No credible media reported any such action by MLB. The MLB Communications Department publicly denied these rumors, emphasizing the integrity of the 2025 title. The false narrative appears to have been an attempt to generate advertising revenue through misinformation. This fact-check underscores the importance of verifying claims from unofficial outlets, especially regarding major sports milestones.
📖 Comprehensive Summary
In the aftermath of the Los Angeles Dodgers clinching their ninth World Series title and first repeat championship since the late 1990s, multiple social media posts and web articles alleged that MLB was reviewing the legitimacy of the 2025 championship with a view toward revoking it. Claims originated from Facebook pages named after MLB teams and linked to WordPress blogs filled with advertisements. Despite these viral posts, comprehensive checks of searches on Bing, Google, Yahoo, and DuckDuckGo showed no legitimate media outlets reporting such a review or suspension.
The persistent rumor appeared to be an invention by unknown actors aiming for ad revenue, rather than informed news reportage. Snopes reached out to MLB for comment, who confirmed no review or suspension is underway. The Major League Baseball Communications Department also publicly denied the claims on social media channels.
This misinformation highlights the growing problem in the digital age where viral, misleading stories can quickly spread without factual basis. The Dodgers’ 2025 World Series win stands undisputed as one of baseball’s great recent achievements, celebrated for its dramatic conclusion and competitive excellence. Fans and media are advised to rely on credible sources for information and cautious skepticism of sensationalist viral rumors.
Summary Quality Metrics:
- Recommended audience: Sports fans, fact-checkers, general public
- Key topics covered: Rumor debunking, misinformation on sports achievements
- Important statistics: None relevant
- Notable quotes: “We respect the league’s process and will cooperate fully. Our focus remains on our players, our fans, and the integrity of the sport.” — MLB statement