CloudBase Agent Python SDK
Build production-ready AI agent backends with multi-framework support, streaming
protocol, rich tools, persistent memory, and full observability.
Note: This skill is for Python projects only.
When to use this skill
Use this skill for AI agent development when you need to:
- Deploy AI agents as HTTP services with AG-UI protocol support
- Build agent backends using LangGraph, CrewAI, or LlamaIndex frameworks
- Create custom agent adapters implementing the AbstractAgent interface
- Understand AG-UI protocol events and message streaming
- Build production-ready agent servers with FastAPI
Do NOT use for:
- Simple AI model calling without agent capabilities (use
ai-model-* skills)
- CloudBase cloud functions (use
cloud-functions skill)
- CloudRun backend services without agent features (use
cloudrun-development skill)
- TypeScript/JavaScript agent projects (use
cloudbase-agent skill, refer to the ts/ sub-directory)
How to use this skill (for a coding agent)
Choose the right adapter
- Use LangGraph adapter for stateful, graph-based workflows
- Use CrewAI adapter for multi-agent collaboration patterns
- Build custom adapter for specialized agent logic
Write agent code — follow the adapter-specific doc from the Routing table
Deploy the agent server — follow the blocking deployment pipeline in agent-deployment
Routing (Execution Order)
⚠️ Deployment is a BLOCKING 4-step pipeline. Steps marked ✅ BLOCKING
must be completed AND verified before proceeding to the next step.
Do NOT call manageAgent until all blocking steps pass.
| Step |
Task |
Document |
Blocking? |
| 0 |
Choose adapter & write agent code |
See "Adapter Selection" below |
— |
| 1 |
Ensure Python 3.10 |
agent-deployment § Step 1 |
✅ BLOCKING |
| 2 |
Build env/ (one-shot) |
agent-deployment § Step 2 |
✅ BLOCKING |
| 3 |
Verify env/ integrity |
agent-deployment § Step 3 |
✅ BLOCKING |
| 4 |
Deploy with manageAgent |
agent-deployment § Step 4 |
— |
Adapter Selection (Step 0)
| Framework |
Read |
Install |
| LangGraph (stateful graphs) |
adapter-langgraph |
cloudbase-agent-langgraph |
| CrewAI (multi-agent crews) |
adapter-development |
cloudbase-agent-crewai |
| Coze platform |
adapter-coze |
cloudbase-agent-coze |
| Custom / raw FastAPI |
server-quickstart + adapter-development |
cloudbase-agent-server |
Additional References (read on demand, NOT required for deployment)
| Task |
Read |
| Server setup, middleware, multi-agent, CORS |
server-quickstart |
| Authentication and user context |
authentication |
Quick Start (Framework-Agnostic)
Prerequisites: Python >= 3.10 is required.
1. Install dependencies (pick ONE adapter):
# Option A: LangGraph-based agent
pip install cloudbase-agent-langgraph
# Option B: CrewAI-based agent
pip install cloudbase-agent-crewai
# Option C: Custom / minimal
pip install cloudbase-agent-server
2. Create server entry point:
# server.py — this pattern works with ANY adapter
import os
from dotenv import load_dotenv
load_dotenv()
from cloudbase_agent.server import AgentServiceApp, AgentCreatorResult
# Import your agent (framework-specific, see adapter docs)
# from agents.chat.agent import create_my_agent
def create_agent() -> AgentCreatorResult:
agent = create_my_agent() # Your agent factory
return {"agent": agent}
app = AgentServiceApp()
app.set_cors_config(allow_origins=["*"])
if __name__ == "__main__":
port = int(os.environ.get("SCF_RUNTIME_PORT", "9000"))
app.run(create_agent, port=port, host="0.0.0.0")
3. Deploy to CloudBase:
Follow the 4-step deployment pipeline in agent-deployment.
Architecture
Client (React / MiniProgram / curl)
│ HTTP POST + SSE streaming
▼
┌─────────────────────────────────────────────┐
│ AgentServiceApp (FastAPI) │
│ ├─ /send-message ← AG-UI SSE │
│ ├─ /chat/completions ← OpenAI-compat │
│ └─ Middleware chain (onion model) │
├─────────────────────────────────────────────┤
│ Agent Layer │
│ ├─ LangGraphAgent ├─ CrewAIAgent │
│ ├─ LlamaIndexAgent ├─ CozeAgent/DifyAgent │
│ └─ BaseAgent (extend for custom) │
├──────────────────┬──────────────────────────┤
│ Tools │ Storage │
│ Bash/FS/Code/MCP│ Memory + LongTermMemory │
├─────────────────────────────────────────────┤
│ Observability (OpenTelemetry + Langfuse) │
└─────────────────────────────────────────────┘
Installation
CloudBase Agent Python SDK is published to PyPI as separate packages. Note: PyPI package names use hyphens (cloudbase-agent-*), and Python imports use the same namespace (cloudbase_agent.*).
# Core + Server + LangGraph (most common)
pip install cloudbase-agent-langgraph
# Individual packages
pip install cloudbase-agent-core # Core framework
pip install cloudbase-agent-server # FastAPI server
pip install cloudbase-agent-langgraph # LangGraph integration
pip install cloudbase-agent-tools # Tool system
pip install cloudbase-agent-storage # Memory/Storage
pip install cloudbase-agent-observability # OpenTelemetry/Langfuse
pip install cloudbase-agent-coze # Coze platform
pip install cloudbase-agent-crewai # CrewAI integration
Import Note: All packages share the cloudbase_agent namespace:
# After installing cloudbase-agent-langgraph, import from cloudbase_agent
from cloudbase_agent.langgraph import LangGraphAgent
from cloudbase_agent.server import AgentServiceApp
from cloudbase_agent.tools import create_bash_tool
Reference Documents
Based on what the user needs, read the corresponding reference document.
Only read the relevant reference — don't load all of them.
| User Need |
Reference |
What It Covers |
| Deploying agent to CloudBase |
Read agent-deployment |
manageAgent MCP tool (MUST USE), 4-step blocking pipeline, Python 3.10, env/ build, verification |
| Server setup, deployment, middleware, multi-agent, CORS |
Read references/server.md |
AgentServiceApp 3 deployment methods, middleware (generator/yield/onion model), multi-agent server, Agent Creator pattern, health checks |
| LangGraph agent, callbacks, tool proxy, HITL, checkpoints |
Read references/langgraph.md |
LangGraphAgent constructor, AgentCallback protocol, ToolProxy, human-in-the-loop with interrupt(), TDAICheckpointSaver, client-defined tools |
| Tools: bash, filesystem, code execution, MCP, custom tools |
Read references/tools.md |
create_bash_tool, 8 file tools, code executors, MCPToolkit/CloudBaseMCPServer, @tool decorator, BaseTool, framework adapters |
| Memory, persistence, short/long-term, MySQL, MongoDB |
Read references/storage.md |
InMemoryMemory, TDAIMemory, MySQLMemory, MongoDBMemory, TDAILongTermMemory, Mem0LongTermMemory, LangGraph checkpoint |
| Tracing, monitoring, Langfuse, OpenTelemetry |
Read references/observability.md |
ConsoleTraceConfig, OTLPTraceConfig, setup_observability, env vars, manual observation spans |
| Common patterns, JWT auth, MCP integration, production |
Read references/recipes.md |
JWT middleware, MCP + LangGraph, production deployment, adding tools to agents, client-defined tools |
Key Imports Quick Reference
# Server
from cloudbase_agent.server import AgentServiceApp, AgentCreatorResult
from cloudbase_agent.server import create_send_message_adapter, create_openai_adapter
from cloudbase_agent.server import RunAgentInput, OpenAIChatCompletionRequest
# Agents
from cloudbase_agent.langgraph import LangGraphAgent
from cloudbase_agent.crewai import CrewAIAgent
# Tools
from cloudbase_agent.tools import create_bash_tool, create_read_tool, create_write_tool
from cloudbase_agent.tools import MCPToolkit, CloudBaseMCPServer, CloudBaseTool
from cloudbase_agent.tools import tool, BaseTool # custom tools
# Storage
from cloudbase_agent.storage import InMemoryMemory, TDAIMemory
from cloudbase_agent.storage import TDAILongTermMemory, Mem0LongTermMemory
from cloudbase_agent.langgraph import TDAICheckpointSaver, TDAIStore
# Observability
from cloudbase_agent.observability import ConsoleTraceConfig, OTLPTraceConfig, setup_observability
# Schemas
from cloudbase_agent.schemas import Message, MessageRole, StreamEvent, EventType
Project Structure Convention
my-agent-project/
├── agents/
│ ├── agentic_chat/agent.py # build_workflow() → agent instance
│ ├── human_in_the_loop/agent.py
│ └── __init__.py
├── server.py # Main entry: AgentServiceApp().run(...)
├── scf_bootstrap # CloudBase startup script (required for deployment)
├── .env # OPENAI_API_KEY, etc.
└── requirements.txt
Environment Variables
| Variable |
Purpose |
OPENAI_API_KEY |
OpenAI API key |
AUTO_TRACES_STDOUT |
Enable console tracing (true) |
LANGFUSE_PUBLIC_KEY / LANGFUSE_SECRET_KEY |
Langfuse keys |
TDAI_ENDPOINT / TDAI_API_KEY |
TDAI memory/checkpoint endpoint |
SCF_RUNTIME_PORT |
CloudBase runtime port (set automatically during deployment) |
Key Design Decisions
- Agent Creator Pattern: Every request creates a fresh agent via factory function. Supports cleanup callbacks for resource release.
- Dual Protocol: Every agent supports both AG-UI native (SSE + rich events) and OpenAI-compatible (
/chat/completions).
- Middleware = Generator: Use
yield — pre-yield = pre-processing, post-yield = post-processing (onion model).
- Namespace Package:
cloudbase_agent spans multiple PyPI packages (cloudbase-agent-core, cloudbase-agent-server, cloudbase-agent-langgraph, etc.). PyPI names use hyphens, but all imports use from cloudbase_agent.xxx import ....
- Observability Auto-Integration: Install
cloudbase-agent-observability and tracing works automatically — zero config needed.
- Deploy with manageAgent: Always use the
manageAgent MCP tool for CloudBase deployment. Follow the 4-step blocking pipeline in agent-deployment.
1---
2name: cloudbase-agent-python
3description: "Build production-ready AI agent backends using the CloudBase Agent Python SDK — create agents with LangGraph/CrewAI/LlamaIndex, serve them via FastAPI with AG-UI protocol streaming + OpenAI-compatible endpoints, add tools (bash, filesystem, MCP, code execution), memory (in-memory, TDAI, MySQL, MongoDB), observability (OpenTelemetry/Langfuse), and middleware (auth, logging). Use this skill when the user wants to create an AI agent server, build a chatbot backend, set up human-in-the-loop workflows, integrate MCP tools, add agent observability, or deploy an agent API — even if they don't explicitly mention 'CloudBase Agent.'"
4alwaysApply: true
5metadata:
6 source: https://skillmd.com/skills/infometa/cloudbase-agent-python
7---
8
9# CloudBase Agent Python SDK
10
11Build production-ready AI agent backends with multi-framework support, streaming
12protocol, rich tools, persistent memory, and full observability.
13
14> **Note:** This skill is for **Python** projects only.
15
16## When to use this skill
17
18Use this skill for **AI agent development** when you need to:
19
20- Deploy AI agents as HTTP services with AG-UI protocol support
21- Build agent backends using LangGraph, CrewAI, or LlamaIndex frameworks
22- Create custom agent adapters implementing the AbstractAgent interface
23- Understand AG-UI protocol events and message streaming
24- Build production-ready agent servers with FastAPI
25
26**Do NOT use for:**
27- Simple AI model calling without agent capabilities (use `ai-model-*` skills)
28- CloudBase cloud functions (use `cloud-functions` skill)
29- CloudRun backend services without agent features (use `cloudrun-development` skill)
30- TypeScript/JavaScript agent projects (use `cloudbase-agent` skill, refer to the `ts/` sub-directory)
31
32## How to use this skill (for a coding agent)
33
341. **Choose the right adapter**
35 - Use LangGraph adapter for stateful, graph-based workflows
36 - Use CrewAI adapter for multi-agent collaboration patterns
37 - Build custom adapter for specialized agent logic
38
392. **Write agent code** — follow the adapter-specific doc from the Routing table
40
413. **Deploy the agent server** — follow the **blocking deployment pipeline** in [agent-deployment](agent-deployment.md)
42
43## Routing (Execution Order)
44
45> ⚠️ **Deployment is a BLOCKING 4-step pipeline.** Steps marked ✅ BLOCKING
46> must be completed AND verified before proceeding to the next step.
47> Do NOT call `manageAgent` until all blocking steps pass.
48
49| Step | Task | Document | Blocking? |
50|------|------|----------|-----------|
51| 0 | **Choose adapter & write agent code** | See "Adapter Selection" below | — |
52| 1 | **Ensure Python 3.10** | [agent-deployment](agent-deployment.md) § Step 1 | ✅ BLOCKING |
53| 2 | **Build env/ (one-shot)** | [agent-deployment](agent-deployment.md) § Step 2 | ✅ BLOCKING |
54| 3 | **Verify env/ integrity** | [agent-deployment](agent-deployment.md) § Step 3 | ✅ BLOCKING |
55| 4 | **Deploy with manageAgent** | [agent-deployment](agent-deployment.md) § Step 4 | — |
56
57### Adapter Selection (Step 0)
58
59| Framework | Read | Install |
60|-----------|------|---------|
61| LangGraph (stateful graphs) | [adapter-langgraph](adapter-langgraph.md) | `cloudbase-agent-langgraph` |
62| CrewAI (multi-agent crews) | [adapter-development](adapter-development.md) | `cloudbase-agent-crewai` |
63| Coze platform | [adapter-coze](adapter-coze.md) | `cloudbase-agent-coze` |
64| Custom / raw FastAPI | [server-quickstart](server-quickstart.md) + [adapter-development](adapter-development.md) | `cloudbase-agent-server` |
65
66### Additional References (read on demand, NOT required for deployment)
67
68| Task | Read |
69|------|------|
70| Server setup, middleware, multi-agent, CORS | [server-quickstart](server-quickstart.md) |
71| Authentication and user context | [authentication](authentication.md) |
72
73## Quick Start (Framework-Agnostic)
74
75**Prerequisites:** Python >= 3.10 is required.
76
77**1. Install dependencies (pick ONE adapter):**
78
79```bash
80# Option A: LangGraph-based agent
81pip install cloudbase-agent-langgraph
82
83# Option B: CrewAI-based agent
84pip install cloudbase-agent-crewai
85
86# Option C: Custom / minimal
87pip install cloudbase-agent-server
88```
89
90**2. Create server entry point:**
91
92```python
93# server.py — this pattern works with ANY adapter
94import os
95from dotenv import load_dotenv
96load_dotenv()
97
98from cloudbase_agent.server import AgentServiceApp, AgentCreatorResult
99
100# Import your agent (framework-specific, see adapter docs)
101# from agents.chat.agent import create_my_agent
102
103def create_agent() -> AgentCreatorResult:
104 agent = create_my_agent() # Your agent factory
105 return {"agent": agent}
106
107app = AgentServiceApp()
108app.set_cors_config(allow_origins=["*"])
109
110if __name__ == "__main__":
111 port = int(os.environ.get("SCF_RUNTIME_PORT", "9000"))
112 app.run(create_agent, port=port, host="0.0.0.0")
113```
114
115**3. Deploy to CloudBase:**
116
117Follow the **4-step deployment pipeline** in [agent-deployment](agent-deployment.md).
118
119---
120
121## Architecture
122
123```
124Client (React / MiniProgram / curl)
125 │ HTTP POST + SSE streaming
126 ▼
127┌─────────────────────────────────────────────┐
128│ AgentServiceApp (FastAPI) │
129│ ├─ /send-message ← AG-UI SSE │
130│ ├─ /chat/completions ← OpenAI-compat │
131│ └─ Middleware chain (onion model) │
132├─────────────────────────────────────────────┤
133│ Agent Layer │
134│ ├─ LangGraphAgent ├─ CrewAIAgent │
135│ ├─ LlamaIndexAgent ├─ CozeAgent/DifyAgent │
136│ └─ BaseAgent (extend for custom) │
137├──────────────────┬──────────────────────────┤
138│ Tools │ Storage │
139│ Bash/FS/Code/MCP│ Memory + LongTermMemory │
140├─────────────────────────────────────────────┤
141│ Observability (OpenTelemetry + Langfuse) │
142└─────────────────────────────────────────────┘
143```
144
145## Installation
146
147CloudBase Agent Python SDK is published to PyPI as separate packages. **Note: PyPI package names use hyphens (`cloudbase-agent-*`), and Python imports use the same namespace (`cloudbase_agent.*`)**.
148
149```bash
150# Core + Server + LangGraph (most common)
151pip install cloudbase-agent-langgraph
152
153# Individual packages
154pip install cloudbase-agent-core # Core framework
155pip install cloudbase-agent-server # FastAPI server
156pip install cloudbase-agent-langgraph # LangGraph integration
157pip install cloudbase-agent-tools # Tool system
158pip install cloudbase-agent-storage # Memory/Storage
159pip install cloudbase-agent-observability # OpenTelemetry/Langfuse
160pip install cloudbase-agent-coze # Coze platform
161pip install cloudbase-agent-crewai # CrewAI integration
162```
163
164**Import Note**: All packages share the `cloudbase_agent` namespace:
165```python
166# After installing cloudbase-agent-langgraph, import from cloudbase_agent
167from cloudbase_agent.langgraph import LangGraphAgent
168from cloudbase_agent.server import AgentServiceApp
169from cloudbase_agent.tools import create_bash_tool
170```
171
172## Reference Documents
173
174Based on what the user needs, read the corresponding reference document.
175**Only read the relevant reference — don't load all of them.**
176
177| User Need | Reference | What It Covers |
178|-----------|-----------|---------------|
179| **Deploying agent to CloudBase** | Read [agent-deployment](agent-deployment.md) | **manageAgent MCP tool (MUST USE)**, 4-step blocking pipeline, Python 3.10, env/ build, verification |
180| Server setup, deployment, middleware, multi-agent, CORS | Read `references/server.md` | AgentServiceApp 3 deployment methods, middleware (generator/yield/onion model), multi-agent server, Agent Creator pattern, health checks |
181| LangGraph agent, callbacks, tool proxy, HITL, checkpoints | Read `references/langgraph.md` | LangGraphAgent constructor, AgentCallback protocol, ToolProxy, human-in-the-loop with interrupt(), TDAICheckpointSaver, client-defined tools |
182| Tools: bash, filesystem, code execution, MCP, custom tools | Read `references/tools.md` | create_bash_tool, 8 file tools, code executors, MCPToolkit/CloudBaseMCPServer, @tool decorator, BaseTool, framework adapters |
183| Memory, persistence, short/long-term, MySQL, MongoDB | Read `references/storage.md` | InMemoryMemory, TDAIMemory, MySQLMemory, MongoDBMemory, TDAILongTermMemory, Mem0LongTermMemory, LangGraph checkpoint |
184| Tracing, monitoring, Langfuse, OpenTelemetry | Read `references/observability.md` | ConsoleTraceConfig, OTLPTraceConfig, setup_observability, env vars, manual observation spans |
185| Common patterns, JWT auth, MCP integration, production | Read `references/recipes.md` | JWT middleware, MCP + LangGraph, production deployment, adding tools to agents, client-defined tools |
186
187## Key Imports Quick Reference
188
189```python
190# Server
191from cloudbase_agent.server import AgentServiceApp, AgentCreatorResult
192from cloudbase_agent.server import create_send_message_adapter, create_openai_adapter
193from cloudbase_agent.server import RunAgentInput, OpenAIChatCompletionRequest
194
195# Agents
196from cloudbase_agent.langgraph import LangGraphAgent
197from cloudbase_agent.crewai import CrewAIAgent
198
199# Tools
200from cloudbase_agent.tools import create_bash_tool, create_read_tool, create_write_tool
201from cloudbase_agent.tools import MCPToolkit, CloudBaseMCPServer, CloudBaseTool
202from cloudbase_agent.tools import tool, BaseTool # custom tools
203
204# Storage
205from cloudbase_agent.storage import InMemoryMemory, TDAIMemory
206from cloudbase_agent.storage import TDAILongTermMemory, Mem0LongTermMemory
207from cloudbase_agent.langgraph import TDAICheckpointSaver, TDAIStore
208
209# Observability
210from cloudbase_agent.observability import ConsoleTraceConfig, OTLPTraceConfig, setup_observability
211
212# Schemas
213from cloudbase_agent.schemas import Message, MessageRole, StreamEvent, EventType
214```
215
216## Project Structure Convention
217
218```
219my-agent-project/
220├── agents/
221│ ├── agentic_chat/agent.py # build_workflow() → agent instance
222│ ├── human_in_the_loop/agent.py
223│ └── __init__.py
224├── server.py # Main entry: AgentServiceApp().run(...)
225├── scf_bootstrap # CloudBase startup script (required for deployment)
226├── .env # OPENAI_API_KEY, etc.
227└── requirements.txt
228```
229
230## Environment Variables
231
232| Variable | Purpose |
233|----------|---------|
234| `OPENAI_API_KEY` | OpenAI API key |
235| `AUTO_TRACES_STDOUT` | Enable console tracing (`true`) |
236| `LANGFUSE_PUBLIC_KEY` / `LANGFUSE_SECRET_KEY` | Langfuse keys |
237| `TDAI_ENDPOINT` / `TDAI_API_KEY` | TDAI memory/checkpoint endpoint |
238| `SCF_RUNTIME_PORT` | CloudBase runtime port (set automatically during deployment) |
239
240## Key Design Decisions
241
2421. **Agent Creator Pattern**: Every request creates a fresh agent via factory function. Supports cleanup callbacks for resource release.
2432. **Dual Protocol**: Every agent supports both AG-UI native (SSE + rich events) and OpenAI-compatible (`/chat/completions`).
2443. **Middleware = Generator**: Use `yield` — pre-yield = pre-processing, post-yield = post-processing (onion model).
2454. **Namespace Package**: `cloudbase_agent` spans multiple PyPI packages (cloudbase-agent-core, cloudbase-agent-server, cloudbase-agent-langgraph, etc.). PyPI names use hyphens, but all imports use `from cloudbase_agent.xxx import ...`.
2465. **Observability Auto-Integration**: Install `cloudbase-agent-observability` and tracing works automatically — zero config needed.
2476. **Deploy with manageAgent**: Always use the `manageAgent` MCP tool for CloudBase deployment. Follow the **4-step blocking pipeline** in [agent-deployment](agent-deployment.md).