> ## 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.

# 클래스: SubAgent

> TypeScript SDK 레퍼런스

[weave](../) / SubAgent

중첩된 에이전트 호출입니다. 현재 에이전트가 작업을
이름이 지정된 다른 에이전트에 넘길 때 사용됩니다
(예: planner가 researcher에게 작업을 넘기는 경우). 하위 에이전트의 이름과
(선택적으로) 모델이 태그된
`invoke_agent` span을 생성합니다.

`weave.startSubagent()`(또는 `turn.startAgent()`, 또는
`llm.startAgent()`)로 생성되며, `end()`로 종료됩니다.

`예시`

```ts twoslash theme={null}
// @noErrors
const sub = weave.startSubagent({name: 'researcher', model: 'gpt-4o'});
try {
  // ... 서브 에이전트의 LLM/Tool Call을 조율합니다 ...
} finally {
  sub.end();
}
```

<div id="hierarchy">
  ## 계층 구조
</div>

* `SpanBase`

  ↳ `SubAgent`

<div id="table-of-contents">
  ## 목차
</div>

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

* [모델](./subagent#model)
* [이름](./subagent#name)

<div id="methods">
  ### 방법
</div>

* [addEvent](./subagent#addevent)
* [end](./subagent#end)
* [setAttributes](./subagent#setattributes)
* [create](./subagent#create)

## 속성

<div id="model">
  ### 모델
</div>

• `Readonly` **모델**: `string`

<div id="defined-in">
  #### 정의 위치
</div>

[src/genai/subagent.ts:41](https://github.com/wandb/weave/blob/9591aba8a5e77309ee0858e5ba94d31c1bd7e404/sdks/node/src/genai/subagent.ts#L41)

***

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

• `Readonly` **이름**: `string`

<div id="defined-in">
  #### 정의 위치
</div>

[src/genai/subagent.ts:40](https://github.com/wandb/weave/blob/9591aba8a5e77309ee0858e5ba94d31c1bd7e404/sdks/node/src/genai/subagent.ts#L40)

## 방법

<div id="addevent">
  ### addEvent
</div>

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

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

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

| 이름            | 유형           |
| :------------ | :----------- |
| `name`        | `string`     |
| `attributes?` | `Attributes` |
| `startTime?`  | `TimeInput`  |

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

`this`

`예시`

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

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

SpanBase.addEvent

<div id="defined-in">
  #### 정의 위치
</div>

[src/genai/spanBase.ts:77](https://github.com/wandb/weave/blob/9591aba8a5e77309ee0858e5ba94d31c1bd7e404/sdks/node/src/genai/spanBase.ts#L77)

***

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

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

SubAgent span을 종료합니다. 멱등성을 가집니다. 실패로 표시하려면 `error`를 전달하세요;
종료 시점을 이전으로 소급하려면 `endTime`을 전달하세요.

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

| 이름      | 유형               |
| :------ | :--------------- |
| `opts?` | `SpanEndOptions` |

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

`void`

<div id="defined-in">
  #### 정의 위치
</div>

[src/genai/subagent.ts:72](https://github.com/wandb/weave/blob/9591aba8a5e77309ee0858e5ba94d31c1bd7e404/sdks/node/src/genai/subagent.ts#L72)

***

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

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

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

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

| 이름           | 유형           |
| :----------- | :----------- |
| `attributes` | `Attributes` |

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

`this`

`예시`

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

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

SpanBase.setAttributes

<div id="defined-in">
  #### 정의 위치
</div>

[src/genai/spanBase.ts:63](https://github.com/wandb/weave/blob/9591aba8a5e77309ee0858e5ba94d31c1bd7e404/sdks/node/src/genai/spanBase.ts#L63)

***

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

▸ **create**(`opts`): [`SubAgent`](./subagent)

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

| 이름     | 유형                                                                |
| :----- | :---------------------------------------------------------------- |
| `opts` | [`SubAgentInit`](../interfaces/subagentinit) & `ChildSpanContext` |

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

[`SubAgent`](./subagent)

<div id="defined-in">
  #### 정의 위치
</div>

[src/genai/subagent.ts:46](https://github.com/wandb/weave/blob/9591aba8a5e77309ee0858e5ba94d31c1bd7e404/sdks/node/src/genai/subagent.ts#L46)
