Skip to content

Meter Reading AI Agent Setup Guide

This guide covers deployment and configuration of Meter Reading AI Agent.

Quick Start

Prerequisites

  • AWS Account
  • AWS CLI installed and configured
  • CloudFormation execution permissions
  • Access permissions to Bedrock AgentCore Runtime
  • Access permissions to S3 Tables

Launch Stack

Deploy CloudFormation Stack (CLI)

bash
aws cloudformation create-stack \
  --stack-name meter-reading-agent-stack \
  --template-url https://cm-seller-resources.s3.us-east-1.amazonaws.com/meter-reading-ai-agent/cfn/reader-agent.yaml \
  --capabilities CAPABILITY_NAMED_IAM \
  --region us-east-1

Verify Deployment Completion

bash
aws cloudformation describe-stacks \
  --stack-name meter-reading-agent-stack \
  --region us-east-1 \
  --query 'Stacks[0].StackStatus'

Retrieve Output Values

After deployment is complete, retrieve the following output values:

bash
aws cloudformation describe-stacks \
  --stack-name meter-reading-agent-stack \
  --region us-east-1 \
  --query 'Stacks[0].Outputs'

Important output values:

  • RuntimeArn: AgentCore Runtime ARN
  • EndpointArn: AgentCore Runtime Endpoint ARN
  • ImageBucketName: S3 bucket name for image uploads
  • KnowledgeBaseId: Knowledge Base ID
  • KnowledgeBaseSourceBucketName: Knowledge Base source bucket name
  • MeterReadingsTableArn: S3 Tables table ARN

Deploy Sample Dashboard Implementation

Launch Stack

Deploy Dashboard Stack (CLI)

bash
aws cloudformation create-stack \
  --stack-name meter-dashboard-stack \
  --template-url https://cm-seller-resources.s3.us-east-1.amazonaws.com/meter-reading-ai-agent/cfn/dashboard-stack.yaml \
  --parameters \
    ParameterKey=ImageUri,ParameterValue=<ECR_IMAGE_URI> \
    ParameterKey=S3TablesArn,ParameterValue=<S3_TABLES_ARN> \
    ParameterKey=S3TablesNamespaceName,ParameterValue=meter_data \
    ParameterKey=S3TablesTableName,ParameterValue=meter_readings \
  --capabilities CAPABILITY_NAMED_IAM \
  --region us-east-1

Retrieve CloudFront URL

After deployment is complete, retrieve the CloudFront URL:

bash
aws cloudformation describe-stacks \
  --stack-name meter-dashboard-stack \
  --region us-east-1 \
  --query 'Stacks[0].Outputs[?OutputKey==`CloudFrontDistributionURL`].OutputValue' \
  --output text

Configuration

Register Meter Reading Instructions

Register instruction files to the Knowledge Base source bucket.

  1. Prepare Instruction File

    Create instructions in Markdown format. Example:

    markdown
    # Meter Reading Instructions
    
    ## Reading Procedure
    ...

    Download a sample from here.

  2. Upload to S3 Bucket

bash
# Get Knowledge Base source bucket name
KB_BUCKET=$(aws cloudformation describe-stacks \
  --stack-name meter-reading-agent-stack \
  --region us-east-1 \
  --query 'Stacks[0].Outputs[?OutputKey==`KnowledgeBaseSourceBucketName`].OutputValue' \
  --output text)

# Upload instruction file
aws s3 cp reading-instructions.md \
  s3://${KB_BUCKET}/instructions/reading-instructions.md \
  --region us-east-1

Register Meter Specification File

Create meter specification files in JSON format and register them to the Knowledge Base source bucket.

  1. Prepare Meter Specification File

    Create in meter-specs/meter-types.json format:

    json
    {
      "meter_types": [
        {
          "id": "pressure-gauge-001",
          "name": "Pressure Gauge (Analog Single Needle)",
          "type": "pressure",
          "description": "Single needle pressure gauge with 0-10MPa range",
          "unit": "MPa",
          "min_value": 0,
          "max_value": 10,
          "graduation": 0.5,
          "reading_method": "Read the position indicated by the single needle",
          "validation_rules": {
            "min": 0,
            "max": 10,
            "decimal_places": 2
          },
          "qr_code_prefix": "PRESS"
        }
      ],
      "common_instructions": {
        "image_quality": "Take photos with sufficient lighting",
        "reading_angle": "Photograph the meter from the front",
        "qr_code": "Photograph the QR code together with the meter"
      }
    }
  2. Upload to S3 Bucket

