Skip to main content

OpenAgentKernel is open source: the framework layer for agent development, written for you

CloudBase TeamCloudBase Team
7 min read

AI agent development today resembles web development before frameworks — every developer builds the same underlying layer, handling a lot of repetitive logic:

  • Session history and compression
  • Disconnection and reconnection
  • Sandbox integration
  • MCP/Skills integration
  • Human in the Loop
  • Multi-turn model loops
  • ……

Only a small fraction of the code is actually related to the developer's own business; 70% of the work goes into these low-level details.

This is much like web development's "slash-and-burn" era: every team repeated the wheel from routing, ORM and session management, until full-stack frameworks like Django and Rails standardized the infrastructure and developers' energy finally returned to business logic.

Agent development now stands at that same dividing line. Although code is still the main way to build agents, developers clearly no longer need to hand-write session persistence and tool orchestration.

To solve these agent-developer pain points, we're pleased to release OpenAgentKernel:

This is an agent framework natively built for CloudBase, with session persistence, tool orchestration and human-in-the-loop (HITL) built in, letting developers focus on business logic instead of infrastructure details.

Try it now

npm install @cloudbase/open-agent-kernel@beta

Prerequisites: Node.js 22+, a CloudBase environment's envId, and the environment's server-side API Key.

Minimal example: understand the core API in thirty seconds

import { createAgent } from "@cloudbase/open-agent-kernel";

process.env.TCB_API_KEY = "your-cloudbase-api-key";

// Create an agent
const agent = createAgent({
envId: "your-env-id",
model: "deepseek-v4-pro",
systemPrompt: "你是一个智能助手,请帮我回答用户的问题",
});

// Create a session
const session = await agent.startSession({ userId: "user-1" });

// Send a message and receive the response
for await (const event of session.send("一句话解释:什么是 Serverless?")) {
if (event.type === "message_delta") process.stdout.write(event.text);
if (event.type === "session_idle") break; // this turn ends
}

You can easily deploy the code above to a CloudBase HTTP cloud function and test it with curl or Postman.

Features

1. Session persistence and cross-process recovery

Session records persist to the cloud development database by default, not process memory.

const agent = createAgent({
envId: "your-env-id",
model: "deepseek-v4-pro",
systemPrompt: "你是一个智能助手,请帮我回答用户的问题",
});

const session = await agent.startSession({ userId: "user-1" });
const conversationId = session.id;

In another process later (say, a second function invocation), use conversationId to restore the conversation context directly:

const resumed = await agent.resumeSession(conversationId);

2. MCP integration

MCP integration is nearly a must in agent development, so we built in several ways: in-process, local stdio, remote HTTP.

import { createSdkMcpServer, tool } from "@anthropic-ai/claude-agent-sdk";
import { z } from "zod";

// In-process MCP
const localMCPServer = createSdkMcpServer({
name: "calc",
version: "1.0.0",
tools: [
tool(
"add",
"Add two numbers",
{ a: z.number(), b: z.number() },
async (args) => ({
content: [{ type: "text", text: String(args.a + args.b) }],
}),
),
],
});

// Local stdio MCP
const stdioMCPServer = {
type: "stdio",
command: "npx",
args: ["-y", "@modelcontextprotocol/server-everything"],
};

// Remote HTTP MCP
const remoteMCPServer = {
type: "http",
url: "https://example.com/mcp/v1",
headers: { Authorization: "Bearer xxx" },
};

const agent = createAgent({
envId,
model: "glm-5.2",
systemPrompt: "你是一个智能助手,请帮我回答用户的问题",
mcpServers: {
local: localMCPServer,
stdio: stdioMCPServer,
remote: remoteMCPServer,
},
});

3. Human in the Loop (HITL)

For sensitive agent operations (deleting a database, setting a password, etc.), we usually need the user's confirmation before the agent continues.

