Skip to main content

Deploying with CloudBase Run

CloudBase Run is the recommended way to deploy Agents. It supports persistent connections, custom runtimes, and elastic scaling, making it ideal for complex Agents and high-concurrency scenarios.

Prerequisites

  • A CloudBase environment has been activated
  • Python 3.9+ is installed
  • Agent development is complete
  • CloudBase CLI is installed (optional, for CLI-based deployment)

Code Examples

Project Structure

my-agent/
├── index.js # Entry file
├── package.json # Dependency configuration
└── Dockerfile # Container configuration

Entry File

// index.js
const { LangchainAgent, createAgentServer } = require("@cloudbase/agent-adapter-langchain");
const { createReactAgent } = require("@langchain/langgraph/prebuilt");
const { ChatOpenAI } = require("@langchain/openai");
const { tool } = require("@langchain/core/tools");
const { z } = require("zod");

// Define tools (optional)
const searchTool = tool(
async ({ query }) => {
return `Search results: relevant information about "${query}"...`;
},
{
name: "search",
description: "Search for information",
schema: z.object({
query: z.string().describe("Search keyword"),
}),
}
);

// Create the model
const model = new ChatOpenAI({
model: process.env.TCB_AI_MODEL || "hunyuan-turbos-latest",
apiKey: process.env.TCB_API_KEY,
configuration: {
baseURL: `https://${process.env.TCB_ENV_ID}.api.tcloudbasegateway.com/v1/ai/hunyuan/v1`,
},
});

// Create a ReAct Agent
const reactAgent = createReactAgent({
llm: model,
tools: [searchTool],
});

// Wrap as a CloudBase Agent
const agent = new LangchainAgent({
name: "SearchAgent",
description: "Intelligent search assistant",
agent: reactAgent,
});

// Export the server
module.exports = createAgentServer(agent);

Dependency Configuration

{
"name": "my-agent",
"main": "index.js",
"dependencies": {
"@cloudbase/agent-adapter-langchain": "latest",
"@cloudbase/agent-server": "latest",
"@langchain/langgraph": "latest",
"@langchain/openai": "latest",
"@langchain/core": "latest",
"zod": "^3.22.0"
}
}

Dockerfile

FROM node:18-slim

WORKDIR /app

# Install dependencies
COPY package*.json ./
RUN npm install --production

# Copy source code
COPY . .

# Set environment variables
ENV PORT=3000
EXPOSE 3000

# Start command
CMD ["node", "index.js"]

Deployment Methods

Method 1: Console Deployment

  1. Go to the CloudBase Console
  2. Select CloudBase RunCreate Service
  3. Choose Local Code as the upload method
  4. Upload the project code package (including the Dockerfile)
  5. Configure service parameters:
    • Service Name: A custom name, e.g., my-agent
    • Access Type: Select WEB (public network access)
    • CPU: Choose based on your needs; 0.5–2 cores recommended
    • Memory: CPU × 2, e.g., 0.5 cores → 1 GB
    • Minimum Instances: Set to 0 for development, 1 for production
    • Maximum Instances: Set based on concurrency needs; 5–20 recommended
  6. Click Confirm to start deployment

Method 2: CLI Deployment

Use the CloudBase CLI to quickly deploy a CloudBase Run service:

# Install CLI (if not already installed)
npm install -g @cloudbase/cli

# Log in to CloudBase
tcb login

# Run deployment from the project directory
tcb cloudrun deploy

The CLI will automatically detect the Dockerfile in your project, build the image, and deploy it to CloudBase Run. During the process, you will be prompted to provide:

  • Environment ID
  • Service name
  • Access type and other configuration

Configuration Reference

Resource Configuration

ParameterDescriptionRecommended Value
CPUNumber of CPU cores0.5–2
MemoryMemory sizeCPU × 2
Minimum InstancesMinimum running instances0 (on-demand) or 1 (avoid cold starts)
Maximum InstancesMaximum running instances5–20
tip

Resource constraint: Memory = 2 × CPU. For example, 0.5 vCPU corresponds to 1 GB of memory.

Access Configuration

Access TypeDescriptionUse Case
WEBPublic network accessWeb applications
VPCVPC private network accessInter-service calls
PRIVATEMini Program private direct connectionMini Programs

Environment Variables

Set environment variables in the console under Service Configuration:

VariableDescription
TCB_ENV_IDCloudBase environment ID
TCB_API_KEYAPI key
TCB_AI_MODELLarge model name, e.g., hunyuan-turbos-latest
tip

CloudBase has built-in support for Tencent Hunyuan and DeepSeek large models — no external API key required. For the list of supported models, refer to the Model Configuration Guide.

Local Debugging

Before deploying, it is recommended to develop and debug locally. For detailed guidance, refer to:

👉 Local Development Guide

The local development guide covers:

  • Getting the project code (GitHub template / syncing from an online service)
  • Installing dependencies and configuring environment variables
  • Starting the local service (including Docker)
  • Debugging with cURL or a proxy
  • Troubleshooting common issues

Monitoring & Operations

Viewing Logs

View service logs through the CloudBase console:

  1. Go to CloudBase Run → select the corresponding service
  2. Click Logs to view runtime logs

Performance Monitoring

Monitoring metrics:

  • Request volume
  • Response time
  • Error rate
  • CPU/memory utilization

Elastic Scaling

CloudBase Run supports automatic scaling:

  • Auto scale-out based on request volume
  • Auto scale-in to 0 when idle
  • Configurable minimum/maximum instance counts

Best Practices

  1. Resource Configuration

    • Configure CPU/memory based on Agent complexity
    • Set minimum instances ≥ 1 in production to avoid cold starts
  2. Access Control

    • Use PRIVATE private direct connection for Mini Programs
    • Use WEB + SDK authentication for web applications
  3. Environment Isolation

    • Use separate environments for development, testing, and production
    • Configure sensitive information via environment variables
  4. Image Optimization

    • Use lightweight base images
    • Use multi-stage builds to reduce image size
    • Optimize dependencies to reduce cold start time