docs(agent): document clone() sharing model + address review#2
Open
cogwirrel wants to merge 2 commits into
Open
docs(agent): document clone() sharing model + address review#2cogwirrel wants to merge 2 commits into
cogwirrel wants to merge 2 commits into
Conversation
Add `clone(options?: CloneOptions)` to `Agent`, which builds a new agent by
replaying the original `AgentConfig` through the constructor — merging
`overrides` (last-wins) and appending `additionalPlugins`. The constructor now
retains a shallow copy of its config so the replay carries the caller's original
`tools` entries by reference.
This is what lets a clone resolve unconnected `McpClient` tools lazily on its
own first `stream()`: the MCP clients live in the replayed config, so each clone
runs tool resolution via `initialize()` without the template ever being
initialized. AG-UI's aws-strands adapter relies on this when it builds a
per-thread agent from a shared template — previously callers had to call
`agent.initialize()` on the template up front as a workaround.
The clone replays CONFIG, not live runtime state: messages, accumulated model
state, and post-construction hook registrations do not carry over. Seed those
explicitly via `overrides`.
Example:
const template = new Agent({ model, tools: [mcpClient] });
const perThread = template.clone({
overrides: { sessionManager, printer: false },
});
Documentation Preview FailedThe documentation deployment encountered an error. Please check the deployment logs for more details. |
cogwirrel
force-pushed
the
review/agent-clone-jack-feedback
branch
from
June 23, 2026 22:16
27498cd to
62a7a69
Compare
Documentation Preview FailedThe documentation deployment encountered an error. Please check the deployment logs for more details. |
cogwirrel
force-pushed
the
review/agent-clone-jack-feedback
branch
from
June 23, 2026 22:28
62a7a69 to
1f31255
Compare
Documentation Preview FailedThe documentation deployment encountered an error. Please check the deployment logs for more details. |
cogwirrel
force-pushed
the
review/agent-clone-jack-feedback
branch
from
June 23, 2026 22:43
1f31255 to
a27a488
Compare
Documentation Preview FailedThe documentation deployment encountered an error. Please check the deployment logs for more details. |
cogwirrel
force-pushed
the
review/agent-clone-jack-feedback
branch
from
June 23, 2026 23:24
a27a488 to
f287142
Compare
Documentation Preview FailedThe documentation deployment encountered an error. Please check the deployment logs for more details. |
Address review feedback on Agent.clone(): - Document the shallow config-share semantics in the clone() docstring — reference-typed config (model, sessionManager, memoryManager, tools, plugins) is shared with the template unless overridden; point users to overrides / additionalPlugins for per-session isolation. - Add a "Cloning Agents" section to the existing Snapshots guide (clone copies config, snapshots copy runtime state — natural siblings) covering the config-not-runtime-state behavior, the shared-vs-isolated table, lazy MCP resolution, and how clone() composes with snapshots. - Collapse the per-field assertions in the clone test into a single shape assertion per TESTING.md, keeping the model reference-identity check separate.
cogwirrel
force-pushed
the
review/agent-clone-jack-feedback
branch
from
June 24, 2026 00:55
f287142 to
0dd3b3c
Compare
cogwirrel
force-pushed
the
feat/agent-clone
branch
from
June 24, 2026 01:03
28242d2 to
946ac78
Compare
Documentation Preview FailedThe documentation deployment encountered an error. Please check the deployment logs for more details. |
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.
Review comments addressed
1. Document the sharing model beyond inline comments (Jack: "It will be helpful if we document it other than just docstring or inline comments")
Added a user-guide page
site/.../concepts/agents/clone.mdx(+ typecheckedclone.tssnippets, nav entry). It covers:model/tools/sessionManager/memoryManager/ constructorpluginsare shared by reference unless overridden, with thesessionManagerand stateful-plugin sharp edges called out and theoverrides/additionalPluginsescape hatches shown,clone()relates to snapshots.Also tightened the
clone()docstring to state the shallow-share semantics directly.2. Test assertion style (Jack: "Could you please also address this comment" — re: per-field assertions vs.
TESTING.md"Object Assertion")Collapsed the per-field assertions in the "replays the template config" test into a single
toEqualshape assertion (so a dropped/extra field fails), keeping theclone.modelreference-identity check as a separatetoBe.Notes
clone()is TypeScript-only, so the doc page is TS-only (marked with an Aside).api/needs-reviewlabel and an API reviewer — are repo-side actions for the upstream PR, not code changes; flagging here rather than actioning.Testing
test-snippets(resolves the local SDK build, which exposesclone()/AgentCloneOptions).agent.clone.test.ts(6 tests) pass with the reworked assertion.