跳转到内容

智能体 AI 地牢游戏

通过本教程,您将使用 @aws/nx-plugin 构建一个智能体 AI 驱动的地牢冒险游戏。本教程不假设您对 @aws/nx-plugin 或相关技术有任何现有知识。 您将在本教程中学到的技术将帮助您:

  • 构建任何基于 @aws/nx-plugin 的应用程序,
  • 深入理解 @aws/nx-plugin,以及
  • 获得如何使用 NX 框架的基本理解。

在教程结束时,您将掌握以下知识:

  • 使用 @aws/nx-plugin 创建新应用程序,
  • 使用 NX 管理/构建代码库,
  • 使用 tRPC 构建 API,
  • 使用 Strands 构建智能体,
  • 使用 TypeScript 构建 MCP 服务器,
  • 使用 Tanstack router 创建新页面,
  • 使用 Tanstack query 调用后端 API,
  • 在 DynamoDB 中建模数据并在本地针对 DynamoDB Local 进行开发,以及
  • 创建和部署 CDK 基础设施。

在本教程中,您将使用 @aws/nx-plugin 构建一个智能体 AI 驱动的地牢冒险游戏。

游戏界面将类似于以下图示:

game-select.png
game-conversation.png

智能体 AI 驱动的地牢冒险游戏使用以下架构构建:

Web BrowserCognito / IAMCloudFrontStatic Assets(S3)API Gateway(Game API)tRPC API(Lambda)Story Agent(AgentCore)Inventory MCP(AgentCore)Game State(DynamoDB)Story Sessions(S3) Sign in Read transcripts AG-UI stream Persist turns Tool calls
  • React/Vite 前端网站,使用:
    • Amazon Cognito/Identity Pools 进行安全的 API 调用。
    • Tanstack router,支持类型安全的基于文件的路由。
    • 用于调用 Game API 的生成 SDK。
  • tRPC API,使用 ElectroDB/DynamoDB 管理游戏状态。
  • 托管在 Amazon Bedrock AgentCore 上的 Strands 智能体,用于运行游戏。
  • 托管在 Amazon Bedrock AgentCore 上的 TypeScript MCP 服务器,供智能体管理玩家的库存。
  • CDK 基础设施,用于部署应用程序。

在继续之前,您需要以下全局依赖项:

  • Git
  • Node >= 22(我们建议使用类似 NVM 的工具来管理您的 node 版本)
    • 通过运行 node --version 来验证
  • UV >= 0.5.29
    1. 通过运行以下命令安装 Python 3.14:uv python install 3.14.0
    2. 使用 uv python list --only-installed 验证
  • AWS Credentials 配置到您的目标 AWS 账户,因为本教程会部署应用程序并调用 Amazon Bedrock
  • Docker(或 Finch)是本地 DynamoDB 开发和构建 AgentCore 组件所必需的