ExecutionTree
Defined in: core/execution-tree.ts:225
The Execution Tree - single source of truth for all execution state.
Features:
- Stores all nodes (LLM calls, gadgets) in a hierarchical structure
- Emits events on mutations
- Provides query methods for aggregation (costs, media, descendants)
- Supports single shared tree model for nested subagents
Example
Section titled “Example”const tree = new ExecutionTree();
// Add root LLM callconst llmNode = tree.addLLMCall({ iteration: 1, model: "sonnet" });
// Add gadget under the LLM callconst gadgetNode = tree.addGadget({ invocationId: "gc_1", name: "ReadFile", parameters: { path: "/foo.txt" }, parentId: llmNode.id,});
// Complete the gadgettree.completeGadget(gadgetNode.id, { result: "file contents", executionTimeMs: 50 });
// Query total costconsole.log(tree.getTotalCost());Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ExecutionTree(
options?):ExecutionTree
Defined in: core/execution-tree.ts:249
Parameters
Section titled “Parameters”options?
Section titled “options?”baseDepth?
Section titled “baseDepth?”number
parentNodeId?
Section titled “parentNodeId?”string | null
Returns
Section titled “Returns”ExecutionTree
Properties
Section titled “Properties”baseDepth
Section titled “baseDepth”
readonlybaseDepth:number
Defined in: core/execution-tree.ts:241
Base depth for all nodes in this tree. Used when this tree is a subagent’s view into a parent tree.
parentNodeId
Section titled “parentNodeId”
readonlyparentNodeId:string|null
Defined in: core/execution-tree.ts:247
Parent node ID for subagent trees. All root nodes in this tree will have this as their parentId.
Methods
Section titled “Methods”addGadget()
Section titled “addGadget()”addGadget(
params):GadgetNode
Defined in: core/execution-tree.ts:445
Add a new gadget node to the tree.
Parameters
Section titled “Parameters”params
Section titled “params”Returns
Section titled “Returns”addLLMCall()
Section titled “addLLMCall()”addLLMCall(
params):LLMCallNode
Defined in: core/execution-tree.ts:334
Add a new LLM call node to the tree.
Parameters
Section titled “Parameters”params
Section titled “params”Returns
Section titled “Returns”appendLLMResponse()
Section titled “appendLLMResponse()”appendLLMResponse(
nodeId,chunk):void
Defined in: core/execution-tree.ts:381
Add text to an LLM call’s response (for streaming).
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
string
Returns
Section titled “Returns”void
complete()
Section titled “complete()”complete():
void
Defined in: core/execution-tree.ts:940
Mark the tree as complete (no more events will be emitted).
Returns
Section titled “Returns”void
completeGadget()
Section titled “completeGadget()”completeGadget(
nodeId,params):void
Defined in: core/execution-tree.ts:514
Complete a gadget node successfully.
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
params
Section titled “params”Returns
Section titled “Returns”void
completeLLMCall()
Section titled “completeLLMCall()”completeLLMCall(
nodeId,params):void
Defined in: core/execution-tree.ts:399
Complete an LLM call node.
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
params
Section titled “params”Returns
Section titled “Returns”void
emitText()
Section titled “emitText()”emitText(
content,llmCallNodeId):void
Defined in: core/execution-tree.ts:603
Emit a text event (notification only, not stored in tree).
Parameters
Section titled “Parameters”content
Section titled “content”string
llmCallNodeId
Section titled “llmCallNodeId”string
Returns
Section titled “Returns”void
events()
Section titled “events()”events():
AsyncGenerator<ExecutionEvent>
Defined in: core/execution-tree.ts:909
Get async iterable of all events. Events are yielded as they occur.
Returns
Section titled “Returns”AsyncGenerator<ExecutionEvent>
failLLMCall()
Section titled “failLLMCall()”failLLMCall(
nodeId,error,recovered):void
Defined in: core/execution-tree.ts:425
Mark an LLM call as failed.
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
Error
recovered
Section titled “recovered”boolean
Returns
Section titled “Returns”void
getAncestors()
Section titled “getAncestors()”getAncestors(
id):ExecutionNode[]
Defined in: core/execution-tree.ts:660
Get ancestors of a node (from root to parent).
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”getChildren()
Section titled “getChildren()”getChildren(
id):ExecutionNode[]
Defined in: core/execution-tree.ts:649
Get children of a node.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”getCurrentLLMCallId()
Section titled “getCurrentLLMCallId()”getCurrentLLMCallId():
string|undefined
Defined in: core/execution-tree.ts:705
Get the current (most recent incomplete) LLM call node.
Returns
Section titled “Returns”string | undefined
getDescendants()
Section titled “getDescendants()”getDescendants(
id,type?):ExecutionNode[]
Defined in: core/execution-tree.ts:681
Get all descendants of a node.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”getNode()
Section titled “getNode()”getNode(
id):ExecutionNode|undefined
Defined in: core/execution-tree.ts:623
Get a node by ID.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”ExecutionNode | undefined
getNodeByInvocationId()
Section titled “getNodeByInvocationId()”getNodeByInvocationId(
invocationId):GadgetNode|undefined
Defined in: core/execution-tree.ts:630
Get a gadget node by invocation ID.
Parameters
Section titled “Parameters”invocationId
Section titled “invocationId”string
Returns
Section titled “Returns”GadgetNode | undefined
getNodeCount()
Section titled “getNodeCount()”getNodeCount():
object
Defined in: core/execution-tree.ts:853
Get node counts.
Returns
Section titled “Returns”object
gadgets
Section titled “gadgets”gadgets:
number
llmCalls
Section titled “llmCalls”llmCalls:
number
getRoots()
Section titled “getRoots()”getRoots():
ExecutionNode[]
Defined in: core/execution-tree.ts:640
Get all root nodes (depth 0 for this tree).
Returns
Section titled “Returns”getSubtreeCost()
Section titled “getSubtreeCost()”getSubtreeCost(
nodeId):number
Defined in: core/execution-tree.ts:738
Get total cost for a subtree (node and all descendants).
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
Returns
Section titled “Returns”number
getSubtreeMedia()
Section titled “getSubtreeMedia()”getSubtreeMedia(
nodeId):GadgetMediaOutput[]
Defined in: core/execution-tree.ts:815
Collect all media from a subtree.
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
Returns
Section titled “Returns”getSubtreeTokens()
Section titled “getSubtreeTokens()”getSubtreeTokens(
nodeId):object
Defined in: core/execution-tree.ts:788
Get token usage for a subtree.
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
Returns
Section titled “Returns”object
cached
Section titled “cached”cached:
number
input:
number
output
Section titled “output”output:
number
getTotalCost()
Section titled “getTotalCost()”getTotalCost():
number
Defined in: core/execution-tree.ts:723
Get total cost for entire tree.
Returns
Section titled “Returns”number
getTotalTokens()
Section titled “getTotalTokens()”getTotalTokens():
object
Defined in: core/execution-tree.ts:766
Get token usage for entire tree.
Returns
Section titled “Returns”object
cached
Section titled “cached”cached:
number
input:
number
output
Section titled “output”output:
number
isComplete()
Section titled “isComplete()”isComplete():
boolean
Defined in: core/execution-tree.ts:952
Check if the tree is complete.
Returns
Section titled “Returns”boolean
isSubtreeComplete()
Section titled “isSubtreeComplete()”isSubtreeComplete(
nodeId):boolean
Defined in: core/execution-tree.ts:838
Check if a subtree is complete (all nodes finished).
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
Returns
Section titled “Returns”boolean
on(
type,listener): () =>void
Defined in: core/execution-tree.ts:886
Subscribe to events of a specific type. Returns unsubscribe function.
Parameters
Section titled “Parameters”Event type to subscribe to (use ”*” for all events)
listener
Section titled “listener”EventListener
Callback function that receives matching events
Returns
Section titled “Returns”Unsubscribe function
():
void
Returns
Section titled “Returns”void
Example
Section titled “Example”const unsubscribe = tree.on("gadget_complete", (event) => { if (event.type === "gadget_complete") { console.log(`Gadget ${event.name} completed`); }});onAll()
Section titled “onAll()”onAll(
listener): () =>void
Defined in: core/execution-tree.ts:901
Subscribe to all events.
Parameters
Section titled “Parameters”listener
Section titled “listener”EventListener
Returns
Section titled “Returns”():
void
Returns
Section titled “Returns”void
skipGadget()
Section titled “skipGadget()”skipGadget(
nodeId,failedDependency,failedDependencyError,reason):void
Defined in: core/execution-tree.ts:561
Mark a gadget as skipped due to dependency failure.
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
failedDependency
Section titled “failedDependency”string
failedDependencyError
Section titled “failedDependencyError”string
reason
Section titled “reason”"dependency_failed" | "controller_skip"
Returns
Section titled “Returns”void
startGadget()
Section titled “startGadget()”startGadget(
nodeId):void
Defined in: core/execution-tree.ts:494
Mark a gadget as started (running).
Parameters
Section titled “Parameters”nodeId
Section titled “nodeId”string
Returns
Section titled “Returns”void