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 conversation.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.
Defined in: src/genai/turn.ts:98
Examples
Extends
SpanBase
Accessors
agentName
Get Signature
get agentName(): string
Defined in: src/genai/turn.ts:111
Returns
string
model
Get Signature
get model(): string
Defined in: src/genai/turn.ts:115
Returns
string
Methods
addEvent()
addEvent(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 aftername,attributes?,startTime?):this
end(). Mirrors OTel Span.addEvent.
Defined in: src/genai/spanBase.ts:84
Parameters
name
string
attributes?
Attributes
startTime?
TimeInput
Returns
this
Example
Inherited from
SpanBase.addEvent
end()
end(Read current field values (to reflect mutations made viaopts?):void
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/turn.ts:257
Parameters
opts?
endTime?
TimeInput
error?
Error
Returns
void
record()
record(Bulk-set any subset of the mutable fields. Replaces (does not merge). Useful for assigning everything at once after a provider call returns. Defined in: src/genai/turn.ts:213opts):this
Parameters
opts
agentDescription?
string
agentId?
string
agentName?
string
agentVersion?
string
messages?
Message[]
model?
string
outputMessages?
Message[]
systemInstructions?
string[]
Returns
this
setAttribute()
setAttribute(Defined in: src/genai/turn.ts:205key,value):this
Parameters
key
string
value
AttributeValue
Returns
this
setAttributes()
setAttributes(Set multiple attributes on the span at once. Warns and no-ops afterattributes):this
end(). Mirrors OTel Span.setAttributes (and the Python SDK’s
set_attributes).
Defined in: src/genai/spanBase.ts:65
Parameters
attributes
Attributes
Returns
this
Example
Inherited from
SpanBase.setAttributes
startLLM()
startLLM(Start a child LLM span under this Turn. Defined in: src/genai/turn.ts:170opts):LLM
Parameters
opts
LLMInit
Returns
LLM
startSubagent()
startSubagent(Start a child SubAgent span under this Turn. Defined in: src/genai/turn.ts:190opts):SubAgent
Parameters
opts
SubAgentInit
Returns
SubAgent
startTool()
startTool(Start a child Tool span under this Turn. Defined in: src/genai/turn.ts:180opts):Tool
Parameters
opts
ToolInit
Returns
Tool