
Security News
The Code You Didn't Write Is Still Yours to Defend
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.
@cloudbase/agent-server
Advanced tools
将 AG-UI 兼容的 Agent 部署为 HTTP 服务。
AG-UI 是一个开放、轻量级、基于事件的协议,用于标准化 AI Agent 与用户界面的交互。它让 Agent 可以:
/send-message、/healthz 等端点flowchart LR
Client[AG-UI 客户端] -->|AG-UI 协议| Server["@cloudbase/agent-server"]
Server --> Adapter[Adapter<br/>LangGraph / LangChain]
Adapter --> Agent[Agent 框架]
| 包名 | 作用 |
|---|---|
@cloudbase/agent-adapter-langgraph | LangGraph 工作流适配器 |
@cloudbase/agent-adapter-langchain | LangChain Agent 适配器 |
express | HTTP 服务框架 |
pnpm add @cloudbase/agent-server express
import { run } from "@cloudbase/agent-server";
import { LanggraphAgent } from "@cloudbase/agent-adapter-langgraph";
import { workflow } from "./workflow.js"; // 你的 LangGraph 工作流
run({
createAgent: () => ({
agent: new LanggraphAgent({ workflow }),
}),
port: 9000,
});
创建一个配置好的 Express 应用:
import { createExpressServer } from "@cloudbase/agent-server";
import { LanggraphAgent } from "@cloudbase/agent-adapter-langgraph";
import { workflow } from "./workflow.js";
const app = createExpressServer({
createAgent: () => ({
agent: new LanggraphAgent({ workflow }),
}),
});
app.listen(9000, () => console.log("Listening on 9000!"));
将路由挂载到现有的 Express 应用:
import { createExpressRoutes } from "@cloudbase/agent-server";
import { LanggraphAgent } from "@cloudbase/agent-adapter-langgraph";
import { workflow } from "./workflow.js";
import express from "express";
const app = express();
createExpressRoutes({
createAgent: () => ({
agent: new LanggraphAgent({ workflow }),
}),
express: app,
});
app.listen(9000, () => console.log("Listening on 9000!"));
创建并启动 HTTP 服务。
run({
createAgent,
port: 9000,
});
参数:
| 参数 | 类型 | 说明 |
|---|---|---|
createAgent | AgentCreator | Agent 创建函数,见下方说明 |
port | number | string | 监听端口 |
basePath | string | 可选,路由基础路径,默认为 /,云函数环境默认为 /v1/aibot/bots/:agentId/ |
cors | boolean | CorsOptions | 可选,CORS 配置,默认启用 |
logger | Logger | 可选,日志实例,用于记录服务端日志 |
创建一个配置好的 Express 应用。
const app = createExpressServer({
createAgent,
cors: true, // 可选,默认启用 CORS
});
参数:
| 参数 | 类型 | 说明 |
|---|---|---|
createAgent | AgentCreator | Agent 创建函数,见下方说明 |
basePath | string | 可选,路由基础路径 |
cors | boolean | CorsOptions | 可选,CORS 配置,默认启用 |
logger | Logger | 可选,日志实例,用于记录服务端日志 |
将 AG-UI 路由挂载到现有的 Express 应用。
createExpressRoutes({
createAgent,
express: app,
basePath, // 可选
});
参数:
| 参数 | 类型 | 说明 |
|---|---|---|
createAgent | AgentCreator | Agent 创建函数,见下方说明 |
express | Express | Express 应用实例 |
basePath | string | 可选,路由基础路径,默认为 /,云函数环境默认为 /v1/aibot/bots/:agentId/ |
logger | Logger | 可选,日志实例,用于记录服务端日志 |
| 端点 | 说明 |
|---|---|
{basePath}send-message | AG-UI 消息发送端点 |
{basePath}healthz | 健康检查端点 |
createAgent 返回一个对象:
agent:符合 AG-UI 协议 的 Agentcleanup:可选,请求结束后的清理函数type AgentCreator = (context?: {
request: Request; // 当前 HTTP 请求(Web Standard Request)
logger?: Logger; // 日志实例(带 requestId 上下文)
requestId?: string; // 请求追踪 ID
}) => AgentCreatorResult | Promise<AgentCreatorResult>; // 支持异步
type AgentCreatorResult = {
agent: AbstractAgent | { toAGUIAgent(): AbstractAgent }; // AG-UI 兼容的 Agent
cleanup?: () => void; // 可选,清理函数
};
使用适配器将你的 Agent 框架转换为 AG-UI 兼容的 Agent:
| 适配器 | 包名 | 说明 |
|---|---|---|
LanggraphAgent | @cloudbase/agent-adapter-langgraph | LangGraph 工作流适配器 |
LangchainAgent | @cloudbase/agent-adapter-langchain | LangChain Agent 适配器 |
import { LanggraphAgent } from "@cloudbase/agent-adapter-langgraph";
createAgent: () => ({
agent: new LanggraphAgent({ workflow }),
})
高级用法: createAgent 可以接收请求上下文,也支持异步:
createAgent: async (context) => {
console.log("Request ID:", context.requestId);
return { agent: new LanggraphAgent({ workflow }) };
}
logger 参数用于记录服务端日志。需要实现以下接口:
interface Logger {
info?(message: string): void;
info?(obj: object, message?: string): void;
debug?(message: string): void;
debug?(obj: object, message?: string): void;
warn?(message: string): void;
warn?(obj: object, message?: string): void;
error?(message: string): void;
error?(obj: object, message?: string): void;
trace?(message: string): void;
trace?(obj: object, message?: string): void;
child?(bindings: object): Logger; // 创建带上下文的子 logger
}
示例:
// 开发环境:使用 console
run({ createAgent, logger: console, port: 9000 });
// 生产环境:使用 pino
import pino from "pino";
run({ createAgent, logger: pino({ level: "info" }), port: 9000 });
📚 完整文档请参阅 云开发 Agent 开发指南
FAQs
将 AG-UI 兼容的 Agent 部署为 HTTP 服务。
We found that @cloudbase/agent-server demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 15 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.