ref(chat): Decompose agent executor into chat/agent phase modules#756
Draft
dcramer wants to merge 2 commits into
Draft
ref(chat): Decompose agent executor into chat/agent phase modules#756dcramer wants to merge 2 commits into
dcramer wants to merge 2 commits into
Conversation
The agent executor is the subsystem, not the execution instance: run/slice vocabulary stays in function and type names (executeAgentRun, AgentRunOutcome), while the module path names what lives there — the agent. chat/agent-run.ts becomes chat/agent/index.ts as the composition root for the upcoming phase decomposition. Pure move; no behavior change and no exported symbol renames. Refs #746 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
executeAgentRunInPrivacyContext was ~2,100 lines with a dozen mutable closure variables that existed so the catch block could persist yield, timeout, and auth-pause continuations. Split it into chat/agent phase modules with explicit contracts: - request.ts owns the role-group types and routing interpretation (requester derivation, surface inference, destination asserts, session identifiers) - resume.ts owns run resumability: safe-boundary checkpoints, durable input commit, resume snapshots, and translation of expected endings into AgentRunOutcome values, so the executor catch block is a thin translation plus genuine-error guards - tools.ts wires sandbox, MCP/plugin auth orchestration, provider restoration, and Pi tool surfaces through a params/return contract - prompt.ts owns user-turn content parts, steering message shape, resume-safe history trimming, and full prompt assembly - skills.ts, session.ts, and sandbox.ts carry the remaining phases; index.ts stays the composition root and inline provider retry loop The private flattenAgentRunRequest shim is dissolved; phases consume the groups directly. Persisted sandbox reuse state (sandboxId, dependency profile hash) moves from the policy group to the state group where it belongs, with the egress trace-propagation override staying in policy as sandboxTracePropagation. agent-run-helpers.ts is dissolved along domain lines: Pi transcript predicates and runtime-turn-context manipulation move to chat/pi/transcript.ts, reply-quality text classifiers become private to services/turn-result.ts, summarizeMessageText joins chat/logging, and the prompt/skill helpers join their agent phase modules. Two production-dead exports (getSuccessfulToolCalls, prependMissingRuntimeTurnContext) are removed with their tests. No behavior change: persistence ordering, telemetry keys, and delivery semantics are preserved; consumer import paths move to the new module homes. Refs #746 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
executeAgentRunInPrivacyContextwas a ~2,100-line function whose dozen mutable closure variables existed so the catch block could persist yield, timeout, and auth-pause continuations. This completes the #746 contract cleanup by decomposing the executor into achat/agent/module — the module path names the subsystem (the agent), while run/slice vocabulary stays in function and type names (executeAgentRun,AgentRunOutcome):request.ts— the six role-group types plus routing interpretation (requester derivation, surface inference, destination asserts, session identifiers)resume.ts— run resumability: safe-boundary checkpoints, the durable input commit, resume snapshots, and translation of expected endings intoAgentRunOutcomevalues, so the executor catch block is a thin translation plus genuine-error guardstools.ts— sandbox executor, MCP/plugin auth orchestration, provider restoration from durable history, and the Pi tool surfaces behind one params/return contractprompt.ts— user-turn content parts, steering message shape, resume-safe history trimming, and full prompt assemblyskills.ts,session.ts,sandbox.ts— the remaining phases;index.tsstays the composition root with the provider retry loop inline to preserve abort-settlement, usage, and span orderingBehavior is unchanged: persistence ordering, telemetry keys, and delivery semantics are preserved, and the existing yield/timeout/auth-pause integration tests plus the full suite pass unmodified except where the request shape below moved.
Two request-contract cleanups deferred from the earlier phases land here. The private
flattenAgentRunRequestshim is dissolved — phases consume the role groups directly. And persisted sandbox reuse state (sandboxId, dependency profile hash) moves from thepolicygroup tostate.sandbox, with the egress trace override staying in policy assandboxTracePropagation; all request producers are updated and the resume paths rebuild this from thread state, so nothing persisted changes shape.agent-run-helpers.tsis dissolved along domain lines: Pi transcript predicates and runtime-turn-context manipulation move tochat/pi/transcript.ts(they were consumed by seven services/runtime modules, nothing agent-specific), the reply-quality text classifiers become private toservices/turn-result.ts(their only consumer),summarizeMessageTextjoinschat/logging, and the prompt/skill helpers join their phase modules. Two exports with no production callers (getSuccessfulToolCalls,prependMissingRuntimeTurnContext) are deleted with their tests.Review order: start with
chat/agent/index.ts(the orchestration skeleton and the slimmed catch block), thenresume.tsagainst the old inline persistence branches, thentools.ts/prompt.tswhich are mostly code motion behind explicit contracts. The first commit is a pure file move; the second is the decomposition.Fixes #746
🤖 Generated with Claude Code