84926ee0cd
由 Prompt Bundle manifest 统一驱动 section、composition、变体和 role overlay 由构建脚本生成 Supervisor 与六组专业 Agent 的静态节点目录 构建期失败关闭校验路径、引用、selector、alias 与 seed DAG 一致性 补充平台、Editor、Provider 请求、节点快照和非法 manifest 回归 同步 Runtime 技术方案与项目决策记录
137 lines
5.3 KiB
Rust
137 lines
5.3 KiB
Rust
use super::*;
|
|
use agent_runtime_core::{AgentCatalog, AgentDescriptor, RunProfileCatalog, RunProfileDefinition};
|
|
|
|
fn build_game_creator_runtime_agent_catalog() -> Result<AgentCatalog, String> {
|
|
let mut agents = vec![AgentDescriptor::try_new(
|
|
GAME_CREATOR_PROJECT_SUPERVISOR_AGENT_ID,
|
|
PROJECT_SUPERVISOR_AGENT_DEFINITION.id,
|
|
std::iter::empty::<&str>(),
|
|
)
|
|
.and_then(|agent| {
|
|
agent.with_metadata(serde_json::json!({
|
|
"groupId": PROJECT_SUPERVISOR_AGENT_DEFINITION.id,
|
|
"roleLabel": PROJECT_SUPERVISOR_AGENT_ROLES[0].role,
|
|
"toolId": PROJECT_SUPERVISOR_AGENT_ROLES[0].tool_id,
|
|
"capabilityAuthority": "game-creator-tool-policy-snapshot"
|
|
}))
|
|
})
|
|
.map_err(|error| format!("AI 游戏创作 Agent catalog 无效:{error}"))?];
|
|
for group in GAME_CREATOR_AGENT_GROUP_DEFINITIONS {
|
|
for role in group.roles {
|
|
agents.push(
|
|
AgentDescriptor::try_new(role.task_id, role.id, std::iter::empty::<&str>())
|
|
.and_then(|agent| {
|
|
agent.with_metadata(serde_json::json!({
|
|
"groupId": group.id,
|
|
"groupLabel": group.label,
|
|
"roleLabel": role.role,
|
|
"toolId": role.tool_id,
|
|
"capabilityAuthority": "game-creator-tool-policy-snapshot"
|
|
}))
|
|
})
|
|
.map_err(|error| format!("AI 游戏创作 Agent catalog 无效:{error}"))?,
|
|
);
|
|
}
|
|
}
|
|
AgentCatalog::try_new(agents)
|
|
.map_err(|error| format!("AI 游戏创作 Agent catalog 无效:{error}"))
|
|
}
|
|
|
|
pub(crate) fn game_creator_runtime_agent_catalog() -> Result<&'static AgentCatalog, String> {
|
|
static CATALOG: OnceLock<Result<AgentCatalog, String>> = OnceLock::new();
|
|
CATALOG
|
|
.get_or_init(build_game_creator_runtime_agent_catalog)
|
|
.as_ref()
|
|
.map_err(Clone::clone)
|
|
}
|
|
|
|
fn build_game_creator_runtime_run_profile_catalog() -> Result<RunProfileCatalog, String> {
|
|
let standard = RunProfileDefinition::try_new(
|
|
AGENT_RUNTIME_RUN_PROFILE_STANDARD,
|
|
std::iter::empty::<&str>(),
|
|
"game-creator-standard-completion",
|
|
)
|
|
.and_then(|profile| {
|
|
profile.with_metadata(serde_json::json!({
|
|
"capabilityAuthority": "game-creator-tool-policy-snapshot",
|
|
"completionAuthority": "game-creator-runtime-finalization"
|
|
}))
|
|
})
|
|
.map_err(|error| format!("AI 游戏创作 Run Profile catalog 无效:{error}"))?;
|
|
let autonomous = RunProfileDefinition::try_new(
|
|
AGENT_RUNTIME_RUN_PROFILE_AUTONOMOUS_GAME_BUILD,
|
|
std::iter::empty::<&str>(),
|
|
"game-creator-autonomous-completion",
|
|
)
|
|
.and_then(|profile| {
|
|
profile.with_metadata(serde_json::json!({
|
|
"rootAgentId": GAME_CREATOR_PROJECT_SUPERVISOR_AGENT_ID,
|
|
"capabilityAuthority": "game-creator-tool-policy-snapshot",
|
|
"completionAuthority": AGENT_RUNTIME_AUTONOMOUS_COMPLETION_CONTRACT_SCHEMA_VERSION
|
|
}))
|
|
})
|
|
.map_err(|error| format!("AI 游戏创作 Run Profile catalog 无效:{error}"))?;
|
|
RunProfileCatalog::try_new([standard, autonomous])
|
|
.map_err(|error| format!("AI 游戏创作 Run Profile catalog 无效:{error}"))
|
|
}
|
|
|
|
pub(crate) fn game_creator_runtime_run_profile_catalog(
|
|
) -> Result<&'static RunProfileCatalog, String> {
|
|
static CATALOG: OnceLock<Result<RunProfileCatalog, String>> = OnceLock::new();
|
|
CATALOG
|
|
.get_or_init(build_game_creator_runtime_run_profile_catalog)
|
|
.as_ref()
|
|
.map_err(Clone::clone)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn game_creator_runtime_agent_catalog_matches_the_existing_role_directory() {
|
|
let catalog = game_creator_runtime_agent_catalog().expect("agent catalog");
|
|
let mut expected =
|
|
std::collections::BTreeSet::from(
|
|
[GAME_CREATOR_PROJECT_SUPERVISOR_AGENT_ID.to_string()],
|
|
);
|
|
for group in GAME_CREATOR_AGENT_GROUP_DEFINITIONS {
|
|
expected.extend(group.roles.iter().map(|role| role.task_id.to_string()));
|
|
}
|
|
assert_eq!(
|
|
catalog
|
|
.iter()
|
|
.map(|agent| agent.id().to_string())
|
|
.collect::<std::collections::BTreeSet<_>>(),
|
|
expected
|
|
);
|
|
assert_eq!(
|
|
catalog
|
|
.get(GAME_CREATOR_PROJECT_SUPERVISOR_AGENT_ID)
|
|
.map(AgentDescriptor::role),
|
|
Some(PROJECT_SUPERVISOR_AGENT_DEFINITION.id)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn game_creator_runtime_run_profiles_are_adapter_registered() {
|
|
let profiles = game_creator_runtime_run_profile_catalog().expect("profile catalog");
|
|
assert_eq!(
|
|
profiles
|
|
.iter()
|
|
.map(|profile| profile.id())
|
|
.collect::<Vec<_>>(),
|
|
vec![
|
|
AGENT_RUNTIME_RUN_PROFILE_STANDARD,
|
|
AGENT_RUNTIME_RUN_PROFILE_AUTONOMOUS_GAME_BUILD
|
|
]
|
|
);
|
|
assert_eq!(
|
|
profiles
|
|
.get(AGENT_RUNTIME_RUN_PROFILE_AUTONOMOUS_GAME_BUILD)
|
|
.map(RunProfileDefinition::completion_policy_id),
|
|
Some("game-creator-autonomous-completion")
|
|
);
|
|
}
|
|
}
|