Repository navigation
fix(agent-core-v2): inherit baseline tools when forking agents - #4832
Conversation
🦋 Changeset detectedLatest commit: 5cbd117 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5cbd1174d4
ℹ️ 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".
| thinking: override.thinking ?? sourceData.thinkingLevel, | ||
| }, | ||
| initialProfile: override?.profile === undefined ? sourceData : undefined, | ||
| initialTools: override?.profile === undefined ? sourceLoop.baselineTools() : undefined, |
There was a problem hiding this comment.
Reconcile inherited schemas with the child tool registry
When an MCP or other runtime tool is removed or changes its schema after the parent's last request but before the fork, sourceLoop.baselineTools() still contains the old definition while the newly created child registry reflects the current tool set. Passing that stale list as initialTools is not corrected by AgentToolSelectService.requestTools, which treats a supplied base as authoritative, so the child advertises a removed tool or obsolete arguments and subsequent calls fail or reach the updated implementation with the wrong schema. Previously the child derived its baseline from its fresh registry; preserve the cached list only when its tool signatures still match, or carry the corresponding frozen registrations into the child.
Useful? React with 👍 / 👎.
Requirement or Bug
Side questions started with
/btwcan lose nearly all prompt-cache reuse when the main agent's available tools change after its Loop has started. The parent continues to request with its original baseline tools, while the fork recomputes a different baseline from the current profile. In the investigated session, cache hit rate dropped from 99.18% to 13.03%.This PR makes same-profile forks inherit the parent's exact baseline tools so their requests preserve the prompt-cache prefix.
Bug Reproduction Steps
activeToolNamesthrough a runtime profile or tool-state update./btwand send a side question.llm.tools_snapshotandusage.record: before the fix, the parent could send 40 tools while the child sent 30. The investigated response had 111,980 input tokens, with only 14,592 read from cache and 97,388 uncached.The existing
forkParitycache-parity test now covers this sequence instead of only configuring tools before the first request.Root Cause
Loopinitialization stores aToolDescription[]baseline separately fromProfileBindingSnapshot.activeToolNames. Later profile and runtime tool updates do not refresh that baseline.forkcopied only the parent's current profile data, so the child Loop computed a fresh baseline that could differ from the parent's actual request tools.This is a fundamental fix: the parent's baseline is passed through the agent-creation path into the child Loop at startup. The Wire format is unchanged, and no workaround or second tool-definition source is introduced.
Code Changes
IAgentLoopService.baselineTools()and allowstart(tools)to accept an initial baseline.CreateAgentOptions.initialToolsand pass the parent's baseline to same-profile forks.Behavior Changes and Affected Users
/btwCoverage:
forkParityverifies system prompt, outbound tools, and inherited history after a post-start tool-state change;agentLifecyclecovers fork lifecycle behavior;toolSelectServicecovers tool selection behavior and updated test doubles.Checklist
.changeset/fork-baseline-tools.mdas a patch changeset. Thegen-changesetsskill was unavailable in the current skill listing, so the file follows the repository's existing format directly.