Preface

DeepSeek Harness (DSH) agents are good at handling text, but processing images in a conversation often requires dragging files out, using external tools, and dragging the results back. The h-table/dsh-bg-tool plugin brings this workflow into the conversation itself. Based on local rembg and BiRefNet, it provides a remove_background tool that the Agent can call directly. The processed transparent-background PNG is written to the workspace, the whole process stays inside Harness, the image never leaves the local machine, and no API Key is required.

Core Features

  • In-conversation background removal: Put an image into the session workspace, the Agent calls remove_background, and the transparent-background PNG is written directly to the output directory.
  • Three-tier model switching as needed: Provides general (arbitrary objects/products), portrait (people/hair/ID photos), and fast (quick draft) modes.
  • Fully local GPU inference: BiRefNet runs in fp16 and is tuned for CUDA; no network requests are required.
  • Self-managed server lifecycle: DSH automatically starts the local rembg service on startup and automatically tears it down when the plugin stops.
  • Official-style plugin configuration card: Settings → Plugins → Plugin Configuration → “Background Removal”, supporting model mapping, output directory, and auto-start switch.

Environment Preparation

The plugin depends on a local environment and requires a .bg-tools/ directory (Python venv + model files + bg_server.py).

  • System requirements: Windows + NVIDIA GPU + CUDA 13.
  • Directory structure:
    .bg-tools/
    ├── venv/           # Python 虚拟环境(含 rembg、onnxruntime-gpu)
    ├── models/         # 模型文件(BiRefNet fp16、u2netp 等)
    ├── bg_server.py    # 本地 rembg HTTP 服务
    ├── start-server.ps1 # 手动启动脚本(可选)
    └── output/         # 默认输出目录
  • Path resolution order: $DSH_BG_TOOL_ROOT > $DSH_HOME/.bg-tools > legacy workspace path.

Installation and Activation

Add the dependency and bundle reference to the local profile’s package.json:

// ~/.dsh/profiles/web/package.json
"dependencies": { "@local/dsh-bg-tool": "link:<本仓库目录>" },
"dsh": { "profile": { "bundles": ["@local/dsh-bg-tool"] } }

After installing, create a symbolic link from node_modules/@local/dsh-bg-tool to this repository directory, and restart the Web Profile to take effect.

Usage

The plugin registers the remove_background tool for each session. When calling it, provide image_path (absolute path, using forward slashes) and mode (general / portrait / fast); output_name is optional.

Example:

把 workspace 里的 DSH娘.png 去掉背景,用 portrait 模式。
把这个商品图抠出来,输出到 output 目录,命名 product_1.png。

The Agent will return output_path. Open that path to view the transparent-background PNG.

Configuration Details

In Settings → Plugins → Plugin Configuration → “Background Removal” card, you can configure the following:
* generalModel: General model (default birefnet-general).
* portraitModel: Portrait model (default birefnet-portrait).
* fastModel: Fast model (default u2netp).
* outputDir: Output directory (default .bg-tools/output).
* autoStartServer: Automatically start the GPU service (default true).

Notes

  • First load: The first call to a model takes about 7 seconds (loading into VRAM); subsequent hot calls take about 1 second per image.
  • Path restrictions: image_path must be an absolute path readable by the Agent; \ and / in output file names are replaced with _.
  • Troubleshooting: If it returns “rembg service cannot be started”, check whether the venv/models in .bg-tools are complete, or manually run start-server.ps1 to view the logs.