@ag-kit/adapter-adp
Tencent Cloud ADP (Agent Development Platform) adapter for AG-Kit agents. This package provides integration between AG-Kit and Tencent Cloud's LKE (Large Knowledge Engine) service, enabling you to use ADP chatbots with AG-Kit's agent infrastructure.
Installation
npm install @ag-kit/agents @ag-kit/adapter-adp
Features
- AdpAgent: Agent implementation that connects to Tencent Cloud ADP chatbot services
- Streaming Support: Real-time SSE (Server-Sent Events) streaming responses
- Thinking Events: Support for thinking/reasoning process events from the model
- Workflow Integration: Support for ADP workflows with tool call events
- Custom Variables: Pass custom parameters to workflows and knowledge base
Environment Variables
Configure the following environment variables:
ADP_APP_KEY=your-adp-app-key
TENCENTCLOUD_SECRETID=your-tencent-cloud-secret-id
TENCENTCLOUD_SECRETKEY=your-tencent-cloud-secret-key
TENCENTCLOUD_SESSIONTOKEN=your-tencent-cloud-session-token
Usage
Basic Agent Setup
import { AdpAgent } from "@ag-kit/adapter-adp";
const agent = new AdpAgent({
name: "my-adp-agent",
description: "A Tencent Cloud ADP chatbot agent",
adpConfig: {
appKey: process.env.ADP_APP_KEY,
},
});
With Credentials in Config
import { AdpAgent } from "@ag-kit/adapter-adp";
const agent = new AdpAgent({
name: "my-adp-agent",
description: "An ADP agent with inline credentials",
adpConfig: {
appKey: "your-app-key",
credential: {
secretId: "your-secret-id",
secretKey: "your-secret-key",
token: "your-session-token",
},
},
});
With Custom Request Options
import { AdpAgent } from "@ag-kit/adapter-adp";
const agent = new AdpAgent({
name: "my-adp-agent",
description: "An ADP agent with custom config",
adpConfig: {
appKey: "your-app-key",
request: {
baseUrl: "https://wss.lke.cloud.tencent.com",
endpoint: "/v1/qbot/chat/sse",
body: {
modelName: "gpt-4",
searchNetwork: "enable",
workflowStatus: "enable",
systemRole: "You are a helpful assistant",
},
},
},
});
Running the Agent
import { randomUUID } from "crypto";
const runId = randomUUID();
const threadId = randomUUID();
const observable = agent.run({
runId,
threadId,
messages: [
{
id: randomUUID(),
role: "user",
content: "Hello, how can you help me?",
},
],
forwardedProps: {
visitorBizId: "user-123",
customVariables: {
key1: "value1",
},
},
});
observable.subscribe({
next: (event) => console.log(event),
complete: () => console.log("Done"),
error: (err) => console.error(err),
});
API Reference
AdpAgent
Agent class that extends AbstractAgent and connects to Tencent Cloud ADP services.
Constructor:
constructor(config: AgentConfig & { adpConfig: AdpConfig })
AdpConfig
Configuration options for the ADP adapter.
interface AdpConfig {
appKey?: string;
credential?: {
secretId?: string;
secretKey?: string;
token?: string;
};
historyCount?: number;
request?: {
baseUrl?: string;
endpoint?: string;
body?: Partial<AdpChatRequest>;
};
}
AdpChatRequest Options
For further information, please check the ADP product documentation.
interface AdpChatRequest {
streamingThrottle?: number;
customVariables?: Record<string, string>;
systemRole?: string;
incremental?: boolean;
searchNetwork?: "" | "enable" | "disable";
modelName?: string;
stream?: "" | "enable" | "disable";
workflowStatus?: "" | "enable" | "disable";
}
Supported Events
The adapter emits the following AG-UI events:
RUN_STARTED / RUN_FINISHED / RUN_ERROR - Run lifecycle events
TEXT_MESSAGE_CHUNK (TEXT_MESSAGE_START / TEXT_MESSAGE_CONTENT / TEXT_MESSAGE_END) - Streaming text response chunks
THINKING_START / THINKING_END - Thinking process boundaries
THINKING_TEXT_MESSAGE_START / THINKING_TEXT_MESSAGE_CONTENT / THINKING_TEXT_MESSAGE_END - Thinking content events
TOOL_CALL_START / TOOL_CALL_ARGS / TOOL_CALL_END / TOOL_CALL_RESULT - Workflow tool call events
Requirements
@ag-ui/client: AG-UI client protocol
axios: HTTP client for API requests
rxjs: Reactive extensions for JavaScript
tencentcloud-sdk-nodejs-lke: Tencent Cloud LKE SDK
Related Resources