Skip to content

refactor(agent-core-v2): port the agent-core llm core into human/llm - #4352

Merged
sailist merged 4 commits into
mainfrom
refact-301-10-22-llm-into-v2-human
Oct 28, 2026
Merged

sailist merged 4 commits into
mainfrom
refact-301-10-22-llm-into-v2-human

Conversation

@sailist

@sailist sailist commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Internal refactor task (refact-301): port the agent-core (237) llm core into agent-core-v2's human/llm, wholesale-replacing the protocol cores and requester internals of human/llm/ + llm-adapter/ while keeping the outward contracts (the LlmRequestEvent vocabulary, the llm-adapter/contract throw classes, and the DI service surface) unchanged. Non-streaming (stream: false) request capability comes with the replacement, per the accepted feat-242/#3872 design.

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

  • Run-loop machinery: ported the platform-free llm run loop into human/llm — request/response/endpoint contracts, the attempt driver generate.ts, the policy loop (runLlmRequest with single-attempt wiring: maxAttemptsPerStep: 1, no recoveries; turn-level retry/recovery unchanged), the settle stage (accumulation, timing, outcome synthesis with empty-response judgment at the source), and the protocol pipeline (defineProtocol, PipelineSpec, legalize passes, rules, kit).
  • A-vocabulary seam (human/llm/requester/run.ts): maps LlmRequestConfig + LlmRequestContent onto the core, wires the headers-timeout fetch per attempt, translates run-loop events into the unchanged 10-event LlmRequestEvent union, and synthesizes terminal events (done / failed / abort-as-llm.failed.remote).
  • Protocol cores: the four bases (openai / openai-responses / anthropic / google-genai) replaced by the ported decoder + pipeline lowering + legality + client/send/replay, each behind a thin create*Requester seam factory. Main-line wire behavior is preserved per protocol (media wire shapes, tool-result conversion modes and texts, reasoning/thinking encoding, usage/finish/error mapping, id normalization, beta/header rules, abort handling).
  • Kimi: rebuilt as protocol .with(patch) compositions in llm-kimi/protocol.ts (keep_parts, kimi thinking kwargs, builtin_function tools, usage hoist, extra_body flattening, x-trace-id, kimi image mimes, strict thinking efforts); the trait hook mechanism is removed and the adapter registry routes via per-provider requester factories.
  • stream=false: LlmRequestConfig.stream (default streaming) selects the non-streaming send+replay path with an isomorphic event sequence; ModelRequestParams gains the same additive pass-through.
  • Docs: docs/en/llm.md and docs/zh/llm.md rewritten for the pipeline architecture.
  • llm-adapter/contract/ is byte-identical (verified empty diff); the DI tokens and service registrations are unchanged.

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
Empty provider response llm.done fired, then the turn re-raised it as llm.failed.remote (empty_response) the requester ends it as llm.failed.remote directly, no preceding llm.done turn machine / ModelRequesterImpl — both already produce the same external error either way (pinned by turn and adapter tests) none needed (same external error class and retry classification)
Non-streaming requests not supported (stream: true hardcoded) stream: false honored at LlmRequestConfig / ModelRequestParams, isomorphic events; default unchanged new capability, nothing to rely on default stays streaming
Aborted requests base emitted llm.failed.remote kind abort same event, emitted by the seam on the aborted outcome ModelRequesterImpl abort propagation (pinned by its test) none needed (unchanged)
Headers timeout / proxy dispatcher via SDK fetchOptions.dispatcher (openai/anthropic/responses only) custom fetch built from the same dispatcher creation code; google-genai still excluded users of KIMI_CODE_LLM_HEADERS_TIMEOUT_MS and HTTP(S)/SOCKS proxy envs — same env parsing, warnings, and dispatcher injection (pinned by headers-timeout.test.ts) none needed (unchanged behavior)
Reasoning-key dialect latched per model from the first observed stream key derived from the reasoning keys stamped on history think parts (same default reasoning_content; explicit override via catalog reasoningKey preserved) providers emitting non-default reasoning keys — covered when history flows back (it always does on the turn path) none; accepted deviation for history-free one-shot callers
llm.failed.remote.rawError present only on actor-caught throws also present on mid-stream/remote failures (additive optional field) additive; consumers ignore absence/presence uniformly none needed
Deferred tool declarations filtered by upstream callers also filtered inside the encode pipeline no live caller relied on pass-through (upstream filters already) none needed
Trait customization hooks per-request trait objects on requester factories provider customization via protocol .with(patch); trait types deleted internal seam only (llm-adapter + llm-kimi updated in this PR) none needed (internal)

