Files
Genarrative/server-rs/crates/agent-runtime-core/src/completion.rs
T
AIGameCreator App d4075c3423
Project CI / Frontend tests (push) Failing after 3m43s
Project CI / Native shell tests (push) Failing after 3m36s
Project CI / Repository checks (push) Failing after 4m36s
Project CI / Backend tests (push) Successful in 8m36s
抽取通用多智能体运行时与可扩展Provider
新增纯 Rust agent-runtime-core,提供运行时契约、能力注册、Agent 目录、Profile、完成策略与零重放恢复
抽取中立 LLM Provider 协议与可扩展 Registry,并适配 OpenAI Responses、OpenAI Chat 和 Anthropic
将 AGC interaction、Provider 控制、Runner 生命周期、steering 与 tool-plan handoff 接入统一运行时边界
补充非游戏消费者、Provider 网络闭环、Runtime 恢复及 GUI Runner owner 测试
同步 Cargo/npm 门禁、Runtime 技术方案和项目共享记忆
2026-07-30 16:15:51 +08:00

80 lines
2.0 KiB
Rust

use crate::contract::{ContractError, validate_description, validate_identifier};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CompletionBlocker {
code: String,
summary: String,
}
impl CompletionBlocker {
pub fn try_new(
code: impl Into<String>,
summary: impl Into<String>,
) -> Result<Self, ContractError> {
let code = code.into();
let summary = summary.into();
validate_identifier(&code, "completion blocker code")?;
validate_description(&summary, "completion blocker summary")?;
Ok(Self { code, summary })
}
pub fn code(&self) -> &str {
&self.code
}
pub fn summary(&self) -> &str {
&self.summary
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
enum CompletionDecisionState {
Ready,
Blocked(Vec<CompletionBlocker>),
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CompletionDecision {
state: CompletionDecisionState,
}
impl CompletionDecision {
pub fn ready() -> Self {
Self {
state: CompletionDecisionState::Ready,
}
}
pub fn blocked(
blockers: impl IntoIterator<Item = CompletionBlocker>,
) -> Result<Self, ContractError> {
let blockers = blockers.into_iter().collect::<Vec<_>>();
if blockers.is_empty() {
return Err(ContractError::new(
crate::ContractErrorKind::InvalidDefinition,
"blocked completion decision 至少需要一个 blocker",
));
}
Ok(Self {
state: CompletionDecisionState::Blocked(blockers),
})
}
pub fn is_ready(&self) -> bool {
matches!(self.state, CompletionDecisionState::Ready)
}
pub fn blockers(&self) -> &[CompletionBlocker] {
match &self.state {
CompletionDecisionState::Ready => &[],
CompletionDecisionState::Blocked(blockers) => blockers,
}
}
}
pub trait CompletionPolicy<Context> {
fn id(&self) -> &str;
fn evaluate(&self, context: &Context) -> CompletionDecision;
}