Files
Genarrative/server-rs/crates/agent-runtime-orchestration/src/plan.rs
T
kdletters d2254d1e8c
Project CI / Repository checks (push) Successful in 2m16s
Project CI / Frontend tests (push) Successful in 6m37s
Project CI / Backend tests (push) Failing after 7m45s
Project CI / Native shell tests (push) Failing after 7m6s
抽取多 Agent 编排 crate 并支持运行中自主扩图 (#207)
## 概要

- 抽取通用 `agent-runtime-orchestration` crate,承接多 Agent DAG 的构图校验、ready/wave、下游闭包和全量/返工选择。
- 保留 `platform-agent` 的游戏领域任务与语义路由,避免把 Runtime、Provider、ToolHost 和持久化职责下沉到公共编排层。
- 增加 `GraphProposal` / `TaskProposal` / `GraphEdge` / `GraphLimits`,允许宿主在执行中安全应用 LLM 提出的新增节点和边。
- 扩图采用候选图原子校验:未知 Agent/端点、重复边、自依赖、环及节点/边/深度/扇出预算都会拒绝,失败时原图保持不变;新增节点默认为 `Pending`。

## 验证

- `npm run agent-runtime-orchestration:check`(15 项通过)
- `cargo test --manifest-path server-rs/crates/platform-agent/Cargo.toml`(19 项通过)
- `npm run agc:skill-pack:check`
- `npm run check:encoding`
- `git diff --check`

前端 typecheck 本轮未执行:当前工作树未安装 `node_modules/tsc`,命令会报 `tsc is not recognized`。

Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/207
2026-08-31 10:51:11 +08:00

65 lines
1.9 KiB
Rust

use serde::{Deserialize, Serialize};
use crate::{OrchestrationError, OrchestrationErrorKind, TaskGraph};
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum PlanSelection {
All,
Repair { task_ids: Vec<String> },
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OrchestrationPlan {
active_task_ids: Vec<String>,
carried_task_ids: Vec<String>,
dependency_waves: Vec<Vec<String>>,
}
impl OrchestrationPlan {
pub fn active_task_ids(&self) -> &[String] {
&self.active_task_ids
}
pub fn carried_task_ids(&self) -> &[String] {
&self.carried_task_ids
}
pub fn dependency_waves(&self) -> &[Vec<String>] {
&self.dependency_waves
}
}
impl TaskGraph {
pub fn plan(&self, selection: PlanSelection) -> Result<OrchestrationPlan, OrchestrationError> {
let all_task_ids = self.all_task_ids();
let active_task_ids = match selection {
PlanSelection::All => all_task_ids.clone(),
PlanSelection::Repair { task_ids } => {
if task_ids.is_empty() {
return Err(OrchestrationError::new(
OrchestrationErrorKind::InvalidInput,
"repair selection 至少需要一个 task",
));
}
self.expand_downstream(&task_ids)?
}
};
let active = active_task_ids
.iter()
.map(String::as_str)
.collect::<std::collections::HashSet<_>>();
let carried_task_ids = all_task_ids
.into_iter()
.filter(|task_id| !active.contains(task_id.as_str()))
.collect::<Vec<_>>();
let dependency_waves = self.dependency_waves(&active_task_ids, &carried_task_ids)?;
Ok(OrchestrationPlan {
active_task_ids,
carried_task_ids,
dependency_waves,
})
}
}