docs(runtime): internal/runtime/loop 44 个文件注释改中文(逐行 1:1,代码零字节改动)

主人 2026-10-03 拍板「注释一律中文」;本模块按长期分批协议(一个模块一次派工)执行。
注释行数 1329 → 1329 逐行 1:1(含中文 33 → 1304);行尾注释 5 条一并译。
校验:机械校验(非注释改动行)= 空;独立 Go AST 程序(剥注释复渲)证明 44/44 文件代码全等;
全树 go test ./... 58 包 ok / 0 FAIL;交叉编译绿。
gofmt:capacity_loop_test.go / flow.go 改动前即未格式化,按铁律保留原样未动。
This commit is contained in:
AskaEth committed 2026-10-03 22:28:21 +08:00
1 parent 355f81d04a
commit 91e8d7a029
44 files changed
+1315 -1315

No files matched your search

+37 -37
View File
@@ -8,11 +8,11 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
)
// buildRequest assembles a model.Request from the turn's agent's public surface,
// mirroring agent.buildRequest so the streaming path behaves identically to
// RunStep (leading instruction message, tool schemas, model routing). The agent
// and the reasoning knobs are resolved from ctx, so a session that switched roles
// gets the new role's prompt and budget on its very next step (design/22 §4.2).
// buildRequest 从该 turn 的 agent 公开表面组装 model.Request,
// 镜像 agent.buildRequest,使流式路径的行为与
// RunStep 一致(前导指令消息、工具 schema、模型路由)。agent
// 与推理旋钮从 ctx 解析,因此切换了角色的会话
// 在其下一步就拿到新角色的提示词与预算(design/22 §4.2)。
func (l *Loop) buildRequest(ctx context.Context, messages []model.Message, ag *agent.Agent, knobs LoopKnobs) model.Request {
req := model.Request{
Model: ag.Model(),
@@ -32,8 +32,8 @@ func (l *Loop) buildRequest(ctx context.Context, messages []model.Message, ag *a
return req
}
// assembleMessages prepends the agent's instructions as a leading system message
// when they are non-empty, otherwise returns the input slice unchanged.
// assembleMessages 在 agent 指令非空时把它们作为前导系统消息
// 前置,否则原样返回输入切片。
func assembleMessages(ag *agent.Agent, messages []model.Message) []model.Message {
instr := ag.Instructions()
if instr == "" {
@@ -45,8 +45,8 @@ func assembleMessages(ag *agent.Agent, messages []model.Message) []model.Message
return out
}
// temperatureOf returns a pointer to the agent's configured temperature, mapping
// zero to nil so the provider default applies (matching the agent package).
// temperatureOf 返回指向 agent 所配置温度的指针,把
// 零映射为 nil,使 provider 默认值生效(与 agent 包一致)。
func temperatureOf(ag *agent.Agent) *float64 {
t := ag.Temperature()
if t == 0 {
@@ -55,18 +55,18 @@ func temperatureOf(ag *agent.Agent) *float64 {
return &t
}
// toolSchemas advertises the registered tool schemas to the model, or nil when no
// dispatcher is configured. When a capacity decider is wired and enabled, it
// classifies the current round and returns only the allowed set for that state
// (a view over the dispatcher, per design/14 §4): the model sees/invokes only
// the allowed tools, while Invoke itself stays unblocked. A nil or disabled
// decider keeps the pre-existing behavior (every tool advertised).
// toolSchemas 向模型广告已注册的工具 schema;未配置
// dispatcher 时为 nil。接上并启用了 capacity 判定器时,它
// 判定当前轮次并只返回该状态的允许集
// (dispatcher 之上的一个视图,见 design/14 §4):模型只看见/调用
// 允许的工具,而 Invoke 本身不被拦截。nil 或被禁用的
// 判定器保持既有行为(每个工具都被广告)。
//
// The design/11 §3 security gate runs last over whatever the capacity view left:
// in a group/stranger environment only tools whose editable marker allows that
// environment are advertised (default closed), and the owner environment keeps
// the full set. Security is a hard red line, not a convenience hint, so it can
// only shrink the surface — it never re-admits a tool capacity excluded.
// design/11 §3 安全门最后在 capacity 视图留下的结果之上运行:
// 群聊/陌生人环境中只广告其可编辑标记允许该
// 环境的工具(默认关闭),而 owner 环境保留
// 全集。安全是硬红线而非便利提示,因此它
// 只能收缩暴露面 —— 绝不重新放行被 capacity 排除的工具。
func (l *Loop) toolSchemas(ctx context.Context, messages []model.Message) []model.ToolSpec {
d := l.dispatcher()
if d == nil {
@@ -110,9 +110,9 @@ func (l *Loop) toolSchemas(ctx context.Context, messages []model.Message) []mode
return l.restrictSchemas(ctx, d, out)
}
// capacityTexts extracts the recent conversation text for the capacity decider:
// the last few non-system/non-tool turns, in chronological order (oldest first),
// so the decider's current-turn window sees the latest user message last.
// capacityTexts 为 capacity 判定器提取近期对话文本:
// 最后几个非 system/非 tool 的轮次,按时间顺序(最早的在前),
// 使判定器的当前轮窗口最后看到最新的用户消息。
func capacityTexts(messages []model.Message) []string {
texts := make([]string, 0, 6)
for i := len(messages) - 1; i >= 0 && len(texts) < 6; i-- {
@@ -130,17 +130,17 @@ func capacityTexts(messages []model.Message) []string {
return texts
}
// capacityRecallTopK bounds how many recalled habit memories the capacity L4 layer
// considers per round.
// capacityRecallTopK 限制 capacity L4 层每轮考虑多少条
// 召回的习惯记忆。
const capacityRecallTopK = 5
// capacityRecall retrieves the owner's relevant long-term memories for the capacity
// L4 habit-alignment layer (design §2.2 L4), the memory feed that lets the decider
// learn the user's task-expression habits. It returns nil (keeping L4 silent) when
// no retriever/persona is configured — backward compatible — or in a restricted
// (group chat / stranger) context, per the isolation red line: L4 learns the owner's
// habits and must never read owner-sensitive memory into a group or stranger intent
// decision (design §2.2 红线: 不读陌生人敏感).
// capacityRecall 为 capacity L4 习惯对齐层(design §2.2 L4)
// 检索主人的相关长期记忆,这是让判定器学到用户任务表达
// 习惯的记忆输入。它返回 nil(使 L4 保持静默)的情形包括:
// 未配置 retriever/persona —— 向后兼容 —— 或处于受限
// (群聊 / 陌生人)上下文,依据隔离红线:L4 学习主人的
// 习惯,绝不把主人敏感记忆读进群聊或陌生人的意图
// 判定(design §2.2 红线: 不读陌生人敏感)。
func (l *Loop) capacityRecall(ctx context.Context, messages []model.Message) []capacity.RecallItem {
personaID := l.personaFor(ctx)
if l.retriever == nil || personaID == "" {
@@ -168,11 +168,11 @@ func (l *Loop) capacityRecall(ctx context.Context, messages []model.Message) []c
return items
}
// decodeToolCalls decodes tool calls from a model.Response via the agent's shared
// decoder, so the streaming and non-streaming paths agree on the provider-native
// tool calls the adapters emit (Anthropic tool_use / OpenAI tool_calls) as well
// as the legacy JSON-envelope convention. It reports ok=true (with a non-empty
// slice) when a call is decoded.
// decodeToolCalls 经 agent 的共享解码器从 model.Response 解码工具
// 调用,使流式与非流式路径对适配器发出的 provider 原生
// 工具调用(Anthropic tool_use / OpenAI tool_calls)以及
// 旧式 JSON 信封约定保持一致。解码出调用时
// 报告 ok=true(切片非空)。
func decodeToolCalls(resp model.Response) ([]agent.ToolCall, bool) {
return agent.ExtractToolCalls(resp)
}