Repository navigation
Conversation
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
|
❌ Nix build failed Hash mismatch in
Please update |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 39841d6b7b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| export type LlmDeltaEvent = | ||
| | { readonly type: 'llm.delta.response_header'; readonly headers: Record<string, string> } |
There was a problem hiding this comment.
Add release metadata for the breaking event vocabulary
This commit removes the old exported event types and changes every runtime discriminator from llm.streaming.*/llm.retrying to llm.delta.*/llm.retry, but adds no .changeset entry. This reaches external consumers because packages/klient/src/core/facade/kosong-types.ts publicly aliases GenerateEvent to LlmRunEvent; upgrading will therefore break both compiled consumers and scripts matching the old event names without the required major-version signal. Obtain approval for the breaking bump and add the corresponding changeset before release.
AGENTS.md reference: AGENTS.md:L87-L87
Useful? React with 👍 / 👎.
| system: module.profile.systemPrompt, | ||
| messages: module.content.messages.flatMap((message) => pipeline.message(lowerableMessage(message), module)), | ||
| tools: (module.profile.tools ?? []).filter((tool) => tool.deferred !== true).map(pipeline.tool), | ||
| tools: (module.profile.tools ?? []).map(pipeline.tool), |
There was a problem hiding this comment.
Include newly transmitted deferred tools in request hashes
When a top-level tool has deferred: true, this line now transmits it to the provider, but llmStartedEvent/llmRequestedEvent in policy.ts:109 and llmToolsSnapshotPayload still remove every deferred tool before computing the tools hash and durable snapshot. Consequently llm.requested.toolsHash, llm.tools_snapshot, request logs, and cache-break telemetry describe a different tool set from the actual provider request; for non-dynamic models this occurs whenever the new legalization path promotes a deferred tool to an ordinary declaration. Compute observability hashes from the legalized/transmitted tool set rather than the old filtered view.
Useful? React with 👍 / 👎.
| system: module.profile.systemPrompt, | ||
| messages: module.content.messages.flatMap((message) => pipeline.message(lowerableMessage(message), module)), | ||
| tools: (module.profile.tools ?? []).filter((tool) => tool.deferred !== true).map(pipeline.tool), | ||
| tools: (module.profile.tools ?? []).map(pipeline.tool), |
There was a problem hiding this comment.
Keep deferred tools out of dynamic models' top-level list
With ToolSelect enabled for a model declaring dynamically_loaded_tools, the Loop seeds its profile with initialTools(), which marks every deferred MCP tool, and requestTools(..., disclosure=true, dynamic=true) returns that base array unchanged. legalizeTools also preserves those entries for a dynamic model, so this unconditional mapping now serializes every deferred schema into the ordinary top-level provider tools list. This defeats the flag's on-demand-loading contract and restores the full context cost for configurations with many deferred MCP tools; filter unloaded deferred entries in the ToolSelect resolver or otherwise keep them out of this conversion while still allowing explicitly retained direct-API tools.
Useful? React with 👍 / 👎.
| model: { | ||
| ...request.model, | ||
| spec: withProtocolCapabilities(request.model.spec, request.protocol.base), | ||
| spec: request.model.spec, | ||
| }, |
There was a problem hiding this comment.
Preserve inferred capabilities for custom protocols
When a Protocol supplies capabilities through its capability(modelName) callback but the request model omits explicit capabilities, generate() previously passed the merged spec to both encode and decoder. The merge now happens only inside runPipeline, so a custom Protocol.encode that does not use that helper—and even a defineProtocol decoder or patched decoder that inspects module.model.spec.capability—receives the unmerged model and can silently choose the wrong decoding or feature behavior. Build the capability-enriched module in generate() as before; runPipeline can retain its idempotent merge for direct encode calls.
Useful? React with 👍 / 👎.
- unify run boundaries, request summaries, deltas, retries, and outcomes - normalize deferred and duplicate tool declarations with notices and debug tracing - migrate consumers and add aimock-backed LLM behavior coverage
39841d6 to
cffb84f
Compare
Requirement or Bug
使用 core、agent-core-v2 或 klient 消费 LLM 事件时,run 与 attempt 的边界混杂,外部调用者难以用同一套生命周期理解请求、重试和 recovery。与此同时,
convert会静默过滤 deferred 工具,但直接 API 实测可以接受这些工具;顶层和 system message 中的同名声明也缺少统一的最终处理。这个 PR 统一 LLM 事件流与工具声明编码,让每次 generate、每个 attempt、重试、recovery 和重复声明都有明确且可观测的行为。
Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路
把能力解析、合法化和工具声明规范化收归到同一条 encode pipeline;事件则按 run、attempt 和增量数据分别建模。正常
generate()与直接protocol.encode现在共享同一次 capability 合并,不再需要各测试或调用方自行补齐。flowchart LR Input[LlmRequest] --> Caps[with-capabilities] Caps --> Legalize[legalize + legalize-tools] Legalize --> Convert[convert] Convert --> Transport[send / sendStream] Transport --> Settle[settle] Settle --> Events[started / requested / delta / retry / ended]legalize-tools是最终兜底,外部 resolver 仍可在更早阶段解决重复声明,从而避免最后的 notice/warn。空 system message 不在这个阶段删除,交由其他 pipeline 处理。关键决策
runPipeline入口一次generate与legalize-tools各自合并legalize-model后的legalize-toolsllm.notice和一条log.warntools: []阅读指南
packages/core/src/llm/response.ts:统一后的事件类型与载荷。packages/core/src/llm/generate.ts和policy/:run、attempt、重试与最终 outcome 的生成路径。packages/core/src/llm/protocol/pipeline.ts:capability 合并、阶段 trace 和 convert 映射。packages/core/src/llm/protocol/rules/tools.ts:deferred 元数据清理、同名去重和通知。packages/agent-core-v2/src/agent/loop/:journal、turn projection、request observation 与 loopService 的消费迁移。packages/core/test/llm/:事件生命周期、provider、错误、thinking 和真实 aimock transport 覆盖;数据 fixtures 可略读。Behavior Changes and Affected Users
llm.sent、llm.streaming.*、llm.retrying与内部attempt.*混合llm.started / requested / delta.* / retry / ended;不双发旧名称llm.requested与llm.ended载荷deferred: truetools: []log.debug({ pass })验证
7e2c565e31fb后:core与toolSelectService共 28 个文件,331/331。@moonshot-ai/coretypecheck 通过。pnpm lint通过:注释检查、oxlint、import boundary、guards、ratchet、instructions 均通过。pnpm install --frozen-lockfile成功。npm run build成功;仅有既有 ES2024 target 与 chunk-size 警告。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.(任务所有者明确要求本次不写 changeset。)gen-docsskill, or this PR needs no doc update.(已手动同步中英文文档,未运行 gen-docs。)