---
name: "addPanelAgentCustomRole"
mode: "api"
versionRequirements:
  - { name: "@tuya-miniapp/cloud-api", version: "1.0.6" }
---

## addPanelAgentCustomRole

> [VERSION] @tuya-miniapp/cloud-api >= 1.0.6

> 💡 This API depends on cloud capabilities. In the Miniapp Developer Platform (https://platform.tuya.com/miniapp/), go to Development Settings > Cloud Capabilities to configure authorization.

### Description

Create a custom role.

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `params` | `AddPanelAgentCustomRoleParams` | Yes | Request body |

### Return Value

Type: `Promise<string>`

AddPanelAgentCustomRoleResult (see type definitions and minituya return parameters for field meanings)

### Referenced Types

##### `interface` AddPanelAgentCustomRoleParams

| Property | Type | Description |
| --- | --- | --- |
| `devId` | `string` | Device ID |
| `roleName` | `string` | Role name |
| `roleDesc` | `string` | Role description |
| `roleIntroduce` | `string` | Role description |
| `roleVariables` | `Record<string, any>` | Role variables |
| `roleImgUrl` | `string` | Role image |
| `useLangCode` | `string` | Role language |
| `useTimbreId` | `string` | Role voice (timbre) |
| `useLlmId` | `string` | Role language model |
| `speed` | `string` | Role voice speed |
| `tone` | `string` | Role tone |


### Examples

#### Request example

```typescript
import { addPanelAgentCustomRole } from '@tuya-miniapp/cloud-api';

const params = {
  devId: 'your_device_id',
  roleName: 'Smart Assistant Xiaomei',
  roleDesc: 'A gentle and caring smart assistant',
  roleIntroduce: "I'm Xiaomei, your dedicated smart assistant. Glad to serve you!",
  roleVariables: {
    personality: 'friendly',
    expertise: 'general',
  },
  roleImgUrl: 'https://example.com/avatar.jpg',
  useLangCode: 'zh-CN',
  useTimbreId: 'timbre_001',
  useLlmId: '1001',
  speed: '1.0',
  tone: 'gentle',
};

addPanelAgentCustomRole(params)
  .then(result => {
    console.log('Created successfully, role ID:', result);
  })
  .catch(error => {
    console.error('Failed to create custom role:', error);
  });
```

#### Response example

```json
"role_custom_12345"
```
