Skip to main content

What Is a Thread?

A thread is a conversation instance backed by a Cloudflare Durable Object and SQLite state. Each thread has isolated:
  • messages
  • execution state
  • logs
  • filesystem

DurableThread Inheritance

agents/Thread.ts extends built-in DurableThread:
import { DurableThread } from 'virtual:@standardagents/builder';

export class Thread extends DurableThread {}

ThreadState APIs

Tools/hooks/endpoints receive ThreadState. Key methods:
  • getMessages() / injectMessage() / updateMessage()
  • queueMessage()
  • getParentThread() / getChildThread(referenceId)
  • terminate()
  • filesystem methods (readFile, writeFile, etc.)
Key properties:
  • children (resumable child registry)
  • terminated

Queue Semantics

queueMessage() is durable and ordered:
  • if thread is active, queued messages are injected before the next model step
  • if thread is idle, queueing forces execution
  • queue entries survive eviction

Parent/Child Communication

Subagent communication is message + filesystem aware:

Parent -> Child

  • initial invocation mapping and resumable subagent_message
  • any referenced attachments are copied parent -> child

Child -> Parent

  • completion/failure payloads are queued as silent parent messages
  • returned attachments are copied child -> parent
  • copied attachment paths are rewritten for the destination thread

Termination

terminate() performs soft shutdown:
  • sets terminated timestamp
  • aborts in-flight execution
  • rejects new execution/queue operations
  • propagates child termination status to parent registry when linked

Registry and Message Projection

Parent threads maintain a child registry for resumable instances. Messages may carry projected subagent fields (for UI/client grouping), including:
  • subagent_id
  • subagent_name
  • subagent_title
  • subagent_status
  • subagent_resumable
  • subagent_blocking