- 只翻注释/文档字符串:剥离注释后代码行逐字节不变(机械校验只剩允许的行尾注释形态) - 裁决编号与 design 节号(02.4.3 / 11.4.2 / design/05 §9 等)逐字保留 - 复核:go build 绿;orchestration 及其子包(audit/comm)测试绿;gofmt 干净
39 lines
1.5 KiB
Go
39 lines
1.5 KiB
Go
package orchestration
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/memory"
|
|
)
|
|
|
|
// 本文件持有调度器的长期记忆那一半:把子代理的任务记忆交给注入的 *memory.Store。
|
|
// 它紧挨 persona.go,因为子代理以哪个角色运行(design/22 §8-2)正是其记忆归档的
|
|
// 作用域。
|
|
|
|
// SinkMemory 通过注入的 *memory.Store 为子代理持久化一条任务记忆。子代理以哪个
|
|
// 角色运行即用作 persona/角色键 —— 指名了派发目标角色时用该角色,否则沿用旧的
|
|
// RoleID 绑定 —— 因此替班另一个角色的子代理写入的是那个角色的记忆域,绝不是派发
|
|
// 会话的(design/22 §8-2/§8-5)。内容与作用域/类别归类(user/persona/project)由
|
|
// 调用方提供,使作用域策略留在调用点。未注入 store 时返回 ErrNoMemory。
|
|
func (s *Scheduler) SinkMemory(ctx context.Context, sub *SubAgent, content string, scope memory.Scope, kind memory.Kind) (memory.MemoryItem, error) {
|
|
if s.memory == nil {
|
|
return memory.MemoryItem{}, fmt.Errorf("orchestration: sink memory: %w", ErrNoMemory)
|
|
}
|
|
if sub == nil {
|
|
return memory.MemoryItem{}, fmt.Errorf("orchestration: sink memory: %w", ErrAgentNotFound)
|
|
}
|
|
role := sub.PersonaID
|
|
if role == "" {
|
|
role = sub.RoleID
|
|
}
|
|
item := memory.MemoryItem{
|
|
PersonaID: role,
|
|
RoleID: role,
|
|
Scope: scope,
|
|
Kind: kind,
|
|
Content: content,
|
|
}
|
|
return s.memory.Add(ctx, item)
|
|
}
|