What Is ThreadState?
ThreadState is the runtime interface passed to tools, hooks, and thread endpoints.
It provides:
- thread identity
- message operations
- model/prompt/agent loaders
- tool and effect scheduling helpers
- filesystem access
- subagent hierarchy and lifecycle surfaces
Core Surfaces
Identity
threadIdagentIduserIdcreatedAt
Messaging
getMessages()getMessage()injectMessage()updateMessage()queueMessage()
Subagent Hierarchy
getChildThread(referenceId)getParentThread()children(resumable child registry)
Lifecycle
terminate()terminated
Resource Loading
loadModel()loadPrompt()loadAgent()
Utilities
queueTool()/invokeTool()scheduleEffect()/getScheduledEffects()/removeScheduledEffect()- file APIs (
readFile,writeFile,readdirFile,findFiles, etc.)
ThreadState in Tools
Queue Semantics
queueMessage() is durable and ordered:
- active thread: injected before next model step
- idle thread: queue triggers execution
- queue survives eviction
Cross-Thread Attachment Safety
When parent/child communication includes attachments, runtimes copy files across thread filesystems and rewrite attachment paths to destination-local values.Notes
executionmay benullwhen thread is at rest._notPackableRuntimeContextis runtime-specific and not portable.