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:
1 parent
355f81d04a
commit
91e8d7a029
44 files changed
+1315
-1315
No files matched your search
@@ -8,21 +8,21 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
|
||||
)
|
||||
|
||||
// streamStep drives a streaming model call. It is the streaming counterpart of
|
||||
// agent.RunStep: it builds the request from the agent's public surface, runs the
|
||||
// loop's input guardrail, streams deltas through OnStream, runs the output
|
||||
// guardrail and decodes any tool calls. Because RunStep does not expose a stream
|
||||
// path, this method is owned by the loop; it mirrors the agent's semantics so the
|
||||
// two behave identically apart from the delta callback.
|
||||
// streamStep 驱动一次流式模型调用。它是
|
||||
// agent.RunStep 的流式对应物:它从 agent 的公开表面构建请求、
|
||||
// 运行循环的输入护栏、把增量流经 OnStream、运行输出
|
||||
// 护栏并解码所有工具调用。由于 RunStep 不暴露流式
|
||||
// 路径,该方法归循环所有;它镜像 agent 的语义,使两者
|
||||
// 除增量回调外行为一致。
|
||||
func (l *Loop) streamStep(ctx context.Context, messages []model.Message) (*stepOutcome, error) {
|
||||
ag := l.agentFor(ctx)
|
||||
adapter := ag.Adapter()
|
||||
if adapter == nil {
|
||||
return nil, fmt.Errorf("loop: stream step: %w", ErrNoAdapter)
|
||||
}
|
||||
// Resolve the role's agent and reasoning knobs once per step: the same pair is
|
||||
// used for the request and for the per-delta broadcast gate, so a role switch
|
||||
// can never apply the new prompt with the old broadcast switch mid-stream.
|
||||
// 每个 step 解析一次该角色的 agent 与推理旋钮:同一对取值
|
||||
// 既用于请求,也用于逐增量的广播门,因此角色切换
|
||||
// 绝不会在流中途用旧的广播开关套用新的提示词。
|
||||
knobs := l.knobsFor(ctx)
|
||||
req := l.buildRequest(ctx, messages, ag, knobs)
|
||||
|
||||
@@ -37,17 +37,17 @@ func (l *Loop) streamStep(ctx context.Context, messages []model.Message) (*stepO
|
||||
}
|
||||
|
||||
resp, err := adapter.ChatStream(ctx, req, func(ev model.StreamEvent) {
|
||||
// Stamp the session/turn identity at the loop boundary: the adapter runs
|
||||
// below the loop and cannot know which conversation the stream belongs to,
|
||||
// so the loop fills it from the context it was driven with (design/16 §4.2)
|
||||
// and the frontend can route the delta to the active session.
|
||||
// 在循环边界打上 session/turn 身份:适配器运行在
|
||||
// 循环之下,无法知道该流属于哪个会话,
|
||||
// 因此循环用它被驱动的 context 填充(design/16 §4.2),
|
||||
// 前端便能把增量路由到活跃会话。
|
||||
ev.SessionID = loopSession(ctx)
|
||||
ev.TurnID = loopTurn(ctx)
|
||||
// Suppress UI broadcast for internal autonomous passes (backthink),
|
||||
// whose intermediate reasoning must not leak into the chat stream, and for
|
||||
// thinking frames when the turn's role turned them off (showToUser: false).
|
||||
// Both gates are broadcast-only: the response the model produced is
|
||||
// unchanged, so display and persistence stay decoupled.
|
||||
// 为内部自主流程(backthink)抑制 UI 广播,
|
||||
// 其中间推理不得泄露进聊天流;当该 turn 的角色
|
||||
// 关闭思考帧时(showToUser: false)也抑制。两处门
|
||||
// 都只影响广播:模型产出的响应
|
||||
// 不变,因此展示与持久化保持解耦。
|
||||
if l.onStream != nil && !isMutedBroadcast(ctx) && broadcasts(ev, knobs.ThinkingShowToUser) {
|
||||
l.onStream(ev)
|
||||
}
|
||||
@@ -74,11 +74,11 @@ func (l *Loop) streamStep(ctx context.Context, messages []model.Message) (*stepO
|
||||
modelStopReason: resp.StopReason, model: resp.Model}, nil
|
||||
}
|
||||
|
||||
// broadcasts reports whether a streamed event may be pushed to the UI. Only
|
||||
// thinking frames are ever withheld, and only when the turn's role resolved
|
||||
// showToUser to false; text, tool-call and tool-progress frames are never
|
||||
// affected, so turning thinking off cannot change what the client sees of the
|
||||
// answer itself.
|
||||
// broadcasts 报告某流式事件是否可推给 UI。只有
|
||||
// 思考帧会被扣下,且仅当该 turn 的角色把
|
||||
// showToUser 解析为 false 时;文本、工具调用与工具进度帧
|
||||
// 从不受影响,因此关闭思考不会改变客户端所见
|
||||
// 的答案本身。
|
||||
func broadcasts(ev model.StreamEvent, showToUser *bool) bool {
|
||||
if !isThinkingKind(ev.Kind) {
|
||||
return true
|
||||
@@ -86,7 +86,7 @@ func broadcasts(ev model.StreamEvent, showToUser *bool) bool {
|
||||
return showToUser == nil || *showToUser
|
||||
}
|
||||
|
||||
// isThinkingKind reports whether kind is one of the reasoning segment events.
|
||||
// isThinkingKind 报告 kind 是否为推理分段事件之一。
|
||||
func isThinkingKind(kind model.StreamKind) bool {
|
||||
switch kind {
|
||||
case model.StreamKindThinkingStart, model.StreamKindThinkingDelta, model.StreamKindThinkingEnd:
|
||||
|
||||
Reference in new issue
Block a user