Skip to content

feat: experimental sub-agent API and examples#1060

Merged
threepointone merged 2 commits into
mainfrom
facet-api
Mar 4, 2026
Merged

feat: experimental sub-agent API and examples#1060
threepointone merged 2 commits into
mainfrom
facet-api

Conversation

@threepointone
Copy link
Copy Markdown
Contributor

Adds a first-class sub-agent abstraction for spawning child Durable Objects (facets) with isolated SQLite from a parent Agent.

What

  • SubAgent base class — extends partyserver's Server, provides subAgent(), abortSubAgent(), deleteSubAgent()
  • withSubAgents() mixin — adds sub-agent methods to Agent, AIChatAgent, McpAgent, etc. without shipping them in the base class
  • SubAgentStub<T> — typed RPC stubs that expose user-defined methods while hiding Server/DO internals
  • RFCdesign/rfc-sub-agents.md documenting the problem, proposal, alternatives, patterns, and open questions

Examples updated

All four experimental/gadgets-* examples now use the sub-agent API:

  • gadgets-subagents — fan-out/fan-in with parallel LLM calls across three perspective sub-agents
  • gadgets-chat — multi-room chat via ChatRoom sub-agents with isolated message history
  • gadgets-sandboxCustomerDatabase as a sub-agent for data isolation in a code sandbox
  • gadgets-gatekeeper — gated database access enforced structurally via sub-agent boundary

Exported from

import { SubAgent, withSubAgents } from "agents/experimental/subagent";

Requires the "experimental" compatibility flag in wrangler.jsonc.

Introduce an experimental sub-agent system and integrate it into example gadgets. Adds a new RFC (design/rfc-sub-agents.md) describing sub-agents, plus an implementation (packages/agents/src/experimental/sub-agent.ts) with a withSubAgents mixin and typed RPC stubs. Refactors Agents package (index/build/scripts/tests) and adds tests for sub-agents. Update example apps to use sub-agents: experimental/gadgets-chat now uses SubAgent facets, a StreamRelay RPC target, and a client-side AgentChatTransport that supports streaming, cancel, and resume; other gadgets and servers updated to the new API. Misc: docs/README and design listings updated and various package metadata/build changes to wire everything together.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 4, 2026

⚠️ No Changeset found

Latest commit: c3c8774

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 4, 2026

Open in StackBlitz

npm i https://pkg.pr.new/agents@1060
npm i https://pkg.pr.new/@cloudflare/ai-chat@1060
npm i https://pkg.pr.new/@cloudflare/codemode@1060
npm i https://pkg.pr.new/hono-agents@1060

commit: 733ef05

Replace experimental Durable Object "facet" docs with the new sub-agent pattern across four READMEs. Updated terminology, diagrams and TypeScript examples to use SubAgent / withSubAgents, added Key Pattern snippets, streaming protocol details (chat), and Related links. Files changed: experimental/gadgets-chat/README.md, experimental/gadgets-gatekeeper/README.md, experimental/gadgets-sandbox/README.md, experimental/gadgets-subagents/README.md. Primarily documentation updates to reflect API/architecture changes (no functional code changes).
@threepointone threepointone merged commit 054e65d into main Mar 4, 2026
3 checks passed
@threepointone threepointone deleted the facet-api branch March 4, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant