{"slug": "build-a-serverless-image-editing-agent-with-amazon-bedrock-agentcore-harness", "title": "Build a serverless image editing agent with Amazon Bedrock AgentCore harness", "summary": "Amazon Web Services (AWS) announced a serverless image editing agent built on the Amazon Bedrock AgentCore harness, enabling users to edit photos via natural language prompts. The agent uses configuration-driven orchestration, per-invocation model switching, and three Stability AI tools to execute edits like color changes or image extensions, with a React frontend and AWS Amplify hosting. The solution demonstrates AgentCore's capabilities for stateful, isolated microVM execution without custom orchestration code.", "body_md": "[Artificial Intelligence](https://aws.amazon.com/blogs/machine-learning/)\n\n# Build a serverless image editing agent with Amazon Bedrock AgentCore harness\n\nBuilding an AI agent that edits images based on natural language requires an orchestration loop, tool routing, memory management, and a compute environment to run it all. [Amazon Bedrock AgentCore harness](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/harness.html) handles that entire stack with configuration. You declare what the agent does, and the harness runs it in a stateful, isolated microVM with built-in memory, tool routing, and observability.\n\nThis post walks through building a serverless image editor where users upload a photo, describe an edit in plain English, and receive the result in seconds. The agent runs on AgentCore harness without custom orchestration code. We deploy the full solution, including authentication, encrypted storage, three image editing tools, and a React frontend, with a single deployment command. The infrastructure is defined using [AWS Cloud Development Kit (AWS CDK)](https://aws.amazon.com/cdk/).\n\n## Image editing application\n\nThe application accepts prompts like “change the car color to blue” or “extend the image 200 pixels to the right.” An agent powered by [Claude Sonnet 4.6](https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-anthropic-claude-sonnet-4-6.html) breaks the requirement into a series of steps and orchestrates the tool calling, each associated with a different [Stability AI](https://docs.aws.amazon.com/bedrock/latest/userguide/model-cards-stability-ai.html) model. Then it executes the edit, applies a watermark using a shell command on the microVM (no token cost), and returns the result.\n\nThis application demonstrates the following AgentCore harness capabilities:\n\n**Configuration-driven agent creation.** The agent is defined entirely through API parameters. No Python orchestration code, no framework, no container.**Per-invocation model switching.** The frontend routes basic chat to[Claude Haiku 4.5](https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-anthropic-claude-haiku-4-5.html)and edits to Claude Sonnet 4.6. The agent preserves conversation context across model switches.**Per-invocation persona override.** Users select industry personas (Real Estate, Retail, Automotive) that inject domain-specific system prompts without redeploying.- AgentCore memory stores conversation history in the AgentCore service for 30 days. The agent retains full context across turns within a session, so it can reference prior edits without the frontend re-sending history. This sample persists the session ID in\n`localStorage`\n\n, so conversations survive browser refresh. Clearing browser data starts a new session on the frontend, but the conversation history remains available in AgentCore through the`ListEvents`\n\nAPI. Three AWS Lambda-backed tools are exposed through Model Context Protocol (MCP) with semantic routing. The agent selects the right tool based on the prompt.[AgentCore Gateway](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway.html)with MCP.**InvokeAgentRuntimeCommand.** After each edit, a Python script runs directly on the AgentCore runtime microVM to add a watermark. No model reasoning, no tokens consumed.\n\n## Solution overview\n\nThe architecture of the image editing application has four layers.\n\n- A React frontend hosted on\n[AWS Amplify](https://aws.amazon.com/amplify/)where users upload images, draw masks, and enter editing instructions. - An\n[AWS Lambda](https://aws.amazon.com/lambda/)proxy that acts as a security boundary between browser credentials and the harness API, and controls which system prompts are allowed. - An\n[Amazon Bedrock AgentCore](https://aws.amazon.com/bedrock/agentcore/)harness agent with[AgentCore Memory](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/harness-memory.html)for conversation persistence. - Three tool Lambda functions calling Stability AI foundation models through\n[Amazon Bedrock](https://aws.amazon.com/bedrock/)for image generation.\n\n## Creating the agent using configuration\n\nWith an AgentCore harness, the agent definition is a set of parameters passed to the `create_harness`\n\nAPI. Here is the core of our provisioning code that creates the agent during `cdk deploy`\n\n.\n\nThat is the entire agent. No orchestration loop, no tool execution logic, no streaming handler, no error retry code. The AgentCore harness handles all of it.\n\n## Declaring tools through AgentCore Gateway\n\nGiving an agent access to tools normally requires writing code that receives tool calls from the model, parses arguments, invokes the target function, handles errors, and passes results back. With the harness, you skip all of that. You declare the tool schema on an [AgentCore Gateway](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway.html) and point it at a Lambda function. The harness discovers the tools, presents them to the model during reasoning, invokes the selected tool through the Gateway, and feeds the result back into the conversation automatically.\n\nHere is how we declared the search-and-replace tool in the CDK stack.\n\nThe agent reads these tool descriptions and selects the right one based on the user prompt. No routing logic is required. The harness handles tool selection through the model’s reasoning.\n\n## Per-invocation model and persona switching\n\nThe harness accepts a model parameter on every invocation. Passing a different model ID changes which foundation model handles that turn. The harness automatically loads the full conversation history from AgentCore Memory and formats it for the new model, so context carries over without additional code. You do not need to write model-switching logic, history retrieval, or input formatting. The harness manages all of that internally based on a single parameter change.\n\nThe Lambda proxy uses this to route basic chat to Haiku and image edits to Sonnet.\n\nThe frontend determines which model to use based on whether the prompt contains editing keywords. Short messages like “hi” or “what can you do” go to Haiku for lower latency. Edits go to Sonnet for higher quality tool selection. The user can also manually select a model from a menu.\n\nAgentCore Memory preserves the full conversation history regardless of configured model changes in the harness. When Haiku receives “how about blue?” after Sonnet handled “change the car to black,” it knows “blue” refers to the car because Memory feeds the complete history to whatever model is active.\n\n## Post-processing with shell commands (no token cost)\n\nAfter the agent generates an image, we run a Python script directly on the harness microVM to add a watermark. This uses InvokeAgentRuntimeCommand, which gives you shell access to the agent’s environment without going through the model.\n\nThis pattern is useful for deterministic post-processing. Resize images before sending to a model (save input tokens), run validation on agent output, extract structured data, or apply business logic. The microVM has Python and bash available by default, and you can install additional packages at runtime.\n\nBecause the harness is configuration-only, there is no agent script where you can add custom logic. InvokeAgentRuntimeCommand is the way to run your own code on the same microVM where the agent runs, but outside the agent loop. The Lambda proxy calls it after the agent finishes its turn. The command executes, does the work, and returns. The agent does not know it had happened.\n\n## Prerequisites\n\nTo deploy this solution, you need the following.\n\n- An\n[AWS account](https://signin.aws.amazon.com/signin?redirect_uri=https%3A%2F%2Fportal.aws.amazon.com%2Fbilling%2Fsignup%2Fresume&client_id=signup)with permissions to create AWS Identity and Access Management (IAM) roles, Lambda functions, Amazon Simple Storage Service (Amazon S3) buckets, Amazon Cognito pools, and AgentCore resources. [Node.js](https://nodejs.org/)20.x or later.[Python](https://www.python.org/downloads/)3.13 or later (for Lambda function runtimes).[AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)2.x configured with credentials.- Access to Anthropic Claude models (Sonnet, Haiku) in Amazon Bedrock.\n- Access to Stability AI models in Amazon Bedrock.\n\nEstimated deployment time is 3 to 5 minutes.\n\n## Deploy the solution\n\nThe deploy script handles everything end-to-end. It installs prerequisites, bundles Lambda dependencies, deploys the CDK stack, builds the frontend, uploads it to Amplify, and creates a test user.\n\nClone the [GitHub repository](https://github.com/aws-samples/sample-serverless-image-editing-agent-bedrock-agentcore-harness) and navigate into the project directory.\n\nRun the deployment script.\n\nAt the end, it prints the live URL and login credentials.\n\nThe CDK stack creates all resources in a single [AWS CloudFormation](https://aws.amazon.com/cloudformation/) stack. The solution uses Amazon Cognito with both a user pool and identity pool to handle authentication. Images are stored in an Amazon S3 bucket protected by AWS Key Management Service (AWS KMS) encryption. The image editing capabilities are powered by three Lambda functions, which are exposed as MCP tools through an AgentCore Gateway. These tools are orchestrated by an AgentCore harness agent equipped with memory, accessed via a Lambda proxy. On the frontend, an AWS Amplify application serves the React-based user interface.\n\n## Walkthrough\n\nAfter signing in, the editor presents a canvas on the left and a chat interface on the right.\n\n**1. Upload an image.** The image uploads to S3 under the user’s identity-scoped prefix.\n\n**2. Describe your edit.** Enter a natural-language instruction in the chat input. For object replacement (“change the sky to a sunset”), the agent uses search-and-replace automatically.\n\n**3. Draw a mask for Region-specific edits.** To edit a specific area of the image, draw a mask on the canvas to define the region, then enter what to generate in the masked area.\n\n**4. View the result.** The edited image appears in the chat thread with a tiled watermark applied by the microVM shell command. The “Behind the Scenes” panel shows which model was used, which tool was called, token counts, latency, and whether the watermark was applied.\n\n**5. Optionally switch models or personas.** Use the menus at the top of the chat to change the reasoning model or switch to an industry-specific persona. The change takes effect on the next message without losing conversation history.\n\n## What the harness specifically reduced for this project\n\nThe solution does not require lines of agent orchestration code. No model call loop, no tool execution handler, no streaming parser, no error retry logic, no container image.\n\nWhat we did write.\n\n- A Lambda proxy (80 lines) that acts as a security boundary and controls which system prompts reach the harness.\n- Three tool Lambda functions (one per Stability AI model) that do the actual image processing.\n- A provisioning script that calls the\n`create_harness`\n\nAPI during deployment (AgentCore harness is in preview and does not yet have a native CDK construct).\n\nThe agent itself is configuration. Changing its behavior (different model, new tool, updated instructions) is an API call, not a code deployment.\n\n## When to use AgentCore Runtime instead\n\nAgentCore harness works well for agents with straightforward tool-calling patterns. The agent receives a prompt, picks a tool, calls it, and returns the result. If your agent needs custom orchestration logic, such as pre-processing inputs between turns, running a LangGraph state machine, or executing arbitrary Python before and after each model call, [AgentCore Runtime](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime.html) gives you full control.\n\nBoth the harness and AgentCore Runtime run on the same underlying infrastructure (microVMs, Memory, Gateway, Observability). You can start with the harness and move to AgentCore Runtime as complexity grows.\n\n## Clean up\n\nRunning the destroy script permanently deletes all resources including the S3 bucket and uploaded images. Back up any data you want to keep before proceeding.\n\n**Delete the stack:**\n\n## Conclusion\n\nAgentCore harness lets us build a production-ready image editing agent without writing orchestration code. The agent handles tool selection, model switching, persona customization, conversation persistence, and deterministic post-processing through configuration and per-invocation parameters. Each session runs in an isolated microVM where we can execute shell commands at no token cost for tasks like watermarking.\n\nFor agents with straightforward tool-calling patterns, the harness removes operational overhead and you can iterate behavior at the speed of a configuration change. The full source code and one-command deployment script are available on [GitHub](https://github.com/aws-samples/sample-serverless-image-editing-agent-bedrock-agentcore-harness).\n\nTo get started with AgentCore harness, visit the [AgentCore harness documentation](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/harness.html) or explore the [Amazon Bedrock AgentCore](https://aws.amazon.com/bedrock/agentcore/) product page for pricing and availability details.", "url": "https://wpnews.pro/news/build-a-serverless-image-editing-agent-with-amazon-bedrock-agentcore-harness", "canonical_source": "https://aws.amazon.com/blogs/machine-learning/build-a-serverless-image-editing-agent-with-amazon-bedrock-agentcore-harness/", "published_at": "2026-07-07 16:51:29+00:00", "updated_at": "2026-07-07 17:05:02.847469+00:00", "lang": "en", "topics": ["artificial-intelligence", "generative-ai", "ai-tools", "ai-infrastructure", "computer-vision"], "entities": ["Amazon Web Services", "Amazon Bedrock", "Claude Sonnet 4.6", "Stability AI", "AWS Lambda", "AWS Amplify", "AWS Cloud Development Kit", "Claude Haiku 4.5"], "alternates": {"html": "https://wpnews.pro/news/build-a-serverless-image-editing-agent-with-amazon-bedrock-agentcore-harness", "markdown": "https://wpnews.pro/news/build-a-serverless-image-editing-agent-with-amazon-bedrock-agentcore-harness.md", "text": "https://wpnews.pro/news/build-a-serverless-image-editing-agent-with-amazon-bedrock-agentcore-harness.txt", "jsonld": "https://wpnews.pro/news/build-a-serverless-image-editing-agent-with-amazon-bedrock-agentcore-harness.jsonld"}}