> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# begin()

> **begin**(`input`, `options?`): [`HarnessSpeculativeTurn`](/docs/agent-sdk/harness-sdk/harness/begin#harnessspeculativeturn)\<[`HarnessTurnResult`](/docs/agent-sdk/harness-sdk/harness/turn#harnessturnresult)\<`HarnessParsedOutput`\<`OutputDefinition`>>>

Start a provisional streaming direct turn, with no writes or tools until commitment.

**Parameters**

| Parameter | Type |
| - | - |
| `input` | `string` |
| `options?` | [`HarnessTurnOptions`](/docs/agent-sdk/harness-sdk/harness/turn#harnessturnoptions)\<`TOOLS`, `OutputDefinition`> |

**Returns**
[`HarnessSpeculativeTurn`](/docs/agent-sdk/harness-sdk/harness/begin#harnessspeculativeturn)\<[`HarnessTurnResult`](/docs/agent-sdk/harness-sdk/harness/turn#harnessturnresult)\<`HarnessParsedOutput`\<`OutputDefinition`>>>

## HarnessSpeculativeTurn

One speculative direct turn. Text is provisional until commit succeeds.

**Type Parameters**

| Type Parameter | Default type |
| - | - |
|  `Result` | \{ `text`: `string`; } |

**Properties**
**result**

> `readonly` **result**: `Promise`\<`Result`>

Observed internally even when a caller discards without awaiting it.

**textStream**

> `readonly` **textStream**: `AsyncIterable`\<`string`>

Single-consumer, provisional text. Consuming it must not cause persistent effects.

**Methods**
**commit()**

> **commit**(`confirmed`): `Promise`\<`Result`>

First decision wins. Same text returns the same promise; different text rejects.

**Parameters**

| Parameter | Type |
| - | - |
| `confirmed` | `string` |

**Returns**
`Promise`\<`Result`>

**discard()**

> **discard**(): `boolean`

True for a discarded turn (including repeats), false after commit won.

**Returns**
`boolean`

## HarnessSpeculationConflictError

In-memory ownership and commitment; never opens a storage transaction.

**Constructors**
**Constructor**

> **new HarnessSpeculationConflictError**(): `HarnessSpeculationConflictError`

**Returns**
`HarnessSpeculationConflictError`

**Properties**
**cause?**

> `optional` **cause?**: `unknown`

**code**

> `readonly` **code**: `"HARNESS_SPECULATION_CONFLICT"`

**message**

> **message**: `string`

**name**

> **name**: `string`

**stack?**

> `optional` **stack?**: `string`

**stackTraceLimit**

> `static` **stackTraceLimit**: `number`

The `Error.stackTraceLimit` property specifies the number of stack frames
collected by a stack trace (whether generated by `new Error().stack` or
`Error.captureStackTrace(obj)`).

The default value is `10` but may be set to any valid JavaScript number. Changes
will affect any stack trace captured *after* the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will
not capture any frames.

**Methods**
**captureStackTrace()**

> `static` **captureStackTrace**(`targetObject`, `constructorOpt?`): `void`

Creates a `.stack` property on `targetObject`, which when accessed returns
a string representing the location in the code at which
`Error.captureStackTrace()` was called.

```js theme={null}
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`
```

The first line of the trace will be prefixed with
`${myObject.name}: ${myObject.message}`.

The optional `constructorOpt` argument accepts a function. If given, all frames
above `constructorOpt`, including `constructorOpt`, will be omitted from the
generated stack trace.

The `constructorOpt` argument is useful for hiding implementation
details of error generation from the user. For instance:

```js theme={null}
function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();
```

**Parameters**

| Parameter | Type |
| - | - |
| `targetObject` | `object` |
| `constructorOpt?` | `Function` |

**Returns**
`void`

**prepareStackTrace()**

> `static` **prepareStackTrace**(`err`, `stackTraces`): `any`

**Parameters**

| Parameter | Type |
| - | - |
| `err` | `Error` |
| `stackTraces` | `CallSite`\[] |

**Returns**
`any`

**See**
[https://v8.dev/docs/stack-trace-api#customizing-stack-traces](https://v8.dev/docs/stack-trace-api#customizing-stack-traces)

## HarnessSpeculationUnsupportedError

**Constructors**
**Constructor**

> **new HarnessSpeculationUnsupportedError**(`detail`): `HarnessSpeculationUnsupportedError`

**Parameters**

| Parameter | Type |
| - | - |
| `detail` | `string` |

**Returns**
`HarnessSpeculationUnsupportedError`

**Properties**
**cause?**

> `optional` **cause?**: `unknown`

**code**

> `readonly` **code**: `"HARNESS_SPECULATION_UNSUPPORTED"`

**message**

> **message**: `string`

**name**

> **name**: `string`

**stack?**

> `optional` **stack?**: `string`

**stackTraceLimit**

> `static` **stackTraceLimit**: `number`

The `Error.stackTraceLimit` property specifies the number of stack frames
collected by a stack trace (whether generated by `new Error().stack` or
`Error.captureStackTrace(obj)`).

The default value is `10` but may be set to any valid JavaScript number. Changes
will affect any stack trace captured *after* the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will
not capture any frames.

**Methods**
**captureStackTrace()**

> `static` **captureStackTrace**(`targetObject`, `constructorOpt?`): `void`

Creates a `.stack` property on `targetObject`, which when accessed returns
a string representing the location in the code at which
`Error.captureStackTrace()` was called.

```js theme={null}
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`
```

The first line of the trace will be prefixed with
`${myObject.name}: ${myObject.message}`.

The optional `constructorOpt` argument accepts a function. If given, all frames
above `constructorOpt`, including `constructorOpt`, will be omitted from the
generated stack trace.

The `constructorOpt` argument is useful for hiding implementation
details of error generation from the user. For instance:

```js theme={null}
function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();
```

**Parameters**

| Parameter | Type |
| - | - |
| `targetObject` | `object` |
| `constructorOpt?` | `Function` |

**Returns**
`void`

**prepareStackTrace()**

> `static` **prepareStackTrace**(`err`, `stackTraces`): `any`

**Parameters**

| Parameter | Type |
| - | - |
| `err` | `Error` |
| `stackTraces` | `CallSite`\[] |

**Returns**
`any`

**See**
[https://v8.dev/docs/stack-trace-api#customizing-stack-traces](https://v8.dev/docs/stack-trace-api#customizing-stack-traces)
