可易

用自然语言在 Amazon Bedrock AgentCore 上构建仪表板自动化智能体

可易团队阅读约 14 分钟

用查找、修改和编排三个智能体,先校验列再新建仪表板版本,把数日的改表请求变成可回滚的自然语言操作。

目录

#用自然语言在 Amazon Bedrock AgentCore 上构建仪表板自动化智能体

业务分析师在响应变化的业务需求时,常常要等上数日才能完成仪表板(dashboard)修改。传统流程是向 IT 团队提交修改请求,由他们理解需求、查阅 API 文档、弄清表结构并部署变更。虽然这种方式保持了应有的监督和质量控制,但在需要快速更新仪表板时,周转时间可能长达数日。

本方案结合 Amazon Bedrock AgentCore、Strands Agents 和 Amazon Quick 转换,交付一套安全、可扩展、智能的系统,用于构建和运行 AI 智能体(Agent),同时把数据变成可执行的业务洞察。

方案概览

在本方案中,我们使用基于 Amazon Bedrock AgentCore 和 Strands 框架构建的多智能体架构。Amazon Bedrock AgentCore 是一个智能体平台,用于安全地大规模构建、部署和运行有效的智能体,无需管理基础设施。它用智能记忆(memory)和网关加速智能体进入生产,以便安全、受控地访问工具和数据。它以生产级安全性和动态扩缩运行智能体,并在生产中监控性能与质量。Strands Agents 是一个代码优先的框架,用于构建与 AWS 服务集成的智能体。本方案还使用 Amazon Quick,它提供由 AI 驱动的商业智能(BI)能力,把分散的数据变成每个人都能用的战略洞察,从而更快决策并取得更好的业务结果。

该架构由三个协同工作的专用智能体组成。_查找仪表板智能体(Find Dashboard Agent)_ 执行发现操作,包括搜索仪表板,以及从仪表板和数据集检索列元数据。_修改仪表板智能体(Modify Dashboard Agent)_ 通过校验列、更新表格可视化并创建新的仪表板版本来执行配置变更。_编排智能体(Orchestrator Agent)_ 根据意图分类把用户请求路由到相应的专用智能体。

编排智能体是用户交互的入口。当用户提交像 “Add lastname to the testing dashboard” 这样的自然语言查询时,Amazon Nova 把请求分类为对话类或操作类。对话类查询使用 Nova 的大语言模型(large language model,LLM)能力直接回答。操作类请求通过 Strands 框架路由到专用智能体,对照可用的数据集列校验变更,并在维持安全控制、审计轨迹以及保留原始仪表板以便回滚(rollback)的同时,自主执行修改。下图说明方案架构和工作流。

该架构包含以下组件:

  • Amazon Bedrock AgentCore:托管 Strands 智能体编排器及专用子智能体。
  • Amazon Nova:提供自然语言处理(natural language processing,NLP)和推理能力。
  • Amazon Quick:仪表板发现和修改操作的目标服务。
  • AgentCore Memory:维护对话上下文和会话状态。
  • Amazon Bedrock AgentCore Observability:记录智能体决策并跟踪 API 交互。

要为 Quick 自助服务实现该智能体 AI 方案,完成以下高层步骤:

  1. 构建智能体(查找仪表板智能体、修改仪表板智能体和编排智能体)。
  2. 把智能体部署到 Amazon Bedrock AgentCore。
  3. 通过 AWS 管理控制台测试智能体。

前提条件

要实现本方案,你必须具备以下前提:

  • 一个对 Amazon Bedrock、Amazon Quick 和 AWS Identity and Access Management(IAM)有权限的 AWS 账户。关于创建新仪表板,更多信息见创建 Amazon Quick 仪表板。
  • 一个已有仪表板的活动 Amazon Quick 账户(创建指南)。
  • 已配置 IAM 权限,授予智能体访问 Quick 应用程序编程接口(Application Programming Interface,API)的权限:
  • quicksight:ListDashboards
  • quicksight:DescribeDashboard
  • quicksight:DescribeDashboardDefinition
  • quicksight:DescribeDataSet
  • quicksight:CreateDashboard
  • Python 3.10 或更高版本(直接代码部署支持 Python 3.10–3.13)。
  • 已安装 uv 包管理器(安装指南)。
  • 已用适当凭据配置 AWS 命令行界面(AWS Command Line Interface,AWS CLI)。
  • 对 Python 和 AWS 服务有基本了解。

演练

要使用 Amazon Bedrock AgentCore 构建、部署并测试由 AI 驱动的仪表板自动化方案,按以下四步进行:

