SuperAPI AI Directory

byted-las-image-resample

Design & creation

View repository

Updated 10-16 08:05

About this skill

LAS image resampling (las_image_resample)

downsample and scale the image (shrink only, upscaling not supported), supports changing DPI and converting between JPG/PNG.

Design pattern

This skill mainly uses:

  • Tool Wrapper: wraps the lasutil CLI call
  • Pipeline: contains a sequential workflow from Step 0 → Step N

Core API and configuration

  • Operator ID: las_image_resample
  • API: sync (process)
  • Environment variables: LAS_API_KEY (required)

For detailed parameters and interface definitions, see references/api.md。

Gotchas

  • Downsampling only:target_size must not exceed the original image size; this operator does not support upscaling.
  • Input restrictions: only supports JPEG/PNG/TIFF, ≤100MB, total pixel count ≤225,000,000.
  • Key security: if the chat box blocks keys, have the user create env.sh in the current directory and write export LAS_API_KEY="..."; the SDK will read it automatically.
  • Disclaimer: the final reply must include: "本方式的计费均为预估计费,与实际费用有差距,实际费用以运行后火山产生的账单为准。计费说明请参考 Volcengine LAS pricing.", and it is prohibited to use the words "actual cost" to describe the estimated price.

Workflow (execute strictly in order)

Copy this checklist and track progress:

执行进度:
- [ ] Step 0: 前置检查
- [ ] Step 1: 初始化与准备
- [ ] Step 2: 预估价格
- [ ] Step 3: 执行/提交任务
- [ ] Step 4: 结果呈现

Step 0: Pre-check (⚠️ must be completed in the first round of dialogue)

After accepting the user's task,do not start executing immediately; the following environment checks must be performed first:

  1. Check LAS_API_KEY and LAS_REGION: confirm whether they are configured in the environment variables or .env .
    • If not, immediately ask the user for them (hint:LAS_REGION is commonly cn-beijing)。
    • Note:LAS_REGION must be exactly consistent with the region where your API Key and TOS Bucket are located. If the user switches Region midway, you must remind the user that their TOS Bucket must also be changed accordingly; otherwise it will cause permission exceptions or upload failures.
  2. Check the input path:
    • If what the user asks to process is alocal file, it must first be uploaded to TOS via the File API (only LAS_API_KEYis needed, no additional TOS credentials are required).
    • If the operator'soutput resultis stored on TOS and the user needs to download it back locally, then VOLCENGINE_ACCESS_KEY and VOLCENGINE_SECRET_KEYare required. Forscenarios where only the input file needs to be uploaded, TOS credentialsare no longer required。
  3. After confirmation: only then can you proceed to the next step.

Step 1: Initialization and preparation

Environment initialization (required for the Agent):

# 执行统一的环境初始化与更新脚本(会自动创建/激活虚拟环境,并检查更新)
source "$(dirname "$0")/scripts/env_init.sh" las_image_resample
workdir=$LAS_WORKDIR

If a network issue causes the update to fail, the script will skip the check and continue executing with the locally installed SDK.

  • When processing local files: first check the format and size locally, estimate the price, and upload only after the user confirms:
    # 提前检查图片格式(避免参数错误)
    ./scripts/check_format.sh <local_path>
    # 本地使用 identify 获取尺寸(无需上传即可预估价格)
    identify -format "%wx%h" <local_path>
    
    Calculate the estimated price and wait for user confirmation, then execute the upload:
    # 用户确认后,上传到 TOS
    lasutil file-upload <local_path>
    
    After a successful upload, JSON is returned; take the presigned_url(HTTPS presigned download link, valid for 24 hours) passed to the operator as the input URL.

Step 2: Estimate price (⚠️ user confirmation required)

  1. Read references/prices.md to get the latest billing standard.
  2. Prefer obtaining dimensions locally(to avoid unnecessary uploads):
    # 使用 ImageMagick identify 本地获取
    identify -format "%wx%h" <local_path>
    
    If identify fails, then use lasutil to obtain remotely:
    lasutil image-info <input_image_url>
    
  3. Calculate the total price based on the resolution tier and unit price,inform the user of the billing unit price together with the estimated total price and forcibly pause execution, and explicitly wait for the user's reply confirmation. Before the user explicitly replies with an approval instruction such as "continue" or "confirm",absolutely prohibitedfrom proceeding to the next step (execute/submit task). Note: the estimate is for reference only; the actual amount is subject to the Volcengine bill. For billing details, refer to Volcengine LAS pricing。

Step 3: Execute resampling (Process)

Construct the basic data.json:

{
  "image_src_type": "image_url",
  "image": "<presigned_url>",
  "tos_dir": "tos://bucket/output/",
  "target_size": [1024, 1024],
  "method": "lanczos"
}

Note: After a local file is uploaded via lasutil file-upload , use presigned_url as the image field value, andimage_src_type set to "image_url". If a TOS path is used directly, set "image_src_type": "image_tos"。

Execute the command:

data=$(cat "$workdir/data.json")
lasutil process las_image_resample "$data" > "$workdir/result.json"

Result presentation

Use the script to automatically generate the result presentation (automatically includes the billing statement):

./scripts/generate_result.md.sh $workdir/result.json <estimated_price>

The generated content includes:

  • Task information card
  • Input/output dimension statistics
  • Automatically includes the billing statement ✅

Manual extraction method:

jq -r '"输出路径:" + .data.image_path' $workdir/result.json

Review criteria

After execution is complete, the Agent should self-check:

  1. Whether environment variables are correctly configured
  2. Whether the input file was successfully uploaded
  3. Whether the output results are correctly presented to the user
  4. Whether the billing statement is included