Test coverage: the 12+13 llm suites (src/human/test/llm, test/llm-adapter) are green with a conserved test count (338 tests); media wiring test and state manifest refreshed; full monorepo suite green on m0-dev (17381 passed, 1 unrelated remote-fs flake that passes in isolation).

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 34d5752

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T07:29:17.239678Z 34d5752 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@34d5752
npx https://pkg.pr.new/@moonshot-ai/kimi-code@34d5752

commit: 34d5752

@sailist
sailist force-pushed the refact-301-10-22-llm-into-v2-human branch 2 times, most recently from afef6fb to f2abbc4 Compare October 23, 2026 04:30

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f2abbc4abd

ℹ️ 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".

Comment on lines +85 to +90
if (efforts.length === 0) return 'on';
if (effort !== 'on' && efforts.includes(effort)) return effort;
const declared = meta?.defaultEffort?.trim();
return declared !== undefined && efforts.includes(declared)
? declared
: efforts[Math.floor(efforts.length / 2)]!;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore rejection of unsupported strict thinking efforts

For a Kimi model declaring supportEfforts: ['low', 'high'], a caller requesting max previously received an llm.failed.syntax thinking-config error, but strictEffort now silently substitutes the default or midpoint effort and sends the request as high. This ignores an explicit caller setting without any signal and contradicts the PR's claim that strict thinking validation is preserved; retain the previous validation failure rather than rewriting unsupported values.

AGENTS.md reference: AGENTS.md:L110-L112

Useful? React with 👍 / 👎.

anthropic: {
base: anthropicBetaBase,
trait: kimiAnthropicTrait,
base: kimiAnthropicBase,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve the Kimi Anthropic beta requester default

When callers use kimiProvider.createRequester('anthropic') with the normal kimiProvider.resolveModel(...) result, this binding no longer forces the beta API: the old binding used anthropicBetaBase, while kimiAnthropicBase now reaches createKimiAnthropicRequester with neither options.betaApi nor model.betaApi, so requests switch from client.beta.messages.create to client.messages.create. This silently drops the provider's previous beta transport for Kimi Anthropic users and can break the beta features that this protocol still emits; make this provider binding opt into betaApi: true as before.

AGENTS.md reference: AGENTS.md:L126-L128

Useful? React with 👍 / 👎.

Comment on lines +78 to +82
let fetchFn: typeof fetch;
try {
fetchFn = createLlmHeadersTimeoutFetch();
} catch (error) {
onEvent?.({ type: 'llm.failed.remote', error: base.decodeError(error), rawError: error });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Parse the headers-timeout setting only for transports that use it

When KIMI_CODE_LLM_HEADERS_TIMEOUT_MS is invalid, this unconditional call now rejects Google GenAI requests and requests using an injected clientFactory before sending, even though those transports never consume endpoint.fetch. The old Google requester and injected clients did not parse this setting, and the PR explicitly says Google remains excluded from headers-timeout handling; defer construction to the default OpenAI/Responses/Anthropic clients so an irrelevant environment variable cannot break these callers.

AGENTS.md reference: AGENTS.md:L110-L112

Useful? React with 👍 / 👎.

@sailist
sailist force-pushed the refact-301-10-22-llm-into-v2-human branch from f2abbc4 to c7f4d5d Compare October 28, 2026 03:29
@github-actions

Copy link
Copy Markdown
Contributor

❌ Nix build failed

Hash mismatch in pnpmDeps:

Hash
specified sha256-fvtkW8HSacFek+jT0t7v3WcYsSTfI22+4kDEyEYHFlY=
got sha256-S7kwWgHbN5ZH4xIH7W/9sbOXi7/JhaitX/ONsLmRr9E=

Please update flake.nix with the got hash.

- relocate requester, media, and built-in protocol modules
- update imports, exports, and module path references
- sync llm guides and the state manifest
Port the LLM protocols, policies, requester composition, and native message flow.
Align endpoint, capability, tool-call, media, persistence, and public client compatibility.
Update dependent packages, manifests, and existing tests.
Hydrate blob-backed media in cold transcript snapshots.
Restore non-assistant tool calls in spliced websocket events.
Cover durable records and live media compatibility paths.
@sailist
sailist force-pushed the refact-301-10-22-llm-into-v2-human branch from e1fd314 to 34d5752 Compare October 28, 2026 07:24
@sailist
sailist merged commit b12d13e into main Oct 28, 2026
16 checks passed
@sailist
sailist deleted the refact-301-10-22-llm-into-v2-human branch October 28, 2026 07:38
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 24, 2026
--refresh adds the 148 upstream commits that were missing from the
ledger; the true open count is now 149, not 1. The refresh keeps the
existing MoonshotAI#4820/MoonshotAI#4831/MoonshotAI#4352 corrections.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants