新增: spawn_agent 子代理派发与级联取消
- 纯内存子会话隔离上下文,一轮回传结论报告 - 白名单钳制低风险并恒剔 spawn_agent 防递归 - 子代理策略下高风险自动拒绝,不挂审批防卡死 - 轮数令牌挂钟三重熔断 - 父停止与删会话级联取消子代理 - AiAgentFinished 事件挂父会话
This commit is contained in:
@@ -133,6 +133,18 @@ impl LlmConcurrency {
|
||||
sema.acquire_owned().await.expect("llm global semaphore closed")
|
||||
}
|
||||
|
||||
/// 取全局 LLM 调用并发 permit 的**非阻塞**版本(对齐 try_acquire_per_conv 语义)。
|
||||
///
|
||||
/// 用途:spawn_agent 子代理循环入口一次性取 global + per_conv(child) 双份额,
|
||||
/// 任一耗尽即 failed(子代理不阻塞等待,防占满父 loop 的执行槽)。
|
||||
/// 锁持有短(不含 try_acquire)。
|
||||
pub async fn try_acquire_global(&self) -> Option<tokio::sync::OwnedSemaphorePermit> {
|
||||
let sema = self.global.lock().await.clone();
|
||||
// try_acquire_owned 非阻塞:Err(NoPermits) 返 None,不阻塞调用方。
|
||||
// Semaphore 不会 close(无 close() 调用),Err 仅可能为 NoPermits。
|
||||
sema.try_acquire_owned().ok()
|
||||
}
|
||||
|
||||
/// 取单对话内并发 permit(F-09 B 批5):按 conv_id 取/建 Semaphore,permits=当前 per_conv_permits(默认 2)。
|
||||
/// lock HashMap → 无则建 → clone Arc → 释放 lock → acquire_owned。锁持有短(不含 await acquire)。
|
||||
pub async fn acquire_per_conv(&self, conv_id: &str) -> tokio::sync::OwnedSemaphorePermit {
|
||||
|
||||
Reference in New Issue
Block a user