步骤 1:构建用于查找和修改仪表板的 Quick 自助智能体

构建驱动 Quick 自助方案的三个核心智能体:

  1. 用于发现操作的查找仪表板智能体。
  2. 用于修改操作的修改仪表板智能体。
  3. 在二者之间协调的编排智能体。

下面分别看每个智能体的角色和实现。

1.1 构建查找仪表板智能体

该智能体处理后续查看或修改动作所需的仪表板发现操作。例如,当用户提交 “show me a report with name ‘testing’” 这样的自然语言查询时,编排器调用该智能体,后者执行 list_dashboards API 以检索仪表板元数据,按搜索条件过滤结果,并以结构化格式返回匹配的仪表板。

这个发现智能体提供三项核心能力:支持精确和部分名称匹配的仪表板搜索、列出账户中的可用仪表板,以及从仪表板及其底层数据集检索列信息。这些发现功能是仪表板操作的前提,因为在执行修改或检索之前,必须先识别目标仪表板。

每项能力都实现为一个 Strands @tool 函数。下面的片段展示查找仪表板工具,它调用 list_dashboards API,并用部分名称匹配过滤结果:

from strands import Agent, tool
from strands.models import BedrockModel

@tool

def find_dashboard_tool(dashboard_name: str = "") -> str:
  """Find Quick dashboards by name (supports partial matching)"""
  client = boto3.client('quicksight', region_name=REGION)

  response = client.list_dashboards(AwsAccountId=AWS_ACCOUNT_ID)

  dashboards = response.get('DashboardSummaryList', [])

  # List all dashboards if no search term provided

  if not dashboard_name or dashboard_name.strip() == "":
   all_names = [d['Name'] for d in dashboards]
   return f"All dashboards ({len(all_names)}): {all_names}"

  # Filter using case-insensitive partial matching

  matches = [d['Name'] for d in dashboards if dashboard_name.lower() in d['Name'].lower()]
      return f"Found {len(matches)} dashboards: {matches}"

然后,智能体把这些工具函数包进一个 Strands Agent,并把自身暴露为 @tool,以便编排器用自然语言查询调用它:

_find_agent = Agent(
  model=BedrockModel(model_id=MODEL_ID),
  tools=[find_dashboard_tool, get_columns_tool],
  system_prompt="You are the Find Dashboard Agent. Help users find dashboards and view columns."

)

@tool

def find_dashboard_agent(query: str) -> str:
 """Agent wrapper exposed as a tool for the orchestrator to invoke"""
 response = _find_agent(query)
 return str(response)

这种“智能体即工具”的模式使多智能体架构成为可能。编排器不直接调用 Quick API,而是调用该智能体,由它在内部处理自然语言理解和 API 调用。

1.2 构建修改仪表板智能体

有了发现能力之后,下一个智能体通过“先校验”工作流处理仪表板配置变更。考虑一个用户请求,例如 “add lastname to the testing dashboard.”。编排器把它路由到修改仪表板智能体,后者校验该列存在于数据集模式中,使用 describe_dashboard_definition API 检索完整的仪表板定义,更新表格可视化的字段井和字段选项,并使用 create_dashboard API 创建新的仪表板版本。

该修改智能体支持两项主要操作:向仪表板添加列(先校验所请求的列存在于底层数据集、但尚未出现),以及从仪表板移除列(先确认该列当前正在显示)。它不是修改现有仪表板,而是创建带唯一标识符的新仪表板,保留原始仪表板以供审计,并在需要时支持回滚。

这种先校验的方法有助于校验数据完整性并防止配置错误,而保留原始仪表板则支持满足治理要求,并为修改提供审计轨迹。

下面的片段展示核心修改工具。它校验请求,更新仪表板定义中表格可视化的字段井,并创建新仪表板:

@tool

def modify_dashboard(dashboard_name: str, action: str, column_name: str) -> str:
"""Modify a dashboard by adding or removing columns"""
client = boto3.client('quicksight', region_name=REGION)
info = _get_dashboard_and_dataset_info(dashboard_name)

# Validation-first: verify column state before making changes
if action == "add":
if column_name in info["dashboard_columns"]:
return f"Column '{column_name}' is already in the dashboard."
if column_name not in info["dataset_columns"]:
return f"Column '{column_name}' doesn't exist in dataset."
elif action == "remove":
if column_name not in info["dashboard_columns"]:
return f"Column '{column_name}' is not in the dashboard."

