Skip to main content

Overview

What is Agent

Agent, or AI Agent, is based on large models and can complete specific tasks through specific instructions or guidance. Agent leverages AI large models, has strong language understanding and generation capabilities, and can perform complex tasks in various fields.

What is Cloud Development Agent

Cloud Development Agent is implemented based on Function-based Cloud Hosting. Developers can fully control the business logic to meet highly personalized requirements. In the function, they can call third-party models, design complex decision-making processes, and use open-source Agent development frameworks to achieve capabilities such as Agent's Perception, Planning, and Action, thereby better achieving personalized requirements.

Developing an AI Agent based on Cloud Functions is a process of backend adapting to frontend. By implementing the agreed-upon API interfaces in Cloud Functions, backend-frontend adaptation and integration can be achieved.

With the AI Agent development framework @cloudbase/aiagent-framework provided by Cloud Development, you can quickly implement a simple blank Agent based on Function-based Cloud Hosting with just a few lines of code. The sample code is as follows:

const { IBot } = require("@cloudbase/aiagent-framework");
const { BotRunner } = require("@cloudbase/aiagent-framework");

const ANSWER = "Hello, I am an Agent, but I can only say this one sentence.";

/**
* @typedef {import('@cloudbase/aiagent-framework').IAbstractBot} IAbstractBot
*
* @class
* @implements {IAbstractBot}
*/
class MyBot extends IBot {
async sendMessage() {
return new Promise((res) => {
// Create a character array
const charArr = ANSWER.split("");

const interval = setInterval(() => {
// Periodically take a character from the array
const char = charArr.shift();

if (typeof char === "string") {
// When characters are present, send an SSE message to the client
this.sseSender.send({ data: { content: char } });
} else {
// After the characters are exhausted, end the periodic loop
clearInterval(interval);
// End SSE
this.sseSender.end();
res();
}
}, 50);
});
}
}

/**
* For the complete type definition, please refer to: https://docs.cloudbase.net/cbrf/how-to-writing-functions-code#%E5%AE%8C%E6%95%B4%E7%A4%BA%E4%BE%8B
* "{demo: string}" is an example type declaration for the event parameter; please modify it according to the actual situation.
* Type hints will take effect only after installing dependencies via `pnpm install`.
*
* @type {import('@cloudbase/functions-typings').TcbEventFunction<unknown>}
*/
exports.main = function (event, context) {
return BotRunner.run(event, context, new MyBot(context));
};

Use the Agent

The developed Agent can be used in the following ways:

  • Through front-end components, quickly introduce and configure the Agent in mini programs, enabling communication with the Agent in conversation components;
  • Via the SDK, call the Agent in the frontend logic of mini programs, H5, and Web applications, or in the backend logic such as cloud functions and servers to achieve interaction with the Agent;
  • Through third-party platform integration capabilities, complete the integration of the Agent with WeChat Mini Program Customer Service, WeChat Customer Service, WeChat Official Accounts (Service Accounts), and WeChat Official Accounts (Subscription Accounts), enabling chat conversations on these platforms to integrate with the Agent;