Update README
面向单机多 Agent 系统的 Linux 用户态运行时压力感知调度、资源隔离、上下文复用、事务输出与可验证依赖执行
CAPSuleRT 将 Agent 视为系统级执行实体,统一管理其生命周期、资源预算、上下文数据、任务依赖、进程执行、结果提交和运行状态。
项目运行在 Agent 应用与 Linux 操作系统之间。上层框架仍可使用 DAG、Graph 或其他方式描述业务流程;CAPSuleRT 负责将任务安全、稳定地落到本地进程和内核资源上。
Agent Application / Workflow Framework │ ▼ CAPSuleRT │ ┌───────────┼───────────┐ ▼ ▼ ▼ cgroup v2 PSI Local Filesystem
当前版本面向 openEuler/Linux 单机环境,核心能力包括:
CAPSuleRT 由两部分组成:
该名称对应项目的核心目标:在系统压力和上下文复用之间进行调度,同时为每个 Agent 提供独立、可验证的执行舱。
CAPSuleRT 解决的是多 Agent 执行过程中的系统问题,而不是替代业务编排框架。
CAPSuleRT 不限定 Agent 的实现方式。当前 Worker 以本地进程为执行单元,可运行 Python、Go 或其他可执行程序。
每个 Agent 由 Agent Control Block(ACB)描述。ACB 贯穿提交、调度、执行和结果发布全过程,保存:
执行生命周期:
CREATED → READY → RUNNING → COMPLETED └→ FAILED
调度状态:
QUEUED → RUNNING → SUCCEEDED ├→ FAILED └→ BLOCKED
CAPSuleRT 为每个 Agent 创建独立 cgroup,可配置:
memory.max
memory.swap.max
pids.max
Runtime 会收集:
Agent 超时或失败时,Runtime 使用 cgroup.kill 清理整个进程树,避免只终止父进程后遗留子进程。
cgroup.kill
Agent cgroup ├── main process ├── child process └── grandchild process
因此,每个 Agent 都是独立的资源与故障域。
CAPS 是 CAPSuleRT 的核心调度策略。它综合考虑:
简化后的评分形式:
score = pressure penalty - context affinity benefit - waiting age bonus
CAPS 的目标不是单纯追求最早提交优先,而是在当前机器状态下选择综合执行成本更低的 Ready Agent。
项目同时保留 FIFO Policy,便于进行行为对照和回归测试。
ContextFS 是 CAPSuleRT 的内容寻址上下文存储。
Logical Reference │ ▼ SHA-256 Digest │ ▼ Immutable Blob
主要能力:
目录结构:
contextfs/ ├── blobs/ │ └── sha256/ ├── metadata/ │ └── sha256/ ├── refs/ └── tmp/
不同逻辑名称只要解析到相同 Digest,就会共享同一个物理对象,并在 CAPS 调度中获得相同的上下文亲和收益。
ContextFS 中的不可变对象不会直接交给 Agent 修改。Runtime 会为每个 Agent 创建独立工作区:
workspace/ ├── inputs/ # 只读输入 ├── private/ # Agent 私有可写区域 └── manifest.json
物化过程:
FICLONE
该机制保证:
Agent 不直接写入最终结果目录,而是写入独立 staging:
Agent Process │ ▼ Private Staging │ ├── Process Failed → Discard / Retain ├── Validation Failed → Discard / Retain └── Validation Passed │ ▼ Atomic Rename │ ▼ Committed Output
提交前会检查:
提交成功后生成:
.aegis-commit.json
Manifest 记录:
最终结果目录通过同一文件系统上的原子 rename 发布,避免下游观察到半成品。
进程退出码为零并不代表任务结果已经可信。
CAPSuleRT 将任务成功定义为:
Process Succeeded + Output Committed + Manifest Verified + Artifact SHA-256 Verified
在下游消费结果前,Runtime 会重新验证:
验证成功后:
OutputVerified = true VerificationMethod = "sha256-manifest"
任务可以声明上游依赖:
scheduler.Job{ Agent: agentControlBlock, DependsOn: []string{ "producer-agent", }, }
下游 Agent 只有在所有上游任务满足以下条件后才会进入调度候选集合:
Phase == SUCCEEDED OutputCommitted == true OutputVerified == true
故障传播规则:
Upstream FAILED │ ▼ Downstream BLOCKED │ ▼ Deeper Dependents BLOCKED
BLOCKED Agent 不会创建:
CAPSuleRT 将运行时关键行为转换为统一事件:
runtime.agent.submitted runtime.pressure.sampled runtime.agent.dispatched runtime.agent.blocked runtime.output.committed runtime.output.verified runtime.output.verification_failed runtime.agent.finished
每个事件包含:
事件通过异步总线写入:
Runtime API 和 CLI 均以统一事件模型为查询基础。
flowchart TB Client["Agent Application / Workflow Framework"] CLI["capsulectl"] API["Runtime HTTP API"] Metrics["Prometheus Metrics"] EventBus["Unified Event Bus"] Scheduler["Concurrent Scheduler"] DAG["DAG Dependency Gate"] CAPS["CAPS Policy"] PSI["Linux PSI Reader"] Registry["Context Registry"] Workspace["Workspace Executor"] Output["Transactional Output Executor"] Runner["Process Runner"] ContextFS["ContextFS"] Cgroup["cgroup v2 Manager"] Process["Agent Process Tree"] Committed["Committed Output Store"] Client --> Scheduler CLI --> API API --> Scheduler API --> EventBus API --> Metrics Scheduler --> DAG Scheduler --> CAPS CAPS --> PSI CAPS --> Registry Registry --> ContextFS Scheduler --> Workspace Workspace --> ContextFS Workspace --> Output Output --> Runner Runner --> Cgroup Cgroup --> Process Output --> Committed Scheduler --> EventBus
完整执行路径:
Submit Job │ ▼ Resolve Context References │ ▼ Check DAG Dependencies │ ▼ Sample Linux PSI │ ▼ CAPS Selects a Ready Agent │ ▼ Prepare Isolated Workspace │ ▼ Begin Output Transaction │ ▼ Create and Attach cgroup │ ▼ Run Agent Process Tree │ ▼ Validate and Commit Output │ ▼ Verify Manifest and SHA-256 │ ▼ Publish Events and Unblock Dependents
. ├── cmd/ │ ├── aegisd/ # Runtime daemon 源码入口 │ ├── aegisctl/ # CLI 源码入口 │ ├── apidemo/ # Runtime API 综合演示 │ ├── eventdemo/ # 统一事件流演示 │ ├── integritydagdemo/ # DAG 与完整性验证演示 │ ├── transactiondemo/ # 事务输出演示 │ ├── workspaceexecdemo/ # 工作区执行演示 │ ├── contextbridgedemo/ # ContextFS 与调度器集成演示 │ ├── contextfsdemo/ # ContextFS 演示 │ ├── affinitydemo/ # 上下文亲和调度演示 │ ├── capsdemo/ # CAPS 与 FIFO 调度演示 │ ├── schedulerdemo/ # 并发调度演示 │ ├── cgroupdemo/ # cgroup 资源隔离演示 │ └── psidemo/ # PSI 读取演示 │ ├── internal/ │ ├── agent/ # Agent Control Block │ ├── scheduler/ # Scheduler、Policy、DAG │ ├── runtime/ # Runner 与执行器组合 │ ├── resource/ # cgroup v2 管理 │ ├── pressure/ # PSI 读取 │ ├── contextfs/ # 内容寻址存储与工作区 │ ├── contextstore/ # Context 解析和热度注册 │ ├── outputtxn/ # 事务输出与完整性验证 │ ├── telemetry/ # 统一事件总线 │ ├── controlapi/ # HTTP API 与 Prometheus │ └── controlclient/ # CLI HTTP Client │ ├── worker/ │ └── python/ # 示例 Agent 和故障注入程序 │ ├── deploy/ │ └── systemd/ # systemd 部署与演示单元 │ ├── Makefile ├── go.mod └── README.md
推荐环境:
无 cgroup 模式可用于本地功能验证;完整资源隔离需要 cgroup v2 和 systemd delegation。
go version python3 --version
检查 cgroup v2:
stat -fc %T /sys/fs/cgroup
预期输出:
cgroup2fs
检查 PSI:
cat /proc/pressure/cpu cat /proc/pressure/memory cat /proc/pressure/io
mkdir -p bin go build \ -o bin/capsulertd \ ./cmd/aegisd go build \ -o bin/capsulectl \ ./cmd/aegisctl go build \ -o bin/apidemo \ ./cmd/apidemo
构建全部命令:
go build ./cmd/...
gofmt -w internal cmd go test ./... go vet ./...
发布前完整检查:
go test -race ./... python3 -m py_compile worker/python/*.py
无 cgroup 模式:
./bin/apidemo \ -disable-cgroup \ -listen 127.0.0.1:18080
Runtime 默认仅监听 Loopback,不直接暴露到外部网络。
另开终端:
./bin/capsulectl health ./bin/capsulectl ready ./bin/capsulectl status ./bin/capsulectl agents ./bin/capsulectl events ./bin/capsulectl metrics
查看当前控制器:
cat /sys/fs/cgroup/cgroup.controllers
至少应包含:
cpu memory pids
内核启动参数可通过以下命令检查:
cat /proc/cmdline
目标环境需要启用:
cgroup_no_v1=all psi=1
systemd 服务需要委派相应控制器:
[Service] Delegate=cpu memory pids CPUAccounting=yes MemoryAccounting=yes TasksAccounting=yes
仓库 deploy/systemd/ 中包含各模块演示单元。部署前需要根据实际环境调整:
deploy/systemd/
User
Group
WorkingDirectory
ExecStart
go run ./cmd/psidemo
go run ./cmd/schedulerdemo
go run ./cmd/capsdemo
go run ./cmd/affinitydemo
go run ./cmd/contextfsdemo
go run ./cmd/contextbridgedemo -disable-cgroup
go run ./cmd/workspaceexecdemo -disable-cgroup
go run ./cmd/transactiondemo -disable-cgroup
go run ./cmd/integritydagdemo -disable-cgroup
go run ./cmd/eventdemo -disable-cgroup
go run ./cmd/apidemo \ -disable-cgroup \ -listen 127.0.0.1:18080
默认地址:
http://127.0.0.1:18080
GET /healthz
GET /readyz
以下状态会使 Runtime 返回不就绪:
GET /v1/runtime/status
GET /v1/agents
查询参数:
phase
QUEUED
RUNNING
SUCCEEDED
FAILED
BLOCKED
limit
示例:
curl -sS \ 'http://127.0.0.1:18080/v1/agents?phase=FAILED&limit=100'
GET /v1/agents/{id}
GET /v1/events
since
kind
agent_id
curl -sS \ 'http://127.0.0.1:18080/v1/events?since=10&limit=100'
安装:
sudo install \ -o root \ -g root \ -m 0755 \ bin/capsulectl \ /usr/local/bin/capsulectl
常用命令:
capsulectl health capsulectl ready capsulectl status capsulectl agents capsulectl agents -phase FAILED capsulectl agents -phase BLOCKED capsulectl agent <agent-id> capsulectl events -since 10 capsulectl watch capsulectl metrics
指定 Runtime 地址:
export CAPSULERT_SERVER=http://127.0.0.1:18080 capsulectl status
或者:
capsulectl \ -server http://127.0.0.1:18080 \ status
接口:
GET /metrics
主要指标:
capsulert_up
capsulert_ready
capsulert_runtime_uptime_seconds
capsulert_scheduler_started
capsulert_scheduler_stopped
capsulert_scheduler_workers
capsulert_scheduler_queue_depth
capsulert_scheduler_queue_capacity
capsulert_scheduler_agents{phase=...}
capsulert_event_bus_published_total
capsulert_event_bus_delivered_total
capsulert_event_bus_sink_errors_total
capsulert_event_bus_queue_depth
capsulert_event_sequence
查询:
curl -sS http://127.0.0.1:18080/metrics
Prometheus 配置示例:
scrape_configs: - job_name: capsulert static_configs: - targets: - 127.0.0.1:18080
CAPSuleRT 当前实现遵循以下约束:
当前版本聚焦单机多 Agent 执行,尚未覆盖:
这些能力不影响当前单机 Runtime 的完整执行闭环。
仓库中的测试和演示覆盖:
完整回归命令:
gofmt -w internal cmd go test ./... go test -race ./... go vet ./... go build ./cmd/... python3 -m py_compile worker/python/*.py
CAPSuleRT 当前已经形成以下完整闭环:
Agent Submission + DAG Dependency Gate + PSI and Context-aware Scheduling + cgroup Fault Domain + ContextFS Workspace + Transactional Output + SHA-256 Verification + Failure Propagation + Unified Observability
CAPSuleRT — Context-aware scheduling inside a verified Agent execution capsule.
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802047560号
CAPSuleRT
CAPSuleRT 将 Agent 视为系统级执行实体,统一管理其生命周期、资源预算、上下文数据、任务依赖、进程执行、结果提交和运行状态。
项目运行在 Agent 应用与 Linux 操作系统之间。上层框架仍可使用 DAG、Graph 或其他方式描述业务流程;CAPSuleRT 负责将任务安全、稳定地落到本地进程和内核资源上。
当前版本面向 openEuler/Linux 单机环境,核心能力包括:
名称含义
CAPSuleRT 由两部分组成:
该名称对应项目的核心目标:在系统压力和上下文复用之间进行调度,同时为每个 Agent 提供独立、可验证的执行舱。
项目定位
CAPSuleRT 解决的是多 Agent 执行过程中的系统问题,而不是替代业务编排框架。
CAPSuleRT 不限定 Agent 的实现方式。当前 Worker 以本地进程为执行单元,可运行 Python、Go 或其他可执行程序。
核心能力
Agent Control Block
每个 Agent 由 Agent Control Block(ACB)描述。ACB 贯穿提交、调度、执行和结果发布全过程,保存:
执行生命周期:
调度状态:
cgroup v2 资源隔离
CAPSuleRT 为每个 Agent 创建独立 cgroup,可配置:
memory.max;memory.swap.max;pids.max。Runtime 会收集:
Agent 超时或失败时,Runtime 使用
cgroup.kill清理整个进程树,避免只终止父进程后遗留子进程。因此,每个 Agent 都是独立的资源与故障域。
CAPS 调度策略
CAPS 是 CAPSuleRT 的核心调度策略。它综合考虑:
简化后的评分形式:
CAPS 的目标不是单纯追求最早提交优先,而是在当前机器状态下选择综合执行成本更低的 Ready Agent。
项目同时保留 FIFO Policy,便于进行行为对照和回归测试。
ContextFS
ContextFS 是 CAPSuleRT 的内容寻址上下文存储。
主要能力:
目录结构:
不同逻辑名称只要解析到相同 Digest,就会共享同一个物理对象,并在 CAPS 调度中获得相同的上下文亲和收益。
Agent 工作区
ContextFS 中的不可变对象不会直接交给 Agent 修改。Runtime 会为每个 Agent 创建独立工作区:
物化过程:
FICLONEreflink;该机制保证:
事务化输出
Agent 不直接写入最终结果目录,而是写入独立 staging:
提交前会检查:
提交成功后生成:
Manifest 记录:
最终结果目录通过同一文件系统上的原子 rename 发布,避免下游观察到半成品。
输出完整性验证
进程退出码为零并不代表任务结果已经可信。
CAPSuleRT 将任务成功定义为:
在下游消费结果前,Runtime 会重新验证:
验证成功后:
DAG 依赖与失败传播
任务可以声明上游依赖:
下游 Agent 只有在所有上游任务满足以下条件后才会进入调度候选集合:
故障传播规则:
BLOCKED Agent 不会创建:
统一事件流
CAPSuleRT 将运行时关键行为转换为统一事件:
每个事件包含:
事件通过异步总线写入:
Runtime API 和 CLI 均以统一事件模型为查询基础。
系统架构
flowchart TB Client["Agent Application / Workflow Framework"] CLI["capsulectl"] API["Runtime HTTP API"] Metrics["Prometheus Metrics"] EventBus["Unified Event Bus"] Scheduler["Concurrent Scheduler"] DAG["DAG Dependency Gate"] CAPS["CAPS Policy"] PSI["Linux PSI Reader"] Registry["Context Registry"] Workspace["Workspace Executor"] Output["Transactional Output Executor"] Runner["Process Runner"] ContextFS["ContextFS"] Cgroup["cgroup v2 Manager"] Process["Agent Process Tree"] Committed["Committed Output Store"] Client --> Scheduler CLI --> API API --> Scheduler API --> EventBus API --> Metrics Scheduler --> DAG Scheduler --> CAPS CAPS --> PSI CAPS --> Registry Registry --> ContextFS Scheduler --> Workspace Workspace --> ContextFS Workspace --> Output Output --> Runner Runner --> Cgroup Cgroup --> Process Output --> Committed Scheduler --> EventBus完整执行路径:
项目结构
运行环境
推荐环境:
无 cgroup 模式可用于本地功能验证;完整资源隔离需要 cgroup v2 和 systemd delegation。
快速开始
1. 检查环境
检查 cgroup v2:
预期输出:
检查 PSI:
2. 构建
构建全部命令:
3. 运行测试
发布前完整检查:
4. 启动本地 Runtime API
无 cgroup 模式:
Runtime 默认仅监听 Loopback,不直接暴露到外部网络。
5. 查询 Runtime
另开终端:
cgroup v2 配置
查看当前控制器:
至少应包含:
内核启动参数可通过以下命令检查:
目标环境需要启用:
systemd 服务需要委派相应控制器:
仓库
deploy/systemd/中包含各模块演示单元。部署前需要根据实际环境调整:User;Group;WorkingDirectory;ExecStart;运行演示
PSI 读取
并发 Scheduler
CAPS 调度
Context Affinity
ContextFS
ContextFS 与 Scheduler 集成
隔离工作区
事务输出
DAG 与输出完整性
统一事件流
HTTP API 综合演示
Runtime HTTP API
默认地址:
健康检查
就绪检查
以下状态会使 Runtime 返回不就绪:
Runtime 状态
Agent 列表
查询参数:
phaseQUEUED、RUNNING、SUCCEEDED、FAILED或BLOCKEDlimit示例:
单个 Agent
事件查询
查询参数:
sincelimitkindagent_idphase示例:
capsulectl
安装:
常用命令:
指定 Runtime 地址:
或者:
Prometheus 指标
接口:
主要指标:
capsulert_upcapsulert_readycapsulert_runtime_uptime_secondscapsulert_scheduler_startedcapsulert_scheduler_stoppedcapsulert_scheduler_workerscapsulert_scheduler_queue_depthcapsulert_scheduler_queue_capacitycapsulert_scheduler_agents{phase=...}capsulert_event_bus_published_totalcapsulert_event_bus_delivered_totalcapsulert_event_bus_sink_errors_totalcapsulert_event_bus_queue_depthcapsulert_event_sequence查询:
Prometheus 配置示例:
设计约束
CAPSuleRT 当前实现遵循以下约束:
项目边界
当前版本聚焦单机多 Agent 执行,尚未覆盖:
这些能力不影响当前单机 Runtime 的完整执行闭环。
验证范围
仓库中的测试和演示覆盖:
完整回归命令:
运行时闭环
CAPSuleRT 当前已经形成以下完整闭环:
CAPSuleRT — Context-aware scheduling inside a verified Agent execution capsule.