# Update table visual field wells in the dashboard definition
updated_definition = info["definition"]
for sheet in updated_definition.get('Sheets', []):
for visual in sheet.get('Visuals', []):
if 'TableVisual' in visual:
field_wells = visual['TableVisual']['ChartConfiguration']['FieldWells']
existing_fields = field_wells['TableAggregatedFieldWells']['GroupBy']
if action == "add":
existing_fields.append({
'CategoricalDimensionField': {
'FieldId': str(uuid.uuid4()),
'Column': {
'DataSetIdentifier': dataset_id,
'ColumnName': column_name
}
}
})

elif action == "remove":
existing_fields = [f for f in existing_fields\
if f['CategoricalDimensionField']['Column']['ColumnName'] != column_name]

# Create new dashboard with UUID suffix, original is preserved for rollback
new_uuid = str(uuid.uuid4())[:8]
client.create_dashboard(
AwsAccountId=AWS_ACCOUNT_ID,
DashboardId=f"dashboard_{new_uuid}",
Name=f"{info['dashboard_name']}_dashboard_{new_uuid}",
Definition=updated_definition
)

与查找仪表板智能体一样,该工具被包进一个 Strands Agent,并作为 @tool 暴露给编排器:

_modify_agent = Agent(
model=BedrockModel(model_id=MODEL_ID),
tools=[modify_dashboard],
system_prompt="You are the Modify Dashboard Agent. You add or remove columns from dashboards."
)

@tool
def modify_dashboard_agent(query: str) -> str:
"""Agent wrapper for the orchestrator to invoke with natural language"""
response = _modify_agent(query)
return str(response)

智能体从用户的自然语言查询中提取仪表板名称、动作和列名,并把它们传给 modify_dashboard 工具,由该工具处理校验和执行。

1.3 创建编排智能体

最后一个组件在 Strands 框架内把查找仪表板智能体和修改仪表板智能体作为工具来协调。该编排器定义系统提示以指示路由逻辑,指明哪个智能体处理发现操作、哪个处理修改操作。配置中注册了两个专用智能体作为工具,使编排器能根据已分类的意图调用它们。

路由逻辑通过自然语言理解处理多种查询模式。包含仪表板名称和列名等显式参数的直接请求,会立即委派给相应的专用智能体。缺少必要参数的含糊请求会触发追问,以收集缺失信息后再路由。这种实现模式使编排器作为协调者而不是执行者:它把 Quick API 操作委派给专用智能体,自己只专注于意图分析和路由决策。

下面的片段展示编排器把两个智能体注册为工具,并通过系统提示定义路由逻辑:

from find_dashboard_agent import find_dashboard_agent
from modify_dashboard_agent import modify_dashboard_agent
orchestrator = Agent(
model=BedrockModel(model_id=MODEL_ID),
tools=[find_dashboard_agent, modify_dashboard_agent],
system_prompt="""You are an Amazon Quick Orchestrator. Route user requests to specialized agents.

AGENTS:
- find_dashboard_agent: Finding dashboards, listing, showing columns
- modify_dashboard_agent: Adding/removing columns

ROUTING LOGIC:
- "find", "show", "list", "get", "columns" → find_dashboard_agent
- "add", "remove", "modify", "delete" → modify_dashboard_agent"""
)

Bedrock AgentCore 集成把该编排器暴露为接收用户请求的入口:

app = BedrockAgentCoreApp()
@app.entrypoint
def invoke(payload):
user_input = payload.get("prompt", "")
response = orchestrator(user_input)
return response.message['content'][0]['text']

因为 find_dashboard_agent 和 modify_dashboard_agent 各自被包成 @tool 函数,编排器把它们当作任何其他工具一样对待。Amazon Nova 分析用户意图,并自动调用相应的智能体。

步骤 2:为智能体部署建立项目

使用直接代码部署,把智能体部署到 Amazon Bedrock AgentCore。这包括初始化项目、添加依赖、创建智能体文件,以及部署到运行时环境。

2.1 初始化项目

使用 uv 包管理器建立一个新的 Python 项目,然后进入项目目录uv init quicksight-selfservice-agentcd quicksight-selfservice-agent这将创建一个新的项目结构,其中包含管理依赖和部署智能体所需的配置文件。

2.2 为项目添加依赖

为项目安装所需的 Amazon Bedrock AgentCore 库和开发工具。在本示例中,使用 uv add 命令添加依赖:

uv add bedrock-agentcore strands-agents strands-agents-tools

uv add --dev bedrock-agentcore-starter-toolkit

激活虚拟环境:

# For Linux/macOS

source .venv/bin/activate

# For Windows

source .venv/Scripts/activate

这些依赖提供构建和部署智能体的核心框架,包括用于创建智能体的 Strands SDK,以及用于部署管理的 Amazon Bedrock AgentCore 工具包。