bash
# Get Knowledge Base source bucket name
KB_BUCKET=$(aws cloudformation describe-stacks \
  --stack-name meter-reading-agent-stack \
  --region us-east-1 \
  --query 'Stacks[0].Outputs[?OutputKey==`KnowledgeBaseSourceBucketName`].OutputValue' \
  --output text)

# Upload meter specification file
aws s3 cp meter-types.json \
  s3://${KB_BUCKET}/meter-specs/meter-types.json \
  --region us-east-1

Synchronize Knowledge Base

Knowledge Base synchronization can be performed from the Bedrock console or CLI.

Synchronize via CLI:

bash
# Get Knowledge Base ID and DataSource ID
KB_ID=$(aws cloudformation describe-stacks \
  --stack-name meter-reading-agent-stack \
  --region us-east-1 \
  --query 'Stacks[0].Outputs[?OutputKey==`KnowledgeBaseId`].OutputValue' \
  --output text)

DS_ID=$(aws cloudformation describe-stacks \
  --stack-name meter-reading-agent-stack \
  --region us-east-1 \
  --query 'Stacks[0].Outputs[?OutputKey==`KnowledgeBaseDataSourceId`].OutputValue' \
  --output text)

# Start synchronization job
aws bedrock start-ingestion-job \
  --knowledge-base-id ${KB_ID} \
  --data-source-id ${DS_ID} \
  --region us-east-1

# Check synchronization job status
aws bedrock get-ingestion-job \
  --knowledge-base-id ${KB_ID} \
  --data-source-id ${DS_ID} \
  --ingestion-job-id <JOB_ID> \
  --region us-east-1

Synchronize via Console:

  1. Access the AWS Bedrock console
  2. Select "Knowledge bases"
  3. Select the target Knowledge Base
  4. Open the "Data sources" tab
  5. Select the target data source and click "Sync"

Specifications

AI Agent Interface Specifications

Entry Point

Call the AgentCore Runtime endpoint in the following format:

Request Format:

json
{
  "s3_bucket": "camera-image-123456789012-us-east-1",
  "s3_key": "images/2025/01/15/image.jpg",
  "session_id": "uuid-string",
  "meter_info": {
    "meter_id": "001",
    "meter_type": "pressure",
    "unit": "MPa"
  }
}

Response Format:

json
{
  "meter_id": "001",
  "meter_type": "pressure",
  "reading_value": 5.5,
  "status": "processed",
  "reading_unit": "MPa",
  "confidence_score": 0.95,
  "image_s3_key": "images/2025/01/15/image.jpg",
  "qr_code_data": "PRESS-001-A1F",
  "processing_duration_ms": 12000,
  "image_quality": 0.88,
  "validation_passed": true,
  "error_message": null,
  "notes": null
}

Field Descriptions

Field NameTypeRequiredDescription
meter_idstringRequiredUnique identifier for the meter
meter_typestringRequiredMeter type (pressure, temperature, flow, power, water)
reading_valuenumberRequiredReading value (numeric)
statusstringRequiredProcessing status (processed, error, warning)
reading_unitstringOptionalUnit (MPa, °C, L/min, kWh, m³)
confidence_scorenumberOptionalConfidence score (0.0-1.0)
image_s3_keystringOptionalS3 key for the image file
qr_code_datastringOptionalData read from QR code
processing_duration_msintegerOptionalProcessing time (milliseconds)
image_qualitynumberOptionalImage quality score (0.0-1.0)
validation_passedbooleanOptionalValidation result
error_messagestringOptionalError message (on error)
notesstringOptionalNotes

Error Response

When an error occurs, the response is returned in the following format:

json
{
  "error": "Error message",
  "status": "error",
  "meter_id": "001",
  "meter_type": "pressure"
}

Meter Specification File Format

Meter specification files are in JSON format with the following structure:

Schema Definition

