Skip to content

index

Functions

print

ts
print(...messages)

A tool for printing a message to the console.

Parameters:

NameTypeDefault
messages

(source)

printJSON

ts
printJSON(obj: any, highlight: boolean)

A tool for printing an object as formatted JSON to the console.

Parameters:

NameTypeDefault
objany
highlightbooleanfalse

(source)

parseJSON

ts
parseJSON(text: string): any

Parse a JSON string and return the corresponding value (object, array, string, number, boolean, or null). Throws if the input is not valid JSON.

Parameters:

NameTypeDefault
textstring

Returns: any

(source)

input

ts
input(prompt: string): string

A tool for prompting the user for input and returning their response.

Parameters:

NameTypeDefault
promptstring

Returns: string

(source)

sleep

ts
sleep(ms: number)

Pause execution for the given duration in milliseconds. Use with unit literals for clarity: sleep(1s), sleep(500ms), sleep(2m).

Parameters:

NameTypeDefault
msnumber

(source)

round

ts
round(num: number, precision: number): number

A tool for rounding a number to a specified number of decimal places.

Parameters:

NameTypeDefault
numnumber
precisionnumber

Returns: number

(source)

fetch

ts
fetch(baseUrl: string, path: string, headers: Record<string, any>, allowedDomains: string[]): Result

A tool for fetching a URL and returning the response as text. Provide baseUrl and optionally path (they are joined). Set headers for custom request headers. Set allowedDomains to restrict which domains can be fetched.

@param baseUrl - The base URL to fetch @param path - Optional path appended to baseUrl @param headers - Custom request headers @param allowedDomains - Restrict fetches to these domains (empty allows all)

Parameters:

NameTypeDefault
baseUrlstring
pathstring""
headersRecord<string, any>{}
allowedDomainsstring[][]

Returns: Result

Throws: std::fetch

(source)

fetchJSON

ts
fetchJSON(baseUrl: string, path: string, headers: Record<string, any>, allowedDomains: string[]): Result

A tool for fetching a URL and returning the response as parsed JSON. Provide baseUrl and optionally path (they are joined). Set headers for custom request headers. Set allowedDomains to restrict which domains can be fetched.

@param baseUrl - The base URL to fetch @param path - Optional path appended to baseUrl @param headers - Custom request headers @param allowedDomains - Restrict fetches to these domains (empty allows all)

Parameters:

NameTypeDefault
baseUrlstring
pathstring""
headersRecord<string, any>{}
allowedDomainsstring[][]

Returns: Result

Throws: std::fetchJSON

(source)

read

ts
read(filename: string, dir: string): Result

A tool for reading the contents of a file and returning it as a string. The filename is resolved relative to dir.

@param filename - The file to read @param dir - The directory to resolve the filename against (defaults to ".")

Parameters:

NameTypeDefault
filenamestring
dirstring"."

Returns: Result

Throws: std::read

(source)

write

ts
write(filename: string, content: string, dir: string, mode: string): Result

A tool for writing content to a file. The filename is resolved relative to dir.

The mode parameter controls how an existing file is handled:

  • "overwrite" (default): replace the file if it exists, create it if not
  • "append": append to the file if it exists, create it if not
  • "create-only": fail if the file already exists

@param filename - The file to write @param content - The content to write @param dir - The directory to resolve the filename against (defaults to ".") @param mode - How to handle an existing file: "overwrite" | "append" | "create-only"

Parameters:

NameTypeDefault
filenamestring
contentstring
dirstring"."
modestring"overwrite"

Returns: Result

Throws: std::write

(source)

readImage

ts
readImage(filename: string, dir: string): Result

A tool for reading an image file and returning its contents as a Base64-encoded string. The filename is resolved relative to dir.

@param filename - The image file to read @param dir - The directory to resolve the filename against (defaults to ".")

Parameters:

NameTypeDefault
filenamestring
dirstring"."

Returns: Result

Throws: std::readImage

(source)

notify

ts
notify(title: string, message: string): boolean

A tool for showing a native OS notification with a title and message. Returns true if the notification was sent.

Parameters:

NameTypeDefault
titlestring
messagestring

Returns: boolean

Throws: std::notify

(source)

range

ts
range(start: number, end: number): number[]

Generate an array of numbers. With one argument, generates from 0 to start-1. With two arguments, generates from start to end-1.

Parameters:

NameTypeDefault
startnumber
endnumber-1

Returns: number[]

(source)

mostCommon

ts
mostCommon(items: any[]): any

Return the most common element in an array. Uses JSON serialization for comparison.

Parameters:

NameTypeDefault
itemsany[]

Returns: any

(source)

keys

ts
keys(obj: any): string[]

Return an array of an object's own enumerable property names.

Parameters:

NameTypeDefault
objany

Returns: string[]

(source)

values

ts
values(obj: any): any[]

Return an array of an object's own enumerable property values.

Parameters:

NameTypeDefault
objany

Returns: any[]

(source)

entries

ts
entries(obj: any): any[]

Return an array of an object's own enumerable entries, each as { key, value }.

Parameters:

NameTypeDefault
objany

Returns: any[]

(source)

emit

ts
emit(data)

Emit a custom event to the calling TypeScript code via the onEmit callback.

Parameters:

NameTypeDefault
data

(source)

callback

ts
callback(name: string, fn: any)

Register a scoped callback for the dynamic extent of the calling function or node. When the caller returns, the callback is automatically removed. Top-level callbacks (registered outside any function or node) are active for the whole run.

@param name - One of the Agency callback hook names (e.g. "onNodeStart", "onFunctionStart", "onLLMCallEnd") @param fn - A function that receives the event data

Parameters:

NameTypeDefault
namestring
fnany

(source)