Repository navigation
docs: document Agent.clone list property sharing - #1705
Conversation
🦋 Changeset detectedLatest commit: f6e2210 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de3233ed02
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 87ca931d14
ℹ️ 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".
Summary
Agent.clone()does not document how list properties are copied, and the real behavior is easy to get backwards. A clone and its original reference the same array for any list property thatclone()does not override, so mutating that list through either agent changes both.Current behavior on
main, unmodified:This is not a new observation. The identical semantics were raised against the Python SDK in openai/openai-agents-python#1293, and the resolution there was to document them rather than change them: openai/openai-agents-python#1296 added a
clone()docstring stating that new list objects are created only if overridden, but their contents are shared with the original.That PR is also a good illustration of how easy this is to misread. The reporter's own reproduction asserted
clone.tools is not original.tools, and the test failed in review, because the lists are in fact the same object.The JS
clone()JSDoc carries none of this. This change adds it so both SDKs describe the same contract.Fix
JSDoc only. No behavior change and no API change.
The wording names the affected properties explicitly (
tools,handoffs,mcpServers,inputGuardrails,outputGuardrails), separates the overridden case from the non-overridden one, states that list entries are shared in both cases, and shows the supported way to give a clone a list it owns:Test plan
Two tests in
packages/agents-core/test/agent.test.ts. Both pin current behavior, so they pass before and after this change:shares list properties between a clone and its original as documentedgives the clone its own array for a list property passed to cloneBecause they are guards rather than regression tests, I verified they are load bearing by temporarily replacing the constructor assignments with copying versions (
config.tools ? [...config.tools] : []) and confirming the first one fails:Then reverted that experiment.
Commands run locally on Windows.
pnpmis not available in this environment, so the package binaries were invoked directly:vitest run test/agent.test.tsforagents-core: 95 passedvitest runfor all ofagents-core: 90 failed, 5716 passed, 2 skippedmain: 90 failed, 5714 passed, 2 skippedtsc --noEmit -p tsconfig.json: cleaneslinton both changed files: cleanprettier --checkon all changed files: cleangit diff --check: cleanIssue number
N/A. Cross-SDK documentation alignment with openai/openai-agents-python#1293 and openai/openai-agents-python#1296.
Checks
pnpm testandpnpm test:examples(pnpm is unavailable in this environment; the equivalentvitestruns are listed in the test plan above)pnpm test:integration.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PRpnpm changesetto indicate my changes