[たぬきのA2A入門]PDFを自動要約して英語レポート化し、Boxに保存するA2Aマルチエージェントを作った話
生成AIを組み込んだA2Aマルチエージェントについて前回の記事で学びました。
実際に何かしら動くものを作りたくて
「日本語PDFを要約 → 英語レポート化 → Boxに保存」
このパイプラインを自動化してみました。
✅ 作ったもの
StreamlitのGUIでPDFをアップロードすると、
日本語PDFからテキスト抽出
↓
要約(GPT)
↓
英語レポートに翻訳(GPT)
↓
Boxにアップロード
↓
結果をGUI表示
まで自動でやってくれます。
おまけとしてサンプル動作確認用PDF作成スクリプトもついています。
txtファイルにメモを書き込んでいくと、それを使ったPDFファイルを自動で生成してくれます。
動作画面のイメージ
初期画面は下のようなものになります。

Streamlitは簡単にGUIが作れるのがいいですよね。
ファイルをアップロードすると、しばらくしたところで結果が表示されます。

Boxを見ると英語で要約したテキストが出力されています。

中身を開くとこんなかんじ。

使い方
requirements.txtをインストールしたら.envファイルにトークンをセットしてください。
※この設定を使うと基本的にBoxのアカウントのルートディレクトリに出来上がりが保存されます。
そのあと、すべての
あとはサーバ起動
uvicorn summarizer_agent.summarizer:app --port 8001 --reload
uvicorn translator_agent.translator:app --port 8002 --reload
uvicorn box_agent.box_uploader:app --port 8003 --reload
uvicorn orchestrator.orchestrator:app --port 8000 --reload
GUI起動
streamlit run gui/gui.py
をしてください。
もう少しGUIは凝ってもいいかもしれません。
ハマったところ
PyPDF2を使ってPDFの処理を行っていたのですが、これが日本語に弱くて文字化けをしてsummarizerが謝罪してきました。結果こんな出力に。。。
#Boxに出力されたテキスト文の内容がこれ
Apologies, but the provided text contains inappropriate characters and unclear symbols, preventing us from providing an accurate summary. We would appreciate it if you could provide the text again in the correct format.
結局、抽出部分は pdfminer.six に切り替えました。するとこんな感じに。
1. The new business strategy for 2025 targets three areas: generative AI solutions, business automation tools, and global market expansion. In particular, differentiation and speed were deemed crucial in the generative AI sector.
2. The plan is to simultaneously advance domestic and international expansion, prioritizing North America and Asia. By establishing a collaborative model with local partner companies, initial costs will be reduced and scaling will be accelerated.
3. Securing talent was identified as a challenge. Due to the difficulty in hiring engineers with specialized skills, a combination of in-house and outsourced resources, as well as the short-term utilization of external talent, was deemed necessary. The next meeting will discuss the MVP development schedule and the marketing roadmap.
日本語とPDF系のライブラリの相性に悩まされる人は結構多いんじゃないかな。。。
まとめ
Orchestratorで責務を限定すると開発が楽になる
A2A以外の構成で同じ機能を持つシステムを作ることもできるのですが、A2Aを使うとシステム同士の結合が密にならないので、責任分離がはっきりしてエラーが出ても対処がどこかわかりやすかったのはよいところだと感じました。
今後、いろんなシステム開発でAgentとかMCPを使うのがファーストチョイスになるかもしれませんね。
では。
Discussion