Fix parentAgent for facet-only parents#1548
Merged
Merged
Conversation
Allow parentAgent() to resolve an immediate parent even when that parent is itself a facet rather than a top-level Durable Object binding. The helper now validates the recorded direct parent, resolves top-level parents through env or worker exports, and uses a root bridge to walk the recorded facet path for facet parents. This also documents the internal parentAgent() behavior, keeps WebSocket upgrades on externally routed sub-agent URLs for now, and adds Workers regressions for custom binding names, nested facet parents, normal HTTP fetch, Request objects, and unsupported WebSocket upgrades. Co-authored-by: Cursor <cursoragent@cursor.com>
🦋 Changeset detectedLatest commit: dd5a550 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 |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
Add a Researcher facet under each multi-ai-chat Chat so the example exercises parentAgent(Chat) from a facet-only direct parent in a real app flow. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
This PR fixes
Agent#parentAgent(Cls)for nested sub-agent trees where the immediate parent is itself a Durable Object facet rather than a top-level bound Durable Object namespace.Before this change,
parentAgent(Cls)only knew how to resolve top-level parents throughenv[Cls.name]. That worked for simpleRoot -> Childtrees, but it broke for deeperRoot -> OuterFacet -> InnerFacettrees becauseInnerFacet.parentAgent(OuterFacet)tried to find a top-levelOuterFacetnamespace even thoughOuterFacetis intentionally facet-only.What changed
parentAgent(Cls)still validates thatCls.namematches the recorded direct parent class inparentPath.env[Cls.name]and falls back to the Workerexportsnamespace by exported class name.parentPathparentAgent()opens the top-level root namespacectx.facets.fetch()calls on a facet-parent stub are supported through the same internal bridge as RPC methods.parentAgent().fetch()now fail early with a clear error because WebSocket handles cannot be serialized over RPC yet. External/sub/...routing remains the supported WebSocket path.getSubAgentByName()now reuses the same internal method invocation helper, keeping stub method dispatch consistent.Docs
docs/sub-agents.mdto explain:parentAgent()resolutionexports.fetch()supportparentAgent().fetch()parentAgent(Cls)calls and external/sub/...routingdesign/sub-agent-routing.mdas the living design doc.design/rfc-sub-agent-routing.mdso readers do not rely on the older RFC wording for currentparentAgent()behavior.Tests
Added Workers regressions covering:
parentAgent()throws clearly when called from a top-level, non-facet agent.fetch()works.fetch()works with a realRequestobject.fetch()worksValidation
npm run test:workers --workspace agents -- src/tests/sub-agent.test.tspassed: 86 testsnpm run checkpassedexamples/think-slide-deck/package.jsonmissing, but exits successfully.Made with Cursor