invoke_agent span and acts as the root of the
trace for that turn: it is always started under ROOT_CONTEXT so it
never accidentally inherits a parent from another OTel-instrumented
library.
Created by weave.startTurn() (or session.startTurn()) and
terminated with end(). Only one Turn may be active in an async chain.
Children (LLM, Tool, SubAgent) attach via the startLLM, startTool,
startSubagent methods.
Example
Table of contents
Properties
Methods
Properties
agentName
•Readonly agentName: string
Defined in
genai/turn.ts:60model
•Readonly model: string
Defined in
genai/turn.ts:61Methods
addEvent
▸ addEvent(name, attributes?, startTime?): this
Add a named event to the Turn span. Useful for marking non-span moments
such as context compaction, tool-loop detection, or guardrail trips.
No-op after end(). Mirrors OTel Span.addEvent.
Parameters
| Name | Type |
|---|---|
name | string |
attributes? | Attributes |
startTime? | TimeInput |
Returns
this
Example
Defined in
genai/turn.ts:152end
▸ end(opts?): void
Close the Turn span. Idempotent. Pass error to mark it as failed.
Parameters
| Name | Type |
|---|---|
opts? | Object |
opts.error? | Error |
Returns
void
Defined in
genai/turn.ts:159setAttribute
▸ setAttribute(key, value): this
Set a single attribute on the Turn span. Useful for stamping running
totals (e.g. cumulative cost, token usage) or other metadata that becomes
known mid-turn. No-op after end(). Mirrors OTel Span.setAttribute.
Parameters
| Name | Type |
|---|---|
key | string |
value | AttributeValue |
Returns
this
Example
Defined in
genai/turn.ts:138startLLM
▸ startLLM(opts): LLM
Start a child LLM span under this Turn.
Parameters
| Name | Type |
|---|---|
opts | LLMInit |
Returns
LLM
Defined in
genai/turn.ts:104startSubagent
▸ startSubagent(opts): SubAgent
Start a child SubAgent span under this Turn.
Parameters
| Name | Type |
|---|---|
opts | SubAgentInit |
Returns
SubAgent
Defined in
genai/turn.ts:122startTool
▸ startTool(opts): Tool
Start a child Tool span under this Turn.
Parameters
| Name | Type |
|---|---|
opts | ToolInit |
Returns
Tool
Defined in
genai/turn.ts:113create
▸ create(opts?): Turn
Parameters
| Name | Type |
|---|---|
opts | TurnInit & { conversationId?: string } |
Returns
Turn