Skip to content

refactor(agent-core-v2): drop the llm state machine, let turn invoke the request actor directly - #3710

Merged
7Sageer merged 2 commits into
mainfrom
refactor/drop-llm-machine
Sep 10, 2026
Merged

refactor(agent-core-v2): drop the llm state machine, let turn invoke the request actor directly#3710
7Sageer merged 2 commits into
mainfrom
refactor/drop-llm-machine

Conversation

@7Sageer

@7Sageer 7Sageer commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — internal cleanup discussed offline.

Problem

The llm state machine (createLlmMachine in src/human/llm/requester/machine.ts) had decayed into a hollow wrapper: the turn machine's invoke has no onDone so the machine's LlmOutput/outcome was never consumed, its own emit() calls had no subscribers (all listeners attach to the root agent actor, which re-emits llm.* itself), retry/recovery are actually driven by the turn machine, and persistence only reads snapshot.context without serializing invoked child state. Everything it did reduced to a single fromCallback that forwards requester events to the parent.

What changed

  • Delete requester/machine.ts; keep the event contract (LlmEvent, LlmInput, MessageResolver) and the thin fromCallback adapter as requester/actor.ts (createRequestActor) — invoke.src still needs actor logic, but not a state machine.
  • createTurnMachine(llmActor, options)createTurnMachine(requester, options); the dormant messageResolvers extension point moves to turn options (media ref / tool-select resolvers and their tests preserved).
  • engine.ts composes one layer less; 8 test files updated mechanically; docs/en|zh/llm.md principle 5 corrected (retry/recovery were always turn-driven) and a rejected-scheme entry added.

Verified: tsc --noEmit, check-import-boundaries, check-no-comments, oxlint --type-aware (0 errors), full agent-core-v2 suite (365 files / 6528 tests) all pass.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: the issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • 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 Sep 10, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 0fb28eb

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

@7Hanrui

7Hanrui commented Sep 10, 2026

Copy link
Copy Markdown

@codex review

@7Sageer
7Sageer marked this pull request as ready for review September 10, 2026 12:09
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: d308b9ff92

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

@pkg-pr-new

pkg-pr-new Bot commented Sep 10, 2026

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

commit: 0fb28eb

Docs-only conflicts with the protocol trait refactor (#3641), resolved to
match the merged code:

- design principles: keep the turn-level event wording (the llm machine is
  gone), take the typed per-protocol trait description with the leak
  boundary re-pointed at the turn
- request lifecycle: the requester plan* composition, with recovery and
  empty-response judgment described where they live now — the turn
@7Sageer
7Sageer merged commit 1e6f6e3 into main Sep 10, 2026
15 checks passed
@7Sageer
7Sageer deleted the refactor/drop-llm-machine branch September 10, 2026 12:22
7Sageer added a commit that referenced this pull request Sep 10, 2026
Resolve the overlap with the llm-machine removal (#3710):

- the machine's createRequestActor is gone; the credential resolution and
  the abort-guarded error boundary move into llm/requester/actor.ts, kept
  synchronous on the credential-less path so the turn startup cascade keeps
  its ordering
- docs/{en,zh}/llm.md: unify principles and the request lifecycle with the
  turn-driven orchestration — credential resolution in the request actor,
  the recovery strategy chain and empty-response judgment in the turn
- turn.test.ts: drive the request actor through a harness machine instead
  of the deleted llm machine
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