const agent = createAgent({
envId,
model: "glm-5.2",
systemPrompt: "你是一个智能助手,请帮我回答用户的问题",

// Configure which tools need human approval
permissions: {
requireApproval: ["database_delete", "reset_password"],
},
});

Once configured, if the agent hits a tool requiring approval during a task, the response event stream triggers a tool_approval_required event. Developers can build the human-confirmation UI on top of it:

const session = await agent.startSession({ userId: "user-1" });

for await (const event of session.send("帮我删除 todo_list 这个数据表")) {
if (event.type === "tool_approval_required") {
// implement the confirmation UI; get event.toolUseId and call session.respondApproval()
}
}

4. Agent memory

Memory is now a built-in capability for most agents. In OpenAgentKernel, we built it in:

const agent = createAgent({
envId,
model: "glm-5.2",
systemPrompt: "你是一个智能助手,请帮我回答用户的问题",
// enable memory
userMemory: true,
});

The user's private .claude/ memory files sync automatically to CloudBase cloud storage and take effect across sessions.

Developers can also proactively call APIs to preset or delete memory:

import { writeUserMemoryFiles } from "@cloudbase/open-agent-kernel";

await writeUserMemoryFiles({
envId,
userId: "alice",
files: [{ path: "CLAUDE.md", content: "请始终用中文回答。" }],
});

5. Sandbox: run code and touch files safely

Agents running code, changing files and executing shells need an isolated execution environment. So we built sandbox support into OpenAgentKernel:

const agent = createAgent({
envId,
model: "glm-5.2",
systemPrompt: "你是一个全能编程助手,帮助用户编写代码",
// enable Sandbox
sandbox: {
enabled: true,
cloudbaseTools: true, // when the image supports it, CloudBase MCP tools can be called inside the sandbox
scope: "shared", // shared: shared instance across sessions; session: independent instance per session
ttl: 3600,
},
});

With the sandbox on, the agent executes code and reads/writes files inside it. For example, generating a web page and previewing it:

const session = await agent.startSession({ userId: "user-1" });
session.send(
"帮我写一个个人博客的首页,用 React + Tailwind CSS,然后部署到 CloudBase 上"
);

The agent then creates files, installs dependencies and uses the CloudBase credentials built into the sandbox to deploy the artifact to the cloud — the developer doesn't manage or schedule the sandbox.

CloudBase's Sandbox capability is in internal beta; contact us if you need it.

How we use OpenAgentKernel ourselves

Most of CloudBase's AI features are now built on OpenAgentKernel, including:

CloudBase Agent

The Agent section of the CloudBase console was rebuilt on OpenAgentKernel: when creating a new agent, choosing the official cloudbase-agent template gives you an OpenAgentKernel project — session persistence, MCP tools and human approval out of the box. Once created, you can chat directly on the "Connect & debug" page.

For deep customization, the "Local development" page gives full guidance: tcb fn code download pulls the code locally for your AI coding tool to modify, then tcb fn deploy deploys it back with one command. The console handles hosting, logs and debug entry; OpenAgentKernel handles the runtime.

Issue Agent

The CloudBase community's (CNB) Issue Bot is an OpenAgentKernel agent running in a pipeline. When a new issue arrives, it researches materials in the role of a "cloud development engineer" and gives grounded answers.

It uses three OpenAgentKernel capabilities: an in-process MCP server provides controlled tools, final answers must be published through the reply tool, mechanically guaranteeing "either evidence-based or explicitly marked as inference"; skills load answering experience (issue-agent-guide); multimodal attachments let it read error screenshots users paste — screenshots are first recognized one by one in a vision session, then enter the main flow.

Use OpenAgentKernel now

npm install @cloudbase/open-agent-kernel@beta

Or view the code at:

Or open the Agent section of the CloudBase console (https://tcb.cloud.tencent.com/dev) directly to start your agent development journey:

Follow Tencent Cloud Development for product updates and best practices.

Build your next app on CloudBase

An all-in-one backend covering database, cloud functions, static hosting, and AI capabilities.