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

## createPanelAgentRoleFromTemplate

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

> 💡 This API depends on cloud capabilities. Configure authorization under Development Settings -> Cloud Capabilities on the Mini App Developer Platform (https://platform.tuya.com/miniapp/).

### Description

Create a custom role from a role template.

### Parameters

`Params`

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

### Return Value

Type: `Promise<string>`

CreatePanelAgentRoleFromTemplateResult (see type definitions and minituya response parameters for field meanings)

### Referenced Types

##### `interface` CreatePanelAgentRoleFromTemplateParams

| Property | Type | Description |
| --- | --- | --- |
| `devId` | `string` | Device ID |
| `roleId` | `string` | Role template or role ID (depending on the scenario) |
| `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 |
| `memoryInfo` | `string` | Memory |
| `speed` | `string` | Voice speed |
| `tone` | `string` | Voice tone |
| `needBind` | `string` | Whether binding is required |


### Examples

#### Request example

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

const params = {
  devId: 'your_device_id',
  roleId: 'template_role_001',
  roleName: 'Template-based smart assistant',
  roleDesc: 'A customized assistant created from a template',
  roleIntroduce: "I'm a smart assistant created from a template",
  roleVariables: {
    customization: 'template_based',
    features: ['smart', 'helpful'],
  },
  roleImgUrl: 'https://example.com/template_avatar.jpg',
  useLangCode: 'zh-CN',
  useTimbreId: 'timbre_001',
  useLlmId: '1001',
  memoryInfo: 'Memory information inherited from the template',
  speed: '1.0',
  tone: '0.8',
  needBind: 'true',
};

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

#### Response example

```json
"role_custom_from_template_12345"
```
