Files
agent_management/scripts/demo_multi_tenant.sh
zhanggangyong 4b09912806 feat: 添加动态 Agent 生成器和 CI/CD 集成
主要更新:
- 新增 agent_code_generator.py: AI 驱动的 Pydantic Agent 代码生成
- 新增 gitee_manager.py: Gitee API 集成(仓库创建、文件推送、Secrets 配置)
- 新增 tool_generator_api.py: 动态 Agent 生成 API 端点
- 新增 template_manager.py: 数据库驱动的模板管理
- 新增 docs/DYNAMIC_AGENT_GENERATOR_API.md: 完整 API 文档

功能特性:
- 支持通过 API 定义工具并自动生成 Agent 代码
- 自动创建 Gitee 仓库并推送代码
- CI/CD 自动构建 ARM64 Docker 镜像并推送到 ACR
- 自动部署到 AKS 并创建 DNS A 记录
- 支持参数化工具函数生成

配置集成:
- LiteLLM Gateway 用于 AI 代码生成
- Gitea Actions 用于 CI/CD 流水线
- Azure DNS 用于域名绑定
- ACR/AKS 用于容器化部署

文件整理:
- 脚本文件移动到 scripts/ 目录
- 文档文件移动到 docs/ 目录
2026-01-27 13:17:35 +00:00

157 lines
4.5 KiB
Bash
Executable File

#!/bin/bash
# 多租户 Agent 管理演示脚本
set -e
API_URL="http://localhost:8000"
NAMESPACE="ai-agents"
echo "========================================="
echo "多租户 Agent 管理系统演示"
echo "========================================="
echo
# 颜色定义
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# 1. 创建不同用户的 Agents
echo -e "${BLUE}步骤 1: 创建不同用户的 Agents${NC}"
echo "-----------------------------------"
users=("user001" "user002" "user003")
templates=("echo_agent" "chat_agent" "code_agent")
for i in "${!users[@]}"; do
user="${users[$i]}"
template="${templates[$i]}"
agent_name="${user}-${template//_/-}"
echo -e "\n${YELLOW}创建 Agent: $agent_name (用户: $user)${NC}"
# 删除已存在的 agent
kubectl delete pod "$agent_name" -n "$NAMESPACE" 2>/dev/null || true
sleep 1
# 创建新的 agent
response=$(curl -s -X POST "$API_URL/agents" \
-H "Content-Type: application/json" \
-d "{
\"name\": \"$agent_name\",
\"template\": \"$template\",
\"config\": {
\"user_id\": \"$user\"
}
}")
pod_id=$(echo "$response" | jq -r '.pod_id')
user_id=$(echo "$response" | jq -r '.owner_info.user_id')
if [ "$pod_id" != "null" ]; then
echo -e "${GREEN}✓ 创建成功${NC}"
echo " Pod ID: $pod_id"
echo " User ID: $user_id"
else
echo -e "${RED}✗ 创建失败${NC}"
echo "$response" | jq .
fi
done
echo
echo "等待 Pods 启动..."
sleep 3
# 2. 查看所有 Agents
echo
echo -e "${BLUE}步骤 2: 查看所有 Agents${NC}"
echo "-----------------------------------"
kubectl get pods -n "$NAMESPACE" -l managed-by=agent-manager \
-o custom-columns=NAME:.metadata.name,POD_ID:.metadata.uid,USER:.metadata.labels.user-id,STATUS:.status.phase
# 3. 按用户查询
echo
echo -e "${BLUE}步骤 3: 按用户查询 Agents${NC}"
echo "-----------------------------------"
for user in "${users[@]}"; do
echo
echo -e "${YELLOW}用户: $user${NC}"
pods=$(kubectl get pods -n "$NAMESPACE" -l user-id="$user" \
-o custom-columns=NAME:.metadata.name,POD_ID:.metadata.uid,STATUS:.status.phase --no-headers)
if [ -n "$pods" ]; then
echo "$pods"
pod_count=$(echo "$pods" | wc -l)
echo -e "${GREEN}共 $pod_count 个 Agent${NC}"
else
echo "无 Agents"
fi
done
# 4. 验证 Pod ID 查询
echo
echo -e "${BLUE}步骤 4: 通过 Pod ID 验证归属${NC}"
echo "-----------------------------------"
# 获取第一个 agent
first_agent="${users[0]}-${templates[0]//_/-}"
pod_info=$(kubectl get pod "$first_agent" -n "$NAMESPACE" -o json 2>/dev/null)
if [ -n "$pod_info" ]; then
pod_id=$(echo "$pod_info" | jq -r '.metadata.uid')
user_id=$(echo "$pod_info" | jq -r '.metadata.labels["user-id"]')
echo "Agent: $first_agent"
echo "Pod ID: $pod_id"
echo "User ID: $user_id"
# 验证通过 UID 查询
echo
echo "验证: 通过 Pod ID 查询..."
kubectl get pods -n "$NAMESPACE" --all-namespaces \
-o json | jq -r ".items[] | select(.metadata.uid==\"$pod_id\") | .metadata.name"
fi
# 5. API 状态查询
echo
echo -e "${BLUE}步骤 5: 通过 API 查询 Agent 状态${NC}"
echo "-----------------------------------"
first_agent="${users[0]}-${templates[0]//_/-}"
echo "查询 Agent: $first_agent"
curl -s "$API_URL/agents/$first_agent/status" | jq '{name, status, pod_ip, node_name}'
# 6. 汇总统计
echo
echo -e "${BLUE}步骤 6: 统计信息${NC}"
echo "-----------------------------------"
total_agents=$(kubectl get pods -n "$NAMESPACE" -l managed-by=agent-manager --no-headers | wc -l)
running_agents=$(kubectl get pods -n "$NAMESPACE" -l managed-by=agent-manager \
--field-selector status.phase=Running --no-headers | wc -l)
echo "总 Agents 数: $total_agents"
echo "运行中: $running_agents"
echo
# 按模板统计
echo "按模板统计:"
for template in "${templates[@]}"; do
count=$(kubectl get pods -n "$NAMESPACE" -l template="$template" --no-headers 2>/dev/null | wc -l)
echo " $template: $count"
done
echo
echo "按用户统计:"
for user in "${users[@]}"; do
count=$(kubectl get pods -n "$NAMESPACE" -l user-id="$user" --no-headers 2>/dev/null | wc -l)
echo " $user: $count"
done
echo
echo -e "${GREEN}========================================="
echo "演示完成!"
echo "=========================================${NC}"