Documentation Index
Fetch the complete documentation index at: https://docs.standardagentbuilder.com/llms.txt
Use this file to discover all available pages before exploring further.
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
- sandboxed JavaScript/TypeScript execution through Dynamic Workers
- 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()
Environment
env(propertyName)envType(propertyName)setEnv(propertyName, value, options?)
env() resolves values from thread, account, instance, agent, and prompt env sources. envType() returns secret by default; text values may be shown in tool output and errors, while secret values should be redacted. setEnv() writes a thread-scoped env value and propagates it to active descendant threads. Pass { type: 'text' } or { type: 'secret' } to choose the display/redaction type; omitting type preserves the existing type or defaults new keys to secret.
Utilities
queueTool()/invokeTool()scheduleEffect()/getScheduledEffects()/removeScheduledEffect()- file APIs (
readFile,writeFile,readdirFile,findFiles, etc.) runCode(source, options?)
Code Execution
runCode() executes JavaScript or TypeScript in a Cloudflare Dynamic Worker sandbox loaded by stable content ID when possible. The sandbox does not receive thread state, filesystem, network access, timers, or host globals automatically. Bridge exact capabilities through options.imports and options.globals, use options.modules for local relative ES modules, and use options.execute to choose which export to run with which arguments. By default, AgentBuilder executes the default export with no args.
run.terminate(reason). AgentBuilder uses the AGENT_BUILDER_CODE_LOADER Worker Loader binding; missing configuration returns a link_error result naming that binding.
Memory is enforced by Cloudflare’s Dynamic Worker isolate limit. AgentBuilder accepts memoryLimitBytes for spec compatibility but cannot lower Cloudflare’s platform ceiling or report memoryUsedBytes; recognizable platform memory failures are returned with status: 'memory'.
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.