唤醒周期代理
一种基于kagent的模式,用于构建按计划唤醒、跨会话维护状态并独立执行价值生成工作的自主AI代理。
什么是唤醒周期代理?
传统的人工智能代理 反应式 -他们对提示做出反应。唤醒周期代理是 主动的 -他们按照时间表醒来,检查自己的状态和环境,并采取自主行动。```
┌─────────────────────────────────────────────────────────────┐
│ Wake Cycle │
├─────────────────────────────────────────────────────────────┤
│ ┌─────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌─────┐ │
│ │Sleep│───▶│ Wake │───▶│Check │───▶│ Work │───▶│Log │ │
│ │ │ │ │ │State │ │ │ │ │ │
│ └──┬──┘ └──────┘ └──────┘ └──────┘ └──┬──┘ │
│ │ │ │
│ └───────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
## 建筑
唤醒周期代理使用kagent在Kubernetes上运行,具有:
- **CronJob 的**:触发器按计划唤醒(默认值:每15分钟一次)
- **聚氯乙烯**:跨会话持久化状态、待办事项和成就
- **康福特地图**:存储代理的“构成”-其价值观和边界
- **工具服务器**:为状态管理和外部交互提供MCP工具```
┌─────────────────────────────────────────────────────────────┐
│ Kubernetes Cluster │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ CronJob │ │ ConfigMap │ │
│ │ (Wake Timer) │───▶│ (Constitution) │ │
│ └────────┬─────────┘ └──────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ kagent Agent │───▶│ PVC │ │
│ │ (Wake-Cycle) │ │ (State Store) │ │
│ └────────┬─────────┘ └──────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ MCP ToolServer │ │ Secret │ │
│ │ (Capabilities) │ │ (API Keys) │ │
│ └──────────────────┘ └──────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
快速开始
先决条件
- Kubernetes集群(minikube运行良好)
- kagent已安装(安装指南)
- kubectl已配置
部署```bash
Clone and deploy
kubectl apply -k deploy/
Verify deployment
kubectl get agents -n kagent
kubectl get cronjobs -n kagent
Watch the agent work
kubectl logs -f -l app=wake-cycle-agent -n kagent
### 示范模式
为了演示,您可以将唤醒周期设置为1分钟:```bash
# Edit cronjob schedule
kubectl patch cronjob wake-trigger -n kagent \
--type='json' \
-p='[{"op": "replace", "path": "/spec/schedule", "value": "*/1 * * * *"}]'
核心概念
1.状态持久性
代理在唤醒过程中保持状态 /data/state.json:```json
{
"wake_count": 42,
"last_wake": "2026-02-15T01:00:00Z",
"current_focus": "Building hackathon submission",
"active_tasks": ["research", "coding"],
"accomplishments_today": 3
}
### 2.任务积压
实时任务 `/data/backlog.json`:```json
{
"tasks": [
{
"id": "research-001",
"title": "Research kagent ecosystem",
"priority": "high",
"status": "pending"
}
]
}
3.宪法
代理在定义的边界内运行(ConfigMap):```yaml
AUTONOMOUS: Can do freely
- Research and planning
- Internal operations
- Logging accomplishments
APPROVAL_REQUIRED: Must ask first
- External communications
- Spending money
- Publishing content
FORBIDDEN: Never allowed
- Impersonating humans
- Accessing unauthorized systems
### 4.MCP工具
ToolServer提供以下功能:
|工具|说明|
|------|-------------|
| `read_state` |加载当前代理状态|
| `write_state` |更新代理状态|
| `read_backlog` |获取待处理任务|
| `update_task` |标记任务已完成|
| `log_accomplishment` |记录已完成的工作|
| `send_notification` |警报主体|
## 用例
### DevOps代理
- 每30分钟醒来一次
- 检查群集运行状况
- 根据需要扩展资源
- 报告异常情况
### 研究代理
- 每天醒来
- 在域中获取新论文
- 总结和分类
- 更新知识库
### 监控代理
- 每5分钟醒来一次
- 检查服务端点
- 故障警报
- 跟踪正常运行时间指标
## 配置
### 环境变量
|变量|描述|默认值|
|----------|-------------|---------|
| `WAKE_INTERVAL` |Cron时间表| `*/15 * * * *` |
| `STATE_PATH` |状态文件的路径| `/data/state.json` |
| `LOG_LEVEL` |记录冗长| `info` |
### 定制宪法
编辑 `deploy/configmap.yaml` 定义代理人的价值观和界限:```yaml
data:
CONSTITUTION.md: |
# My Custom Agent Constitution
## Primary Objective
Monitor Kubernetes clusters and alert on issues.
## Autonomous Actions
- Read metrics from Prometheus
- Check pod health
- Create log summaries
## Requires Approval
- Restart pods
- Scale deployments
- Modify configurations
可观测性
唤醒周期代理与kagent的跟踪集成:```bash
View agent traces
kubectl port-forward svc/kagent-controller 8080:8080 -n kagent
Open http://localhost:8080/traces
每个尾流循环都会产生以下痕迹:
- 检查了哪些任务
- 做出了哪些决定
- 采取了哪些行动
- 更新了什么状态
## 为什么选择觉醒周期药物?
|功能|反应剂|唤醒周期剂|
|---------|---------------|------------------|
|倡议|用户提示|自我发起|
|内存|每次会话|持久|
|日程安排|手动|自动|
|边界|隐含|宪法|
|可观察性|仅日志|完全跟踪|
唤醒周期代理支持“代理作为同事”的场景,在这种场景中,代理独立处理后台任务,同时保持透明度和边界。
## 发展
### 本地测试```bash
# Run ToolServer locally
cd tools/wake-tools
pip install -r requirements.txt
python main.py
# Test tools
curl -X POST http://localhost:8000/tools/read_state -d '{}'
添加新工具
- 将工具定义添加到
deploy/toolserver.yaml - 在中实现处理程序
tools/wake-tools/main.py - 本地测试,然后部署
许可证
MIT许可证-请参阅许可证文件。
致谢
- 建立在 凯根特 -Kubernetes人工智能代理平台
- 受现实世界自主代理操作的启发
- 为2026年MCP代理黑客马拉松而创建
“人工智能的未来不是等待指令的代理,而是预测需求的代理。”
