Skip to content

feat: AgentCore Runtime improvements — MCP server_instructions, iteration limit, Code Interpreter option, S3 link format#1526

Open
okamoto-aws wants to merge 17 commits intomainfrom
fix/mcp-server-instructions
Open

feat: AgentCore Runtime improvements — MCP server_instructions, iteration limit, Code Interpreter option, S3 link format#1526
okamoto-aws wants to merge 17 commits intomainfrom
fix/mcp-server-instructions

Conversation

@okamoto-aws
Copy link
Copy Markdown
Collaborator

@okamoto-aws okamoto-aws commented Apr 9, 2026

Summary

AgentCore Runtime の汎用的な機能改善をまとめたPRです。MCP サーバーとの連携を強化し、ビルトインツールを拡充して、複雑なワークフローへの対応力を向上させます。

Changes

1. MCP Server Instructions の注入

MCP サーバーが提供する server_instructions を収集し、エージェントのシステムプロンプトに注入するようにしました。これにより、MCP サーバーが自身のツールの使い方をエージェントに直接伝えられるようになります。

  • tools.py: MCP クライアント初期化時に server_instructions を収集
  • agent.py: 収集した instructions をシステムプロンプトに追加
  • strands-agents を 1.34.1 にアップグレード(server_instructions サポートに必要)

2. ARM64 platform 指定

x86_64 ホスト(Intel/AMD)で Docker ビルドする際に ARM64 イメージが正しくビルドされるよう、CDK の platform を明示的に指定しました。

3. DEFAULT_MAX_ITERATIONS 100

デフォルトのイテレーション上限を 20 → 100 に変更しました。複数ツールを組み合わせる複雑な MCP ワークフローでは 20 回では不足するケースがありました。

4. agentCoreCodeInterpreterEnabled オプション

AgentCore チャットで Code Interpreter を有効化するオプションを新設しました。

  • cdk.json / parameter.tsagentCoreCodeInterpreterEnabled: true を設定可能
  • フロントエンド(AgentCorePage)から code_execution_enabled パラメータとして渡される
  • AgentBuilder では従来通り UI から設定可能、AgentCore チャットではこのオプションで制御
  • なお、Code Interpreter のサンドボックスはホストのファイルシステムと分離されており、MCP ツールとのファイル共有はできません

5. S3 URL の Markdown リンク形式出力

upload_file_to_s3_and_retrieve_s3_url で取得した S3 URL を、画像以外のファイル(.pptx, .csv, .pdf 等)でも Markdown リンク形式([filename](URL))で出力するようシステムプロンプトに追記しました。フロントエンドの LinkRenderer が S3 URL を検出して presigned URL に変換するため、Markdown リンク形式でないとダウンロードリンクとして機能しません。

6. ビルトインツールの拡充

AgentCore Runtime に以下のビルトインツールを追加しました:

ツール 機能
write_file /tmp/ws 配下へのファイル作成・追記・部分置換(str_replace モード)
concat_files 複数ファイルの結合(LLM 出力のタイムアウト回避に有用)
web_fetch URL からテキストコンテンツを取得(HTML 自動ストリップ)

write_file は Code Interpreter のサンドボックス分離問題を解決します。エージェントがホストのファイルシステムに直接ファイルを書き込めるため、MCP ツールがそのファイルを読み取れます。

concat_files は LLM の出力制限によるタイムアウトを回避するために、分割書き出し → 結合のワークフローを可能にします。

web_fetch はエージェントが URL からドキュメントや参考資料を取得できるようにします。

7. ドキュメント・テスト更新

  • 英語版・日本語版 DEPLOY_OPTION.md に agentCoreCodeInterpreterEnabled の説明を追加
  • CDK テストスナップショットを更新

Testing

  • AgentCore チャットおよび AgentBuilder で、MCP サーバー(stdio)のツール呼び出し → ファイル生成 → S3 アップロード → ダウンロードリンク提示の一連のフローを検証済み
  • ARM64 ネイティブ環境(CodeBuild ARM_CONTAINER)でのコンテナビルドを検証済み

Breaking Changes

なし。全て後方互換性のある変更です。agentCoreCodeInterpreterEnabled はデフォルト false で既存の動作に影響しません。

Checklist

  • Modified relevant documentation
  • Verified operation in local environment
  • Executed npm run cdk:test and updated snapshots with npm run cdk:test:update-snapshot

Shintaro Okamoto added 9 commits April 9, 2026 22:52
The UI's LinkRenderer detects S3 URLs in Markdown links and converts
them to presigned URLs for download. Without Markdown link format,
S3 URLs for non-image files (e.g. .pptx) are rendered as plain text
and cannot be downloaded.
- Revert cdk.json formatting noise and createGenericAgentCoreRuntime
  back to false (default)
- Add agentCoreCodeInterpreterEnabled to correct location (default false)
- Add agentCoreCodeInterpreterEnabled to English DEPLOY_OPTION.md
- Remove sdpm-specific example from Japanese DEPLOY_OPTION.md
- Update CDK test snapshots
@okamoto-aws okamoto-aws force-pushed the fix/mcp-server-instructions branch from e449f5c to 99e44aa Compare April 9, 2026 13:53
Shintaro Okamoto added 5 commits April 9, 2026 23:24
Adds a write_file tool that allows agents to create and append to files
under /tmp/ws without requiring Code Interpreter. This enables MCP tools
that expect file paths (e.g. generate_pptx with slides_json_path) to
work without the Code Interpreter sandbox isolation issue.

Path traversal is prevented by requiring all paths to be under WORKSPACE_DIR.
Allows agents to fetch text content from URLs. HTML is automatically
stripped of scripts/styles/tags for readability. Useful for reading
documentation, reference materials, or API responses.
Comment thread packages/cdk/lambda-python/generic-agent-core-runtime/src/tools.py Fixed
@okamoto-aws okamoto-aws marked this pull request as ready for review April 9, 2026 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants