桃子桃子快讯
返回首页
工具

AWS Bedrock AgentCore Harness 上线:零编排代码搭建图像编辑 Agent

AWS 推出 Bedrock AgentCore harness,通过配置即可创建图像编辑 Agent,结合 Claud…

2026.07.08 · 周三9 分钟阅读

AWS 在 Amazon Bedrock 中推出 AgentCore harness,主打「配置即 Agent」的理念:开发者只需声明 agent 的能力,由平台自动负责编排循环、工具路由、会话记忆与运行环境,无需自行编写 Python 编排代码。本文以一个无服务器的图像编辑应用为例,演示了如何用 harness 快速搭建端到端方案——用户上传照片、用自然语言描述编辑需求,数秒内即可返回结果。整个方案(包括身份认证、加密存储、三种图像编辑工具与 React 前端)通过单一部署命令即可上线。

应用场景与技术栈

该应用支持「把车改成蓝色」「把图片向右扩展 200 像素」这类指令。底层由 Claude Sonnet 4.6 充当编排大脑,将需求拆解成多步骤任务并调用对应工具,执行完成后由运行在 microVM 上的 Python 脚本为结果添加水印(不消耗 token)。前端则将轻量对话路由到 Claude Haiku 4.5,将编辑任务路由到 Claude Sonnet 4.6,agent 在切换模型时保留完整会话上下文。

AgentCore harness 展示了以下几项关键能力:

  • 配置驱动建 Agent:完全通过 API 参数定义 agent,无需 Python 编排代码、框架或容器。
  • 单次调用内模型动态切换:harness 在同一次调用中根据任务类型路由到不同模型,并保持上下文。
  • 单次调用内人格覆盖:可切换 Real Estate、Retail、Automotive 等行业人设,向 system prompt 注入领域知识而无需重新部署。
  • 内置 30 天会话记忆:AgentCore Memory 服务存储对话历史,agent 在会话内可引用前序编辑。
  • AgentCore Gateway + MCP:通过 Model Context Protocol 暴露 AWS Lambda 后端的工具,由 harness 按 prompt 语义自动选择。
  • InvokeAgentRuntimeCommand:在 agent runtime microVM 上直接运行命令脚本(如加水印),不消耗模型 token。

四层架构

该图像编辑应用的架构分为四层:

  • AWS Amplify 上托管的 React 前端,负责上传图像、绘制 mask 与输入编辑指令。
  • AWS Lambda 代理层,作为浏览器凭证与 harness API 之间的安全边界,控制可用的 system prompt。
  • 挂载 AgentCore Memory 的 Amazon Bedrock AgentCore harness agent,负责会话持久化。
  • 三个工具 Lambda 函数,通过 Amazon Bedrock 调用 Stability AI 基础模型完成图像生成。

通过配置创建 Agent

使用 harness 时,agent 定义是一组传给 create_harness API 的参数。下例展示在 cdk deploy 期间创建 agent 的核心代码:

harness_params = { 'harnessName': 'img_editor', 'executionRoleArn': execution_role_arn, 'model': {'bedrockModelConfig': {'modelId': 'us.anthropic.claude-sonnet-4-6'}}, 'systemPrompt': [{'text': system_prompt}], 'tools': [{'type': 'agentcore_gateway', 'name': 'gateway', 'config': {'agentCoreGateway': {'gatewayArn': gateway_arn}}}], # 将 agent 限定在 gateway 暴露的三个工具,避免 wildcard 暴露所有工具 'allowedTools': [ 'inpaint-target___inpaint', 'outpaint-target___outpaint', 'search-replace-target___search_and_replace', ], 'maxIterations': 10, 'timeoutSeconds': 300, }

harness_params['memory'] = { 'agentCoreMemoryConfiguration': {'arn': memory_arn} }

response = client.create_harness(**harness_params)

以上即为完整的 agent 定义——无编排循环、无工具执行逻辑、无流式处理代码、无错误重试代码,全部由 AgentCore harness 托管。

通过 Gateway 声明工具

通常让 agent 调用工具需要编写代码接收模型返回的工具调用、解析参数、调用目标函数、处理错误并把结果回传。使用 harness 后,这一步被省略:只需在 AgentCore Gateway 上声明工具 schema 并指向 Lambda 函数,harness 会在推理过程中自动发现工具、向模型呈现、按选择调用并把结果回填到对话中。

以 search-and-replace 工具为例,CDK 中通过以下方式声明:

this.gateway.addLambdaTarget('SearchReplaceTarget', { gatewayTargetName: 'search-replace-target', lambdaFunction: this.searchReplaceLambda, toolSchema: agentcore.ToolSchema.fromInline([{ name: 'search_and_replace', description: 'Find an object in the image by description and replace it. ' + 'Does NOT require a mask. Use when the user wants to replace a specific object.', inputSchema: { type: agentcore.SchemaDefinitionType.OBJECT, properties: { source_image_key: { type: agentcore.SchemaDefinitionType.STRING }, search_prompt: { type: agentcore.SchemaDefinitionType.STRING }, prompt: { type: agentcore.SchemaDefinitionType.STRING }, }, required: ['source_image_key', 'search_prompt', 'prompt'], }, }]), });

agent 读取这些工具描述后即可根据用户 prompt 自动选型,无需开发者编写任何路由逻辑。整个方案借助 AWS CDK 一键部署,把身份认证、加密存储、Amplify 前端与 AgentCore harness 装配成完整可用的图像编辑服务,适合希望快速验证「自然语言→图像编辑」产品原型的团队参考。

信源