Sub-agents
Spawn child harnesses that share the same backend and user-scoped memories. Task-scoped work stays private to the child.
spawn()
const child = harness.spawn({
agentId: "researcher",
sessionId: "research-task-1",
})
The child harness:
- Shares the same backend connection
- Inherits the parent's
userId - Has its own
agentIdandsessionId - Can read the parent's
user-scoped andagent-scoped memories - Can write
task-scoped memories that stay private
Memory visibility
// parent writes a user-scoped memory
await harness.memory().write({
content: "User prefers concise answers",
scope: "user",
embedding,
})
// child can read it
const results = await child.memory().search({
embedding: queryVec,
scope: ["user"],
})
// results include "User prefers concise answers"
// child writes a task-scoped memory — private
await child.memory().write({
content: "API uses REST, not GraphQL",
scope: "task",
embedding,
})
// parent cannot see task-scoped memories from child
Closing
child.close()
Closing a child harness does not close the shared backend. Only the root harness's close() method closes the backend connection.
Nested spawning
Children can spawn their own children. The same rules apply — shared backend, inherited userId, isolated task scope.
const grandchild = child.spawn({
agentId: "sub-researcher",
sessionId: "sub-task-1",
})