# Global Bindings

Source: https://docs.autessa.com/docs/autessascript/bindings

> The four global objects every AutessaScript sees: console, response, variables, and responseStream.

# Global Bindings

Four objects are injected into every script's global scope before it runs: `console` for logging, `response` for returning the result, `variables` for reading inputs, and `responseStream` for streaming progress (streaming executions only). Everything else — `api`, `llm`, `connector`, `secrets`, `tools`, `mathUtils`, `waitUtils` — is a helper library covered in the helper pages.

## console

Captured logging. Nothing goes to a server console — every call is recorded into the execution's log list with a timestamp and level, in the format `[yyyy-MM-dd HH:mm:ss.SSS] [LEVEL] message`. All five methods accept any number of arguments of any type; arguments are stringified and joined with single spaces.

  - `console.log` — void"> Records a `LOG`-level entry.
  - `console.info` — void"> Records an `INFO`-level entry.
  - `console.warn` — void"> Records a `WARN`-level entry.
  - `console.error` — void"> Records an `ERROR`-level entry.
  - `console.debug` — void"> Records a `DEBUG`-level entry.

```javascript
console.log("processing", 3, "items");
// -> [2026-07-01 14:02:11.482] [LOG] processing 3 items
```

> Arguments are converted with plain string coercion, not JSON serialization — a JS object logs as an unhelpful opaque string. Log `JSON.stringify(obj)` when you want to see the contents.

## response

How your script returns its result. **Calling `response.setResponse(...)` is required.** If the script finishes without calling it, the execution's final response is empty: a script tool returns no result to the agent, and a computed column writes no value. There is no implicit "last expression" return.

  - `response.setResponse` — void"> Sets the script's final output. Pass a string. Non-string values are coerced with string conversion — so for structured data, always pass `JSON.stringify(obj)` rather than the object itself. Calling it again replaces the previous value; the last call wins.
  - `response.getFinalResponse` — string"> Returns the value set so far (or nothing if `setResponse` hasn't been called). Occasionally useful for append-style patterns.

```javascript
const result = { status: "ok", count: 42 };
response.setResponse(JSON.stringify(result));   // correct
// response.setResponse(result);                // wrong: coerced to a string, not JSON
```

## variables

Read-only access to the script's inputs. In a script tool this map contains every `@@{name}` argument the tool declares — the same placeholder mechanism all Autessa tools use — plus platform context values such as `AUTESSA_COMPANY_ID`, `AUTESSA_TOOL_NAME`, and `AUTESSA_AGENT_NAME`. A tool config containing `@@{customerName}` means your script reads `variables.get("customerName")`.

  - `variables.get` — string"> Returns the value for `key`, or `null` if absent. In tool executions every value is a string — parse numbers and JSON yourself. (In computed columns, values keep their native column types; see [Computed columns](/docs/autessascript/computed-columns.md).)
  - `variables.has` — boolean"> Whether `key` is present.
  - `variables.keys` — string[]"> All variable names. Iterable from JavaScript.
  - `variables.size` — number"> Number of variables.

```javascript
if (!variables.has("orderId")) {
  response.setResponse(JSON.stringify({ error: "orderId is required" }));
} else {
  const orderId = variables.get("orderId");        // string, e.g. "1042"
  const qty = parseInt(variables.get("quantity")); // parse it yourself
  console.log("keys:", Array.from(variables.keys()).join(", "));
  // ... work ...
  response.setResponse(JSON.stringify({ orderId, qty }));
}
```

> `variables` is a method-based accessor, not a plain object — `variables.orderId` and `variables["orderId"]` do not work. Always go through `variables.get("orderId")`.

## responseStream

Intermediate progress messages for **streaming executions only** — for example a script tool invoked inside a live agent conversation. Each message is emitted to the caller immediately, before the script finishes; the final result still comes from `response.setResponse(...)`.

  - `responseStream.addStreamMessage` — void"> Emits one streaming message tagged with the tool name and invocation id.

```javascript
responseStream.addStreamMessage("Fetching orders...");
const orders = JSON.parse(api.get(JSON.stringify({ endpoint: url })));
responseStream.addStreamMessage("Fetched " + orders.length + " orders, summarizing...");
```

**When the execution is not streaming, `responseStream` is not bound at all** — referencing it throws `ReferenceError: responseStream is not defined`. That includes computed columns and non-streaming tool runs. Guard if your script must work in both modes:

```javascript
if (typeof responseStream !== "undefined") {
  responseStream.addStreamMessage("working...");
}
```

## Related

- [The sandbox](/docs/autessascript/sandbox.md)
- [Computed columns](/docs/autessascript/computed-columns.md)
- [Examples](/docs/autessascript/examples.md)
- [AutessaScript overview](/docs/autessascript.md)