json
{
  "meter_types": [
    {
      "id": "string (required)",
      "name": "string (required)",
      "type": "string (required)",
      "description": "string (required)",
      "unit": "string (required)",
      "min_value": "number (required)",
      "max_value": "number (required)",
      "graduation": "number (required)",
      "reading_method": "string (required)",
      "validation_rules": {
        "min": "number (required)",
        "max": "number (required)",
        "decimal_places": "integer (required)"
      },
      "qr_code_prefix": "string (required)"
    }
  ],
  "common_instructions": {
    "image_quality": "string (required)",
    "reading_angle": "string (required)",
    "qr_code": "string (required)",
    "error_handling": "string (required)",
    "confidence": "string (required)"
  }
}

Meter Specification File Field Descriptions

Each element in the meter_types array:

Field NameTypeDescription
idstringUnique ID for the meter type
namestringDisplay name for the meter type
typestringMeter category (pressure, temperature, flow, power, water)
descriptionstringMeter description
unitstringMeasurement unit
min_valuenumberMinimum measurement value
max_valuenumberMaximum measurement value
graduationnumberScale interval
reading_methodstringDescription of reading method
validation_rulesobjectValidation rules
qr_code_prefixstringQR code prefix (PRESS, TEMP, FLOW, POWER, WATER)

Sample File

json
{
  "meter_types": [
    {
      "id": "pressure-gauge-001",
      "name": "Pressure Gauge (Analog Single Needle)",
      "type": "pressure",
      "description": "Single needle pressure gauge with 0-10MPa range. Scale graduation is 0.5MPa.",
      "unit": "MPa",
      "min_value": 0,
      "max_value": 10,
      "graduation": 0.5,
      "reading_method": "Read the position indicated by the single needle. Interpolate when reading between scale marks.",
      "validation_rules": {
        "min": 0,
        "max": 10,
        "decimal_places": 2
      },
      "qr_code_prefix": "PRESS"
    }
  ]
}

File Location

Place meter specification files under the meter-specs/ prefix in the Knowledge Base source bucket:

text
s3://<knowledge-base-source-bucket>/
  └── meter-specs/
      └── meter-types.json

S3 Tables Schema

Meter reading data is saved to S3 Tables with the following schema:

Column NameTypeRequiredDescription
timestamptimestampRequiredReading datetime (UTC)
meter_idstringRequiredMeter ID
meter_typestringRequiredMeter type
reading_valuedoubleRequiredReading value
reading_unitstringOptionalUnit
confidence_scoredoubleOptionalConfidence score
image_s3_keystringOptionalS3 key for image file
qr_code_datastringOptionalQR code data
processing_duration_msintOptionalProcessing time (milliseconds)
image_qualitydoubleOptionalImage quality score
validation_passedbooleanOptionalValidation result
error_messagestringOptionalError message
notesstringOptionalNotes
statusstringRequiredStatus
record_idstringRequiredRecord ID (UUID)

Troubleshooting

Dashboard Stack Deployment Error

Error: "The maximum number of rules per security group has been reached."

Cause: Security group rule limit has been reached

Solution:

  1. Access the AWS Service Quotas console
  2. Check the "Inbound or outbound rules per security group" quota
  3. Submit a limit increase request if necessary

Error: CloudFormation stack enters CREATE_FAILED state

Cause: Insufficient IAM permissions, resource limits, template errors, etc.

Solution:

  1. Check stack events in the CloudFormation console
  2. Review error messages to identify the cause
  3. Add IAM permissions or check resource limits as needed

Knowledge Base Cannot Be Referenced

Cause: Knowledge Base ID configuration error, synchronization not complete

Solution:

  1. Verify the KNOWLEDGE_BASE_ID environment variable is correctly set
  2. Verify the Knowledge Base synchronization job is complete
  3. Check data source configuration

Other

QR Code Cannot Be Read

Cause: Insufficient image quality, invalid QR code format

Solution:

  1. Verify the image is clearly captured
  2. Verify the QR code format is {PREFIX}-{METER_ID}-{LOCATION}
  3. Verify the QR code is captured together with the meter

Low Reading Accuracy

Cause: Insufficient image quality, meter specification configuration error

Solution:

  1. Check image quality score (0.7 or higher recommended)
  2. Verify meter specification file is correctly registered
  3. Verify Knowledge Base synchronization is complete
  4. Retake with a clearer image