API Reference (HarmonyOS)
When you need to customize device behavior, integrate Midscene into a framework, or troubleshoot HDC issues, refer to this section. For common constructor parameters (reports, hooks, caching, etc.), see the platform-agnostic API Reference.
Action Space
HarmonyDevice uses the following action space. The Midscene Agent can use these operations when planning tasks:
Tap— Tap on an element.DoubleClick— Double-tap on an element.Input— Input text, supportingreplace/typeOnly/clearmodes.Scroll— Scroll from an element or screen center in any direction, supporting scroll-to-top/bottom/left/right.DragAndDrop— Drag from one element to another.KeyboardPress— Press a specific key.LongPress— Long-press a target element with optional custom duration.ClearInput— Clear input field contents.Launch— Open a HarmonyOS app (bundle name).RunHdcShell— Execute a rawhdc shellcommand.HarmonyBackButton— Trigger system back.HarmonyHomeButton— Return to home screen.HarmonyRecentAppsButton— Open recent apps / multitasking.
HarmonyDevice
Creates an HDC device instance that can be driven by HarmonyAgent.
Import
Constructor
Device Options
deviceId: string— Value fromhdc list targetsorgetConnectedDevices().hdcPath?: string— Custom path to the HDC executable. If not set, it searchesHDC_HOMEenvironment variable and common installation paths.autoDismissKeyboard?: boolean— Automatically hide keyboard after input, defaulttrue.screenshotResizeScale?: number— Scale screenshots before sending to the model. Not recommended to modify manually.customActions?: DeviceAction[]— Extend the planner's available actions viadefineAction.
Usage Notes
- Use
getConnectedDevices()to discover devices. The returneddeviceIdmatcheshdc list targetsoutput. - If HDC is not in your system PATH, specify it via the
HDC_HOMEenvironment variable or thehdcPathoption.
Examples
Quick Start
Launch Apps
HarmonyAgent
Binds Midscene's AI planning capabilities to a HarmonyDevice for UI automation.
Import
Constructor
HarmonyOS-Specific Options
customActions?: DeviceAction[]— Extend the planner's available actions viadefineAction.appNameMapping?: Record<string, string>— Map friendly app names to bundle names. When you pass an app name tolaunch(target), the Agent looks up the corresponding bundle name in this mapping; if no mapping is found, it tries to launchtargetas-is.- Other fields are the same as API constructors:
generateReport,reportFileName,aiActionContext,modelConfig,cacheId,createOpenAIClient,onTaskStartTip, etc.
Usage Notes
Info
- One device connection corresponds to one Agent.
- HarmonyOS-specific helpers like
launchandrunHdcShellcan also be used in YAML scripts. See HarmonyOS platform-specific actions. - For common interaction methods, see API Reference (Common).
HarmonyOS-Specific Methods
agent.launch()
Launch a HarmonyOS app.
uri: string— Can be an app bundle name (e.g.,com.huawei.hmos.settings), or an app name registered inappNameMapping. If a URL starting withhttp://orhttps://is passed, it opens via the browser.
agent.runHdcShell()
Run a raw hdc shell command on the connected device.
command: string— The command passed directly tohdc shell.
Navigation Helpers
agent.back(): Promise<void>— Trigger HarmonyOS system back.agent.home(): Promise<void>— Return to home screen.agent.recentApps(): Promise<void>— Open recent apps / multitasking.
Utilities
agentFromHdcDevice()
Create a HarmonyAgent from any connected HDC device.
deviceId?: string— Connect to a specific device; leave empty for "first available device".opts?: HarmonyAgentOpt & HarmonyDeviceOpt— Merge Agent options andHarmonyDevicesettings in a single object.
getConnectedDevices()
List HDC devices that Midscene can drive.
Related Reading
- HarmonyOS Getting Started for setup and script examples.

