

AIプレゼンテーションエージェントの構築:完全開発者ガイド
AIエージェントは、ソフトウェアがコンテンツを作成する方法を変革しています。AIプレゼンテーションエージェントは、CRMパイプラインから社内レポートツールまで、自動化されたワークフローの一部として、プロフェッショナルなスライドデッキを生成、カスタマイズ、配信できます。
このガイドでは、2Slides APIを使用して、本番環境に対応したプレゼンテーションエージェントを構築する方法を順を追って説明します。
アーキテクチャの概要
プレゼンテーションエージェントは通常、次のフローに従います。
ユーザーリクエスト → エージェントロジック → 2Slides API → ジョブのポーリング → 結果の配信
↓
コンテキスト収集
(データ、テンプレート、ブランドアセット)主要コンポーネント
- Input Handler — プレゼンテーションリクエスト(テキスト、データ、ファイル)を受信
- Context Builder — テンプレート、ブランド情報、データでリクエストを強化
- Generation Engine — 2Slides APIを呼び出してスライドを作成
- Status Monitor — 完了するまでジョブステータスをポーリング
- Delivery Layer — ダウンロードリンクを返し、メールで送信、Slackに投稿
はじめに
1. APIキーの取得
2slides.comでサインアップし、2slides.com/apiでAPIキーを作成してください。
2. 依存関係のインストール
npm install node-fetch dotenv3. 基本的なエージェントの実装
import fetch from 'node-fetch';
class PresentationAgent {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseUrl = 'https://2slides.com/api/v1';
}
async generateSlides({ topic, themeId, language = 'en', resolution = '2K' }) {
// Step 1: Start generation
const response = await fetch(`${this.baseUrl}/slides/generate`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${this.apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
userInput: topic,
themeId,
responseLanguage: language,
resolution,
mode: 'async'
})
});
const job = await response.json();
if (!response.ok) throw new Error(job.error || 'Generation failed');
// Step 2: Poll until complete
return await this.waitForCompletion(job.jobId);
}
async waitForCompletion(jobId, maxWait = 300000) {
const start = Date.now();
while (Date.now() - start < maxWait) {
const response = await fetch(`${this.baseUrl}/jobs/${jobId}`, {
headers: { 'Authorization': `Bearer ${this.apiKey}` }
});
const status = await response.json();
if (status.status === 'success') return status;
if (status.status === 'failed') throw new Error('Generation failed');
await new Promise(r => setTimeout(r, 3000));
}
throw new Error('Generation timed out');
}
async generateFromFile({ fileUrl, prompt, themeId }) {
const response = await fetch(`${this.baseUrl}/slides/create-pdf-slides`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${this.apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
fileUrl,
userInput: prompt,
themeId,
mode: 'async'
})
});
const job = await response.json();
return await this.waitForCompletion(job.jobId);
}
async generateWithDesign({ topic, referenceImageUrl, resolution = '2K' }) {
const response = await fetch(`${this.baseUrl}/slides/create-like-this`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${this.apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
userInput: topic,
designStyle: {
global: { referenceImageUrl }
},
resolution,
mode: 'async'
})
});
const job = await response.json();
return await this.waitForCompletion(job.jobId);
}
async addNarration({ jobId, mode = 'single', voice = 'Charon' }) {
const response = await fetch(`${this.baseUrl}/slides/generate-narration`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${this.apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ jobId, mode, voice, contentMode: 'concise' })
});
return await response.json();
}
}
// Usage
const agent = new PresentationAgent('sk-2slides-xxx');
const result = await agent.generateSlides({
topic: 'Q1 2026 Business Review',
themeId: 'mckinsey-theme-id',
resolution: '2K'
});
console.log('Download:', result.downloadUrl);Pythonでの実装
import requests
import time
class PresentationAgent:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = 'https://2slides.com/api/v1'
self.headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
}
def generate_slides(self, topic, theme_id=None, language='en', resolution='2K'):
response = requests.post(
f'{self.base_url}/slides/generate',
headers=self.headers,
json={
'userInput': topic,
'themeId': theme_id,
'responseLanguage': language,
'resolution': resolution,
'mode': 'async'
}
)
response.raise_for_status()
job = response.json()
return self._wait_for_completion(job['jobId'])
def generate_from_file(self, file_url, prompt, theme_id=None):
response = requests.post(
f'{self.base_url}/slides/create-pdf-slides',
headers=self.headers,
json={
'fileUrl': file_url,
'userInput': prompt,
'themeId': theme_id,
'mode': 'async'
}
)
response.raise_for_status()
job = response.json()
return self._wait_for_completion(job['jobId'])
def _wait_for_completion(self, job_id, max_wait=300):
start = time.time()
while time.time() - start < max_wait:
response = requests.get(
f'{self.base_url}/jobs/{job_id}',
headers=self.headers
)
status = response.json()
if status['status'] == 'success':
return status
if status['status'] == 'failed':
raise Exception('Generation failed')
time.sleep(3)
raise TimeoutError('Generation timed out')
# Usage
agent = PresentationAgent('sk-2slides-xxx')
result = agent.generate_slides('AI Trends 2026', resolution='4K')
print(f"Download: {result['downloadUrl']}")高度なパターン
パターン1:テンプレートベースの生成
さまざまなユースケースに合わせてテーマを事前設定します。
const TEMPLATES = {
'pitch-deck': { themeId: 'apple-id', resolution: '2K' },
'quarterly-review': { themeId: 'mckinsey-id', resolution: '2K' },
'training': { themeId: 'corporate-id', resolution: '1K' },
'social-media': { themeId: 'saul-bass-id', resolution: '4K', aspectRatio: '1:1' },
};
async function generateByType(type, topic) {
const config = TEMPLATES[type];
return agent.generateSlides({ topic, ...config });
}パターン2:データパイプラインとの統合
データソースに接続します。
async function weeklyReport(dataSource) {
// 1. Fetch latest data
const data = await dataSource.getWeeklyMetrics();
// 2. Format as presentation input
const topic = `Weekly Report: Revenue $${data.revenue}, Users ${data.users}, Churn ${data.churn}%`;
// 3. Generate slides
const result = await agent.generateSlides({ topic, themeId: 'mckinsey-id' });
// 4. Deliver
await slackBot.postMessage('#team-updates', `Weekly report ready: ${result.downloadUrl}`);
}パターン3:マルチフォーマット出力
スライド、ナレーション、ビデオを1つのパイプラインで生成します。
async function fullPresentation(topic) {
// 1. Generate slides
const slides = await agent.generateSlides({ topic });
// 2. Add voice narration
await agent.addNarration({ jobId: slides.jobId, mode: 'multi', voice: 'Charon' });
// 3. Download with audio
const download = await fetch(`${agent.baseUrl}/slides/download-slides-pages-voices`, {
method: 'POST',
headers: agent.headers,
body: JSON.stringify({ jobId: slides.jobId })
});
return download.json();
}本番環境での考慮事項
レート制限
- デフォルト:1分あたり60リクエスト
- 指数バックオフで429応答を処理
- バッチ操作には非同期モードを使用
エラー処理
- すべてのAPI呼び出しをtry/catchで囲む
- 一時的な障害に対してリトライロジックを実装
- デバッグのためにジョブIDをログに記録
コスト管理
- 生成ごとのクレジット使用量を追跡
- 2Slidesダッシュボードで予算アラートを設定
- 社内/ドラフトコンテンツには低解像度を使用
セキュリティ
- APIキーは環境変数に保存し、コードには決して含めない
- サーバーサイドAPI呼び出しのみを使用 — クライアントにキーを公開しない
- Webhookコールバックにはリクエスト署名を実装
よくある質問
2Slides APIの上にSaaS製品を構築できますか?
はい、APIは本番環境での使用を想定して設計されています。商用アプリケーションに対する制限はありません。
最大同時生成制限はどのくらいですか?
APIはレート制限を介して同時リクエストを処理します。大量のニーズがある場合は、エンタープライズ制限について2Slidesチームにお問い合わせください。
ジョブ完了のWebhookはありますか?
現在、ジョブエンドポイントを介したポーリングを使用してください。Webhookのサポートはロードマップに含まれています。
プレゼンテーションエージェントを構築しましょう — 2SlidesでAPIキーを取得して、プログラムでスライドの生成を開始してください。
About 2Slides
Create stunning AI-powered presentations in seconds. Transform your ideas into professional slides with 2slides AI Agent.
Try For Free