Documentation menu
Documentation

Sub-agents

Create co-located child agents with isolated storage and typed parent–child RPC.

Delegate durable responsibilities

Use native this.subAgent(ChildClass, name) when one root entity owns an open-ended set of children such as chats, documents, sessions, projects, or orchestration workers.

example
export class Orchestrator extends Agent {
  async research(topics: string[]) {
    return Promise.all(topics.map(async (topic, index) => {
      const child = await this.subAgent(Researcher, `research-${index}`);
      return child.search(topic);
    }));
  }
}

export class Researcher extends Agent {
  async search(topic: string) {
    return { topic, findings: [] };
  }
}

Lifecycle and access

  • Export child classes from the worker entry so the runtime can discover them.
  • Children have isolated SQLite but run as facets co-located with the parent.
  • Use parentAgent() for child-to-parent RPC.
  • Use hasSubAgent() and listSubAgents() for registry-backed access control.
  • abortSubAgent() stops execution but preserves storage; deleteSubAgent() permanently removes it.