> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-locadex-parallel-t9n-main-cs60c8p4o6ik99tylxgp3.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Tool

> TypeScript SDK 레퍼런스

export const GitHubLink = ({url, compact = false}) => <a href={url} target="_blank" rel="noopener noreferrer" className={compact ? "source-link" : "github-source-link"}>
    {compact ? "소스 보기" : <>
    <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
      <path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z" />
    </svg>
    GitHub 소스 코드
      </>}
  </a>;

<GitHubLink url="https://github.com/wandb/weave/blob/7c9efdc9fe05ffcaf2430dd652ef9bc5b3ffdfaa/sdks/node/src/genai/tool.ts#L65" />

도구 호출입니다. 도구 이름, 인수, 도구 호출 id, 결과를 담은 `execute_tool` span을 생성합니다. string 인수와 결과는 그대로 기록되며, 그 외의 JSON 값은 직렬화됩니다.

`weave.startTool()`(또는 `turn.startTool()`, `llm.startTool()`)로 생성되며, 결과와 선택적 오류 메타데이터를 받는 `end()`로 종료됩니다.

<div id="example">
  ## 예시
</div>

```ts twoslash theme={null}
// @noErrors
const tool = weave.startTool({name: 'get_weather', args: {city: 'Tokyo'}});
try {
  const result = await getWeather('Tokyo');
  tool.end({result});
} catch (error) {
  tool.end({error: error as Error, errorType: 'weather_error'});
  throw error;
}
```

<div id="extends">
  ## 상속
</div>

* `SpanBase`

<div id="properties">
  ## 속성
</div>

<div id="args">
  ### args
</div>

> `readonly` **args**: `string`

***

<div id="name">
  ### name
</div>

> `readonly` **name**: `string`

***

<div id="result">
  ### ~~result~~
</div>

<Warning>
  **사용 중단.** 대신 `result`를 `end()`에 전달하세요.
</Warning>

> `선택` **result**: `string`

string 형식의 도구 출력입니다. `result`는 `end()`에 전달하는 방식을 사용하세요.

***

<div id="toolcallid">
  ### toolCallId
</div>

> `readonly` **toolCallId**: `string`

<div id="methods">
  ## 메서드
</div>

<div id="addevent">
  ### ~~addEvent()~~
</div>

<Warning>
  **사용 중단.** 대신 [setAttributes](#setattributes)로 이 데이터를 기록하세요.
  OpenTelemetry는 Span Event API(`Span.addEvent`)를 단계적으로 폐지하고 있습니다. 이
  방법은 계속 작동하며 기존 span-event 데이터도 유효합니다.
  [https://opentelemetry.io/blog/2026/deprecating-span-events/](https://opentelemetry.io/blog/2026/deprecating-span-events/)를 참조하세요.
</Warning>

> **addEvent**(`name`, `attributes?`, `startTime?`): `this`

span에 이름이 지정된 이벤트를 추가합니다. 컨텍스트 압축, 도구 루프 감지 또는
가드레일 위반과 같이 span이 아닌 시점을 표시할 때 유용합니다. `end()` 호출 후에는 경고를 표시하고
아무 작업도 수행하지 않습니다. OTel `Span.addEvent`와 동일하게 동작합니다.

<div id="parameters">
  #### 매개변수
</div>

<ParamField path="name" type="string" required />

<ParamField path="attributes" type="Attributes" />

<ParamField path="startTime" type="TimeInput" />

<div id="returns">
  #### 반환값
</div>

`this`

<div id="example-2">
  #### 예시
</div>

```ts twoslash theme={null}
// @noErrors
span.addEvent('context_compacted', {removedMessages: 12});
```

<div id="inherited-from">
  #### 상속됨
</div>

`SpanBase.addEvent`

***

<div id="end">
  ### end()
</div>

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

선택적으로 결과와 오류 유형을 기록한 뒤 span을 종료합니다. 여러 번 호출해도 동일하게 동작합니다.
span을 실패로 표시하려면 `error`를, 종료 시점을 과거로 설정하려면 `endTime`을 전달하세요.

<div id="parameters-2">
  #### 매개변수
</div>

<ParamField path="opts" type="ToolEndOptions">
  [`ToolEndOptions`](./toolendoptions)를 참조하세요.
</ParamField>

<div id="returns-2">
  #### 반환값
</div>

`void`

***

<div id="setattributes">
  ### setAttributes()
</div>

> **setAttributes**(`attributes`): `this`

span에 여러 속성을 한 번에 설정합니다. `end()` 호출 후에는 경고를 표시하고
아무 작업도 수행하지 않습니다. OTel `Span.setAttributes` 및 Python SDK의
`set_attributes`와 동일하게 동작합니다.

<div id="parameters-3">
  #### 매개변수
</div>

<ParamField path="attributes" type="Attributes" required />

<div id="returns-3">
  #### 반환값
</div>

`this`

<div id="example-3">
  #### 예시
</div>

```ts twoslash theme={null}
// @noErrors
span.setAttributes({'weave.tag': 'prod', 'gen_ai.response.id': id});
```

<div id="inherited-from-2">
  #### 상속됨
</div>

`SpanBase.setAttributes`
