> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-drtangible-wip-test-inline-tag.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# SubAgent

> TypeScript SDK reference

Defined in: [src/genai/subagent.ts:84](https://github.com/wandb/weave/blob/7c9efdc9fe05ffcaf2430dd652ef9bc5b3ffdfaa/sdks/node/src/genai/subagent.ts#L84)

## Extends

* `SpanBase`

## Accessors

### model

#### Get Signature

> **get** **model**(): `string`

Defined in: [src/genai/subagent.ts:101](https://github.com/wandb/weave/blob/7c9efdc9fe05ffcaf2430dd652ef9bc5b3ffdfaa/sdks/node/src/genai/subagent.ts#L101)

##### Returns

`string`

***

### name

#### Get Signature

> **get** **name**(): `string`

Defined in: [src/genai/subagent.ts:97](https://github.com/wandb/weave/blob/7c9efdc9fe05ffcaf2430dd652ef9bc5b3ffdfaa/sdks/node/src/genai/subagent.ts#L97)

##### Returns

`string`

## Methods

### ~~addEvent()~~

<Warning>
  **Deprecated.** Record this data via [setAttributes](#setattributes) instead.
  OpenTelemetry is phasing out the Span Event API (`Span.addEvent`). This
  method still works and existing span-event data stays valid.
  See [https://opentelemetry.io/blog/2026/deprecating-span-events/](https://opentelemetry.io/blog/2026/deprecating-span-events/)
</Warning>

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

Add a named event to the span. Useful for marking non-span moments such as
context compaction, tool-loop detection, or guardrail trips. Warns and
no-ops after `end()`. Mirrors OTel `Span.addEvent`.

Defined in: [src/genai/spanBase.ts:84](https://github.com/wandb/weave/blob/7c9efdc9fe05ffcaf2430dd652ef9bc5b3ffdfaa/sdks/node/src/genai/spanBase.ts#L84)

#### Parameters

##### name

`string`

##### attributes?

`Attributes`

##### startTime?

`TimeInput`

#### Returns

`this`

#### Example

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

#### Inherited from

`SpanBase.addEvent`

***

### end()

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

Read current field values (to reflect mutations made via `record()`
since `start`) and close the span. Idempotent. Pass `error` to mark
it as failed; pass `endTime` to backdate the close.

Defined in: [src/genai/subagent.ts:218](https://github.com/wandb/weave/blob/7c9efdc9fe05ffcaf2430dd652ef9bc5b3ffdfaa/sdks/node/src/genai/subagent.ts#L218)

#### Parameters

##### opts?

###### endTime?

`TimeInput`

###### error?

`Error`

#### Returns

`void`

***

### record()

> **record**(`opts`): `this`

Bulk-set any subset of the mutable fields. Replaces (does not merge).
Input and output messages are serialized when the span ends.

Defined in: [src/genai/subagent.ts:174](https://github.com/wandb/weave/blob/7c9efdc9fe05ffcaf2430dd652ef9bc5b3ffdfaa/sdks/node/src/genai/subagent.ts#L174)

#### Parameters

##### opts

###### agentDescription?

`string`

###### agentId?

`string`

###### agentVersion?

`string`

###### messages?

[`Message`](./message)\[]

###### model?

`string`

###### name?

`string`

###### outputMessages?

[`Message`](./message)\[]

###### systemInstructions?

`string`\[]

#### Returns

`this`

***

### setAttributes()

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

Set multiple attributes on the span at once. Warns and no-ops after
`end()`. Mirrors OTel `Span.setAttributes` (and the Python SDK's
`set_attributes`).

Defined in: [src/genai/spanBase.ts:65](https://github.com/wandb/weave/blob/7c9efdc9fe05ffcaf2430dd652ef9bc5b3ffdfaa/sdks/node/src/genai/spanBase.ts#L65)

#### Parameters

##### attributes

`Attributes`

#### Returns

`this`

#### Example

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

#### Inherited from

`SpanBase.setAttributes`

***

### startLLM()

> **startLLM**(`opts`): [`LLM`](./llm)

Start a child LLM span nested under this SubAgent.

Defined in: [src/genai/subagent.ts:141](https://github.com/wandb/weave/blob/7c9efdc9fe05ffcaf2430dd652ef9bc5b3ffdfaa/sdks/node/src/genai/subagent.ts#L141)

#### Parameters

##### opts

[`LLMInit`](./llminit)

#### Returns

[`LLM`](./llm)

***

### startSubagent()

> **startSubagent**(`opts`): `SubAgent`

Start a nested SubAgent span under this SubAgent.

Defined in: [src/genai/subagent.ts:161](https://github.com/wandb/weave/blob/7c9efdc9fe05ffcaf2430dd652ef9bc5b3ffdfaa/sdks/node/src/genai/subagent.ts#L161)

#### Parameters

##### opts

[`SubAgentInit`](./subagentinit)

#### Returns

`SubAgent`

***

### startTool()

> **startTool**(`opts`): [`Tool`](./tool)

Start a child Tool span nested under this SubAgent.

Defined in: [src/genai/subagent.ts:151](https://github.com/wandb/weave/blob/7c9efdc9fe05ffcaf2430dd652ef9bc5b3ffdfaa/sdks/node/src/genai/subagent.ts#L151)

#### Parameters

##### opts

[`ToolInit`](./toolinit)

#### Returns

[`Tool`](./tool)
