Skip to content

Commit a9aacbb

Browse files
okamoto-awsShintaro Okamoto
andauthored
feat: GenU (Generative AI Use Cases on AWS) integration support (#30)
* feat: add SDPM_OUTPUT_DIR env var override for container environments * docs: add GenU integration guide (Option 4) to add-to-gateway * Auto-fill fonts and defaultTextColor from template in generate() When presentation.json lacks fonts or defaultTextColor (e.g. when an agent writes slides directly without using init_presentation workflow), auto-detect them from the resolved template file instead of raising ValueError. * Add slides_json parameter to generate_pptx for sandbox environments AgentCore Code Interpreter runs in a sandboxed environment where files written via writeFiles are not accessible from the host filesystem. This means MCP tools like generate_pptx cannot read files created by the Code Interpreter. Add slides_json parameter that accepts JSON string directly as a tool argument, writes it to a temp file, and passes it to the generator. This allows agents to pass presentation data without filesystem access. * Add slides_json guidance to server_instructions for sandboxed environments Instruct agents to use slides_json parameter instead of Code Interpreter writeFiles, since the CI sandbox is isolated from MCP tool filesystem. * Add GenU usage guide with sample prompts for AgentCore Chat and AgentBuilder Document slides_json parameter requirement, Code Interpreter sandbox isolation, and Markdown link format for S3 URLs. Includes sample system prompt for AgentBuilder. * Revert "Add slides_json guidance to server_instructions for sandboxed environments" This reverts commit 89c8333. * Rewrite Option 4 docs: separate AgentCore Chat and AgentBuilder - Add comparison table (mcp.json path, CDK option, system prompt) - Prerequisites now list both CDK options separately - Step 3 clarifies which mcp.json to edit for each use case - AgentBuilder section includes sample system prompt * Fix: use English sample request in English docs * style: apply ruff formatting * fix: suppress bandit B108 for SDPM_OUTPUT_DIR fallback * fix: use tempfile.gettempdir() instead of hardcoded /tmp * docs: update AgentBuilder prompt for write_file + concat_files workflow Replace slides_json approach with write_file split-and-concat strategy to avoid LLM output timeouts on large JSON. Include str_replace for incremental error fixes. * docs: focus Option 4 on AgentBuilder with write_file/concat_files workflow * revert: remove slides_json parameter from generate_pptx write_file built-in tool in GenU makes this unnecessary. --------- Co-authored-by: Shintaro Okamoto <shintaok@amazon.com>
1 parent d7d865b commit a9aacbb

4 files changed

Lines changed: 311 additions & 31 deletions

File tree

‎docs/en/add-to-gateway.md‎

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,110 @@ The JWT `sub` claim is used as the user identity throughout the stack:
148148
- Audit trail
149149

150150
No additional user registration is needed — any valid JWT with a `sub` claim works.
151+
152+
---
153+
154+
## Option 4: Generative AI Use Cases on AWS (GenU) Integration
155+
156+
> **Note:** [Generative AI Use Cases on AWS (GenU)](https://github.com/aws-samples/generative-ai-use-cases-jp) is a separate open-source project under active development. The steps below are based on GenU v5.x as of April 2026 and may change in future releases.
157+
158+
[GenU](https://github.com/aws-samples/generative-ai-use-cases-jp) is an open-source web application that provides various generative AI use cases on AWS. GenU's **AgentBuilder** lets users create custom agents with selected MCP tools and a tailored system prompt. By bundling spec-driven-presentation-maker into the AgentCore Runtime container, users can generate presentations from GenU's web interface.
159+
160+
### Prerequisites
161+
162+
- GenU repository cloned and deployable (see [GenU README](https://github.com/aws-samples/generative-ai-use-cases-jp))
163+
- Docker available on the build machine (required for AgentCore container image build)
164+
- On x86_64 hosts (Intel/AMD), run `docker run --privileged --rm tonistiigi/binfmt --install arm64` before deploying (AgentCore requires ARM64 container images)
165+
- **AgentBuilder enabled** in `packages/cdk/cdk.json` or `parameter.ts`: `agentBuilderEnabled: true`
166+
167+
### Step 1: Copy sdpm files into the GenU AgentCore Runtime directory
168+
169+
```bash
170+
GENU_RUNTIME_DIR=<path-to-genu>/packages/cdk/lambda-python/generic-agent-core-runtime
171+
172+
cp -r <path-to-sdpm>/skill $GENU_RUNTIME_DIR/sdpm-skill
173+
cp -r <path-to-sdpm>/mcp-local $GENU_RUNTIME_DIR/sdpm-mcp-local
174+
```
175+
176+
### Step 2: Patch the Dockerfile
177+
178+
Add the following lines to `$GENU_RUNTIME_DIR/Dockerfile`, **before** the `EXPOSE` line:
179+
180+
```dockerfile
181+
# --- SDPM: spec-driven-presentation-maker ---
182+
COPY sdpm-skill/ ./sdpm-skill/
183+
COPY sdpm-mcp-local/ ./sdpm-mcp-local/
184+
RUN uv pip install --python /tmp/.venv/bin/python ./sdpm-skill
185+
RUN /tmp/.venv/bin/python sdpm-skill/scripts/download_aws_icons.py \
186+
&& /tmp/.venv/bin/python sdpm-skill/scripts/download_material_icons.py
187+
RUN ln -s /var/task/sdpm-skill /var/task/skill
188+
```
189+
190+
### Step 3: Register the MCP server
191+
192+
Add the following entry to `$GENU_RUNTIME_DIR/mcp-configs/agent-builder/mcp.json` under `mcpServers`:
193+
194+
```json
195+
"spec-driven-presentation-maker": {
196+
"command": "python",
197+
"args": ["sdpm-mcp-local/server.py"],
198+
"env": {
199+
"PYTHONPATH": "/var/task/sdpm-skill",
200+
"SDPM_OUTPUT_DIR": "/tmp/ws"
201+
}
202+
}
203+
```
204+
205+
`SDPM_OUTPUT_DIR` tells the skill where to write generated files. GenU requires output files under `/tmp/ws` so that `upload_file_to_s3_and_retrieve_s3_url` can upload them to S3.
206+
207+
### Step 4: Deploy
208+
209+
```bash
210+
cd <path-to-genu>
211+
npx -w packages/cdk cdk deploy --all
212+
```
213+
214+
### Step 5: Create an agent in AgentBuilder
215+
216+
In GenU's AgentBuilder UI:
217+
218+
1. Select `spec-driven-presentation-maker` from the MCP server list
219+
2. Set the following system prompt:
220+
221+
```
222+
You are a presentation design assistant. Use the spec-driven-presentation-maker MCP tools to create PowerPoint slides.
223+
224+
Key rules:
225+
- Always call read_workflows first to load the workflow before making any design decisions.
226+
- When writing the presentation JSON, use the write_file tool to write to /tmp/ws/. Do NOT use Code Interpreter — its sandbox is isolated from MCP tools.
227+
- Large JSON must be split to avoid timeouts. Write each slide as a separate file (e.g. /tmp/ws/part1.json, /tmp/ws/part2.json), then use concat_files to join them into the final /tmp/ws/presentation.json.
228+
- Example split strategy:
229+
1. write_file("/tmp/ws/header.json", '{"template":"sample_template_dark","slides":[', mode="create")
230+
2. write_file("/tmp/ws/slide1.json", '{...slide 1 JSON...},', mode="create")
231+
3. write_file("/tmp/ws/slide2.json", '{...slide 2 JSON...}', mode="create")
232+
4. write_file("/tmp/ws/footer.json", ']}', mode="create")
233+
5. concat_files(source_paths=["/tmp/ws/header.json","/tmp/ws/slide1.json","/tmp/ws/slide2.json","/tmp/ws/footer.json"], destination="/tmp/ws/presentation.json")
234+
6. generate_pptx(slides_json_path="/tmp/ws/presentation.json", template="sample_template_dark")
235+
- If a JSON error occurs, use write_file with mode="str_replace" to fix the specific part instead of rewriting the entire file.
236+
- After generating the PPTX, upload it with upload_file_to_s3_and_retrieve_s3_url and provide the S3 URL as a Markdown link: [filename.pptx](S3_URL)
237+
```
238+
239+
### How it works
240+
241+
```
242+
User → GenU AgentBuilder UI → Strands Agent (AgentCore Runtime)
243+
├── sdpm MCP tools (stdio)
244+
│ ├── generate_pptx → /tmp/ws/*.pptx
245+
│ └── search_assets, analyze_template, ...
246+
├── write_file, concat_files (built-in)
247+
└── upload_file_to_s3_and_retrieve_s3_url
248+
└── S3 URL → User
249+
```
250+
251+
### Writing large files
252+
253+
LLM output can time out when generating large JSON in a single tool call. To avoid this:
254+
255+
1. Use `write_file` to write each part as a separate file
256+
2. Use `concat_files` to join them into the final file
257+
3. Use `write_file` with `mode="str_replace"` to fix errors without rewriting everything

‎docs/ja/add-to-gateway.md‎

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,110 @@ requestHeaderConfiguration: {
141141

142142
- [はじめに](getting-started.md) — セットアップとデプロイ手順
143143
- [アーキテクチャ](architecture.md) — 認証・認可モデルの詳細
144+
145+
---
146+
147+
## オプション 4: Generative AI Use Cases on AWS (GenU) 連携
148+
149+
> **注意:** [Generative AI Use Cases on AWS (GenU)](https://github.com/aws-samples/generative-ai-use-cases-jp) は活発に開発が行われている別のオープンソースプロジェクトです。以下の手順は 2026 年 4 月時点の GenU v5.x に基づいており、今後のリリースで変更される可能性があります。
150+
151+
[GenU](https://github.com/aws-samples/generative-ai-use-cases-jp) は、多様な生成 AI ユースケースを AWS 上で提供するオープンソース Web アプリケーションです。GenU の **AgentBuilder** を使うと、選択した MCP ツールとカスタムシステムプロンプトでエージェントを作成できます。AgentCore Runtime コンテナに spec-driven-presentation-maker をバンドルすることで、GenU の Web インターフェースからプレゼンテーションを生成できます。
152+
153+
### 前提条件
154+
155+
- GenU リポジトリがクローン済みでデプロイ可能な状態([GenU README](https://github.com/aws-samples/generative-ai-use-cases-jp) 参照)
156+
- ビルドマシンで Docker が利用可能(AgentCore コンテナイメージのビルドに必要)
157+
- x86_64 ホスト(Intel/AMD)では、デプロイ前に `docker run --privileged --rm tonistiigi/binfmt --install arm64` を実行(AgentCore は ARM64 コンテナイメージを要求)
158+
- `packages/cdk/cdk.json` または `parameter.ts` で **AgentBuilder を有効化**: `agentBuilderEnabled: true`
159+
160+
### Step 1: sdpm ファイルを GenU AgentCore Runtime ディレクトリにコピー
161+
162+
```bash
163+
GENU_RUNTIME_DIR=<path-to-genu>/packages/cdk/lambda-python/generic-agent-core-runtime
164+
165+
cp -r <path-to-sdpm>/skill $GENU_RUNTIME_DIR/sdpm-skill
166+
cp -r <path-to-sdpm>/mcp-local $GENU_RUNTIME_DIR/sdpm-mcp-local
167+
```
168+
169+
### Step 2: Dockerfile のパッチ
170+
171+
`$GENU_RUNTIME_DIR/Dockerfile` の `EXPOSE` 行の**前**に以下を追加します:
172+
173+
```dockerfile
174+
# --- SDPM: spec-driven-presentation-maker ---
175+
COPY sdpm-skill/ ./sdpm-skill/
176+
COPY sdpm-mcp-local/ ./sdpm-mcp-local/
177+
RUN uv pip install --python /tmp/.venv/bin/python ./sdpm-skill
178+
RUN /tmp/.venv/bin/python sdpm-skill/scripts/download_aws_icons.py \
179+
&& /tmp/.venv/bin/python sdpm-skill/scripts/download_material_icons.py
180+
RUN ln -s /var/task/sdpm-skill /var/task/skill
181+
```
182+
183+
### Step 3: MCP サーバーの登録
184+
185+
`$GENU_RUNTIME_DIR/mcp-configs/agent-builder/mcp.json` の `mcpServers` に以下を追加します:
186+
187+
```json
188+
"spec-driven-presentation-maker": {
189+
"command": "python",
190+
"args": ["sdpm-mcp-local/server.py"],
191+
"env": {
192+
"PYTHONPATH": "/var/task/sdpm-skill",
193+
"SDPM_OUTPUT_DIR": "/tmp/ws"
194+
}
195+
}
196+
```
197+
198+
`SDPM_OUTPUT_DIR` は生成ファイルの出力先を指定します。GenU は `/tmp/ws` 配下のファイルのみ S3 にアップロードできるため、この設定が必要です。
199+
200+
### Step 4: デプロイ
201+
202+
```bash
203+
cd <path-to-genu>
204+
npx -w packages/cdk cdk deploy --all
205+
```
206+
207+
### Step 5: AgentBuilder でエージェントを作成
208+
209+
GenU の AgentBuilder UI で:
210+
211+
1. MCP サーバーリストから `spec-driven-presentation-maker` を選択
212+
2. 以下のシステムプロンプトを設定:
213+
214+
```
215+
あなたはプレゼンテーション設計アシスタントです。spec-driven-presentation-maker の MCP ツールを使って PowerPoint スライドを作成してください。
216+
217+
重要なルール:
218+
- デザインの決定を行う前に、必ず read_workflows を呼び出してワークフローを読み込んでください。
219+
- プレゼンテーション JSON の書き込みには write_file ツールを使い、/tmp/ws/ に出力してください。Code Interpreter は使わないでください — サンドボックスが MCP ツールと分離されています。
220+
- 大きな JSON はタイムアウトを避けるため分割して書いてください。各スライドを別ファイルとして書き出し(例: /tmp/ws/part1.json, /tmp/ws/part2.json)、最後に concat_files で /tmp/ws/presentation.json に結合してください。
221+
- 分割の例:
222+
1. write_file("/tmp/ws/header.json", '{"template":"sample_template_dark","slides":[', mode="create")
223+
2. write_file("/tmp/ws/slide1.json", '{...スライド1のJSON...},', mode="create")
224+
3. write_file("/tmp/ws/slide2.json", '{...スライド2のJSON...}', mode="create")
225+
4. write_file("/tmp/ws/footer.json", ']}', mode="create")
226+
5. concat_files(source_paths=["/tmp/ws/header.json","/tmp/ws/slide1.json","/tmp/ws/slide2.json","/tmp/ws/footer.json"], destination="/tmp/ws/presentation.json")
227+
6. generate_pptx(slides_json_path="/tmp/ws/presentation.json", template="sample_template_dark")
228+
- JSON にエラーがある場合は、write_file の mode="str_replace" で該当箇所だけ修正してください。ファイル全体を書き直す必要はありません。
229+
- PPTX 生成後、upload_file_to_s3_and_retrieve_s3_url でアップロードし、S3 URL を Markdown リンク形式で提示してください: [ファイル名.pptx](S3_URL)
230+
```
231+
232+
### 動作の仕組み
233+
234+
```
235+
ユーザー → GenU AgentBuilder UI → Strands Agent (AgentCore Runtime)
236+
├── sdpm MCP ツール (stdio)
237+
│ ├── generate_pptx → /tmp/ws/*.pptx
238+
│ └── search_assets, analyze_template, ...
239+
├── write_file, concat_files (組み込み)
240+
└── upload_file_to_s3_and_retrieve_s3_url
241+
└── S3 URL → ユーザー
242+
```
243+
244+
### 大きなファイルの書き込み
245+
246+
LLM の出力は1回のツール呼び出しで大きな JSON を生成するとタイムアウトする場合があります。これを回避するには:
247+
248+
1. `write_file` で各パーツを別ファイルとして書き出す
249+
2. `concat_files` で最終ファイルに結合する
250+
3. エラー修正には `write_file` の `mode="str_replace"` を使い、全体の書き直しを避ける

‎mcp-local/server.py‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ def analyze_template(template_path: str, layout: str = "") -> str:
121121

122122

123123
@mcp.tool()
124-
def generate_pptx(slides_json_path: str, template: str = "", output_path: str = "") -> str:
124+
def generate_pptx(
125+
slides_json_path: str,
126+
template: str = "",
127+
output_path: str = "",
128+
) -> str:
125129
"""Generate PPTX from a JSON file. Call after building all slides.
126130
Template is auto-detected from presentation.json if init_presentation was used — no need to specify again.
127131
@@ -134,7 +138,9 @@ def generate_pptx(slides_json_path: str, template: str = "", output_path: str =
134138
JSON with output file path and slide summary.
135139
"""
136140
return json.dumps(
137-
_generate_pptx(slides_json_path=slides_json_path, template=template, output_path=output_path, skill_dir=_SKILL_DIR),
141+
_generate_pptx(
142+
slides_json_path=slides_json_path, template=template, output_path=output_path, skill_dir=_SKILL_DIR
143+
),
138144
ensure_ascii=False,
139145
)
140146

@@ -158,7 +164,9 @@ def get_preview(pptx_path: str, pages: str = "") -> str:
158164

159165

160166
@mcp.tool()
161-
def search_assets(query: str, limit: int = 20, source_filter: str = "", type_filter: str = "", theme_filter: str = "") -> str:
167+
def search_assets(
168+
query: str, limit: int = 20, source_filter: str = "", type_filter: str = "", theme_filter: str = ""
169+
) -> str:
162170
"""Search icons and assets by keyword. Use list_asset_sources to see available sources.
163171
Multiple keywords can be space-separated (e.g. "lambda s3 dynamodb") — each is searched independently.
164172
@@ -173,7 +181,14 @@ def search_assets(query: str, limit: int = 20, source_filter: str = "", type_fil
173181
JSON with matching icons/assets and their paths.
174182
"""
175183
return json.dumps(
176-
_search_assets(query=query, limit=limit, source_filter=source_filter, type_filter=type_filter, theme_filter=theme_filter, skill_dir=_SKILL_DIR),
184+
_search_assets(
185+
query=query,
186+
limit=limit,
187+
source_filter=source_filter,
188+
type_filter=type_filter,
189+
theme_filter=theme_filter,
190+
skill_dir=_SKILL_DIR,
191+
),
177192
ensure_ascii=False,
178193
)
179194

@@ -283,8 +298,15 @@ def read_guides(names: list[str]) -> str:
283298

284299

285300
@mcp.tool()
286-
def code_to_slide(code: str, language: str = "python", theme: str = "dark",
287-
x: int = 0, y: int = 0, width: int = 800, height: int = 300) -> str:
301+
def code_to_slide(
302+
code: str,
303+
language: str = "python",
304+
theme: str = "dark",
305+
x: int = 0,
306+
y: int = 0,
307+
width: int = 800,
308+
height: int = 300,
309+
) -> str:
288310
"""Generate slide elements JSON for a syntax-highlighted code block.
289311
290312
Args:

0 commit comments

Comments
 (0)