2.3 创建 agent.py 文件

从 GitHub 仓库 下载完整实现的 zip 文件。解压该 zip,并把以下文件复制到项目根目录:

  • agent.py:带 Amazon Bedrock AgentCore 集成的主编排智能体入口
  • find_dashboard_agent.py:用于仪表板发现操作的专用智能体
  • modify_dashboard_agent.py:用于仪表板修改操作的专用智能体
  • shared/ 文件夹:包含用于共享 AWS 服务客户端配置的 config.py

其他所需文件,例如 pyproject.toml 和配置文件,已经是初始化步骤所建立项目的一部分。这些文件就位后,你就可以把 Quick 自助智能体部署到 Amazon Bedrock AgentCore。

步骤 3:部署到 Amazon Bedrock AgentCore Runtime

Amazon Bedrock AgentCore 提供托管环境来部署 Strands Agents,有两种部署选项:基于容器的部署和直接代码部署。对本方案,我们可以使用直接代码部署。

3.1 把智能体配置到 Amazon Bedrock AgentCore

运行以下命令来配置 Quick 自助智能体

agentcore configure --entrypoint agent.py --name qs_selfservice_agent

Detected dependency file: pyproject.toml
Press Enter to use this file, or type a different path (use Tab for autocomplete):
Path or Press Enter to use detected dependency file: pyproject.toml
✓ Using requirements file: pyproject.toml
Deployment Configuration
Select deployment type:
Direct Code Deploy (recommended) - Python only, no Docker required
Container - For custom runtimes or complex dependencies
Choice [1]: 1
Select Python runtime version:
PYTHON_3_10
PYTHON_3_11
PYTHON_3_12
PYTHON_3_13
Choice [4]: 4 ✓ Deployment type: Direct Code Deploy (python.3.13)
Execution Role
Press Enter to auto-create execution role, or provide execution role ARN/name to use existing
Execution role ARN/name (or press Enter to auto-create):
✓ Will auto-create execution role
S3 Bucket Press Enter to auto-create S3 bucket, or provide S3 URI/path to use existing S3 URI/path (or press Enter to auto-create):
✓ Will auto-create S3 bucket
Authorization Configuration  Note: AgentCore uses IAM authorization.
Configure OAuth authorizer instead? (yes/no) [no]:
✓ Using default IAM authorization
Request Header Allowlist Configure which request headers are allowed to pass through to your agent.
Common headers: Authorization, X-Amz-Bedrock-AgentCore-Session-.
Configure request header allowlist? (yes/no) [no]:
✓ Using default request header configuration
Configuring BedrockAgentCore agent: Agent1

Memory Configuration
Tip: Use --disable-memory flag to skip memory entirely

MemoryManager initialized for region: us-east-1
Existing memory resources found:
1. agent_mem-RLr7b8Hsif
ID: agent_mem-RLr7b8Hsif
2. orchestrator_agent_mem-kP9yQc96nd
ID: orchestrator_agent_mem-kP9yQc96nd
Options:
• Enter a number to use existing memory
• Press Enter to create new memory
• Type 's' to skip memory setup
Your choice:
✓ Short-term memory will be enabled (default)
• Stores conversations within sessions
• Provides immediate context recall

Optional: Long-term memory
• Extracts user preferences across sessions
• Remembers facts and patterns
• Creates session summaries
• Note: Takes 120-180 seconds to process

Enable long-term memory? (yes/no) [no]:
✓ Using short-term memory only
Will create new memory with mode: STM_ONLY
Memory TTL duration: Short term only
Network mode: PUBLIC
Changing default agent from 'Agent1' to 'Agent2'

配置过程会提示你配置部署设置,包括部署类型(选择选项 1,即 Amazon Simple Storage Service(Amazon S3)部署),其余指令均使用默认值。

3.2 把智能体部署到 AgentCore Runtime 环境:

运行以下命令,把 Quick 自助智能体部署到 Amazon Bedrock

agentcore launch

该命令把代码构建并推送到 Amazon S3,并在 Amazon Bedrock AgentCore 中部署智能体,使其准备好接收和处理请求。

步骤 4:测试智能体

使用 AWS 管理控制台测试智能体。控制台通过 Amazon Bedrock AgentCore 界面提供内置测试环境。按以下步骤测试智能体:

  1. 进入 Amazon Bedrock AgentCore 控制台。
  2. 核验智能体已创建。
  3. 在 AWS 管理控制台中进入 Amazon Bedrock AgentCore 控制台。
  4. 在运行时资源列表中找到你的智能体(例如 qs_selfservice_agent),它应显示 “Ready” 状态,并在状态列有一个绿色对勾。
  5. 端点部分显示 DEFAULT 端点,状态为 “Ready”。
  6. 在智能体及其端点都显示 “Ready” 状态之后,你的智能体已成功创建并部署。
  7. 选择该智能体的 ‘DEFAULT’ 端点,然后测试端点。
