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

# Class: Tool

> TypeScript SDK reference

[weave](../) / Tool

A tool invocation. Emits an `execute_tool` span carrying the tool name,
the JSON-encoded arguments, the tool-call id, and the result.

Created by `weave.startTool()` (or `turn.startTool()`, or
`llm.startTool()`) and terminated with `end()`. Assign `result` before
calling `end()` to record the tool's output on the span.

`Example`

```ts theme={null}
const tool = weave.startTool({
  name: tc.function.name,
  args: tc.function.arguments,
  toolCallId: tc.id,
});
try {
  tool.result = await wikipediaSearch(JSON.parse(tc.function.arguments));
} finally {
  tool.end();
}
```

## Table of contents

### Properties

* [args](./tool#args)
* [name](./tool#name)
* [result](./tool#result)
* [toolCallId](./tool#toolcallid)

### Methods

* [end](./tool#end)
* [create](./tool#create)

## Properties

### args

• `Readonly` **args**: `string`

#### Defined in

[genai/tool.ts:52](https://github.com/wandb/weave/blob/6538626556c93d6f31ae725fdefe4e6b8b71bc2c/sdks/node/src/genai/tool.ts#L52)

***

### name

• `Readonly` **name**: `string`

#### Defined in

[genai/tool.ts:51](https://github.com/wandb/weave/blob/6538626556c93d6f31ae725fdefe4e6b8b71bc2c/sdks/node/src/genai/tool.ts#L51)

***

### result

• `Optional` **result**: `string`

Tool output as a string. Recorded on `gen_ai.tool.call.result` at `end()`.

#### Defined in

[genai/tool.ts:45](https://github.com/wandb/weave/blob/6538626556c93d6f31ae725fdefe4e6b8b71bc2c/sdks/node/src/genai/tool.ts#L45)

***

### toolCallId

• `Readonly` **toolCallId**: `string`

#### Defined in

[genai/tool.ts:53](https://github.com/wandb/weave/blob/6538626556c93d6f31ae725fdefe4e6b8b71bc2c/sdks/node/src/genai/tool.ts#L53)

## Methods

### end

▸ **end**(`opts?`): `void`

Flush `result` to the span and close it. Idempotent. Pass `error` to
mark the span as failed.

#### Parameters

| Name          | Type     |
| :------------ | :------- |
| `opts?`       | `Object` |
| `opts.error?` | `Error`  |

#### Returns

`void`

#### Defined in

[genai/tool.ts:83](https://github.com/wandb/weave/blob/6538626556c93d6f31ae725fdefe4e6b8b71bc2c/sdks/node/src/genai/tool.ts#L83)

***

### create

▸ **create**(`opts`): [`Tool`](./tool)

#### Parameters

| Name   | Type                                                      |
| :----- | :-------------------------------------------------------- |
| `opts` | [`ToolInit`](../interfaces/toolinit) & `ChildSpanContext` |

#### Returns

[`Tool`](./tool)

#### Defined in

[genai/tool.ts:56](https://github.com/wandb/weave/blob/6538626556c93d6f31ae725fdefe4e6b8b71bc2c/sdks/node/src/genai/tool.ts#L56)
