# Overview

The **AI Agent SDK** allows developers to quickly integrate AI conversation functionality into their own mini-programs, enabling developers to focus on implementing their business logic without wasting time on technical details.

Use the SmartLife App (version 6.0.0 and above) to scan the QR code below to experience the AI conversation functionality:

![ray-ai-agent-chat](https://images.tuyacn.com/smart/ui_design_pkg_icon/non-session-user/1739961553cb14faec90a.png)

## Quick Start

### Version Notice

**⚠️ Important Notice**: `@ray-js/t-agent-plugin-assistant` has been deprecated, please use `@ray-js/t-agent-plugin-aistream` instead.

### Install Dependencies

Add the following dependencies to your project's `package.json`:

```json
{
  "dependencies": {
    "@ray-js/t-agent": "^0.2.0",
    "@ray-js/t-agent-plugin-aistream": "^0.2.0",
    "@ray-js/t-agent-ui-ray": "^0.2.0"
  }
}
```

> Ensure that `@ray-js/t-agent`, `@ray-js/t-agent-plugin-aistream`, and `@ray-js/t-agent-ui-ray` versions are consistent.

Run `yarn install` to install the dependencies.

### Mini-Program Kit Requirements

```json
{
  "dependencies": {
    "BaseKit": "3.12.0",
    "BizKit": "4.10.0",
    "DeviceKit": "4.6.1",
    "HomeKit": "3.4.0",
    "MiniKit": "3.12.1",
    "AIStreamKit": "1.0.0"
  },
  "baseversion": "2.21.10"
}
```

### Basic Example

Here is a minimal code example for integrating an AI conversation interface in a mini-program:

```tsx
import React from 'react';
import { View } from '@ray-js/components';
import { createChatAgent, withDebug, withUI } from '@ray-js/t-agent';
import { ChatContainer, MessageInput, MessageList, MessageActionBar } from '@ray-js/t-agent-ui-ray';
import { withAIStream, withBuildIn } from '@ray-js/t-agent-plugin-aistream';

const createAgent = () => {
  const agent = createChatAgent(
    withUI(), // The first plugin withUI provides some default UI behaviors, required
    withAIStream({
      // withAIStream plugin connects to the mini-program AI agent platform, required in mini-programs
      earlyStart: true, // Whether to establish connection during onAgentStart phase
      agentId: '[your_agent_id]', // Enter your agent ID
    }),
    withDebug(), // withDebug prints logs in console
    withBuildIn() // withBuildIn plugin provides some built-in features
  );
  
  return agent;
};

export default function Home() {
  return (
    <View style={{ height: '100vh' }}>
      <ChatContainer createAgent={createAgent}>
        <MessageList />
        <MessageInput />
        <MessageActionBar />
      </ChatContainer>
    </View>
  );
}
```

> Replace `[your_agent_id]` with your Agent ID, which can be obtained from the Tuya AI [Tuya Developer Platform](https://platform.tuya.com/exp/ai).

### Advanced Configuration

#### Custom History Message Size

```tsx
withAIStream({
  agentId: '[your_agent_id]',
  historySize: 500, // History message size, default 1000
})
```

For more detailed instructions and advanced usage, please refer to the [T-Agent SDK Development Guide](https://developer.tuya.com/en/miniapp-codelabs/codelabs/t-agent-sdk-guide/index.html).