Amazon Bedrock AgentCore Runtime 控制台,展示状态为 Ready 的 qs_selfservice_agent 配置、DEFAULT 端点、版本 1 和可观测性指标
  1. 在测试窗口中,提供以下提示来调用“查找仪表板智能体”:

_{“prompt” : “can you show dashboards with name testing”}_

Amazon Bedrock AgentCore 智能体沙箱测试界面,展示 qs_selfservice_agent、一条仪表板搜索查询输入,以及确认找到匹配仪表板的智能体响应
  1. 智能体回应它找到的相关仪表板数量。再进一步提示以修改仪表板,从而调用修改仪表板智能体。

_{“prompt” : “Can you add firstname column to the testing\_dashboad”}_

Amazon Bedrock AgentCore 智能体沙箱,展示 qs_selfservice_agent 成功向 QuickSight 测试仪表板添加 firstname 列,并给出详细的成功响应
  1. 初始的 “XYZ\_testing” 仪表板不包含 firstname 列,如下表所示。
employeenumberlastnameclientid
A1001LN1A
A1002LN2A
A1003LN3A
A1004LN4A
A1005LN5A
B1001LN6B
B1002LN7B
B1003LN8B
B1004LN9B
B1005LN10B
C1001LN11C
C1002LN12C
C1003LN13C
C1004LN14C
C1005LN15C
  1. 修改后的 “XYZ\_testing” 仪表板包含新添加的 firstname 列,如下表所示。
employeenumberlastnameclientidFirstname
A1001LN1AFN1
B1005LN10BFN10
C1001LN11CFN11
C1002LN12CFN12
C1003LN13CFN13
C1004LN14CFN14
C1005LN15CFN15
A1002LN2AFN2
A1003LN3AFN3
A1004LN4AFN4
A1005LN5AFN5
B1001LN6BFN6
B1002LN7BFN7
B1003LN8BFN8
B1004LN9BFN9

如你所见,firstname 列已成功添加,并且已创建新修改的仪表板。你已经创建了一个方案,它使用由 Amazon Bedrock AgentCore 和 Strands 框架驱动的多智能体架构,使自助仪表板管理能够查找仪表板或修改仪表板。你还创建了一个根据意图智能路由用户请求的编排智能体。

清理

为避免今后产生费用,删除以下资源:

  1. 删除 AgentCore Runtime 部署,使用 AWS 控制台或 CLI:
aws bedrock-agentcore delete-agent-runtime --agent-id <agent-id> --region <region>
  1. 移除 ECR 仓库:进入 Amazon Elastic Container Registry(Amazon ECR)控制台,删除部署期间创建的容器仓库,或使用以下 CLI 命令:
aws ecr delete-repository --repository-name <repository-name> --region <region> --force
  1. 移除测试用 Quick 仪表板:进入 Amazon Quick 控制台,删除测试期间创建的带 UUID 后缀的已修改仪表板版本,或使用以下 CLI 命令:
aws quicksight delete-dashboard --aws-account-id <account-id> --dashboard-id <dashboard-id> --region <region>
  1. 删除 Amazon CloudWatch 日志组:进入 Amazon CloudWatch 控制台,移除与该智能体关联的日志组(格式:/aws/bedrock/agentcore/<agent-id>),或使用以下 CLI 命令:
aws logs delete-log-group --log-group-name /aws/bedrock/agentcore/<agent-id> --region <region>

结论

在本文中,我们结合 Strands Agents、Amazon Bedrock AgentCore 和 Amazon Nova,把长达数日的仪表板修改请求变成数秒级的自然语言交互。编排器—子智能体模式可以超出 Quick,延伸到其他由 API 驱动、且业务用户依赖 IT 做日常变更的服务。使用该模式,组织可以构建自主 AI 系统,在保持企业安全、审计轨迹和回滚能力的同时,加快运营工作流。

试用该方案;如有任何评论或问题,请留在评论区。

PRIMARY_SOURCE: https://aws.amazon.com/blogs/machine-learning/build-ai-powered-dashboard-automation-agents-with-nlp-on-amazon-bedrock-agentcore

  • #Amazon Quick
  • #AgentCore
  • #仪表板
  • #回滚
  • #自然语言