Skip to main content
An agent invocation. Typically wraps the work to respond to a single user message. Emits an 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 tracing.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.

Examples

Properties

string
Read-only.
string
Read-only.

Methods

end()

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.

Parameters

SpanEndOptions

record()

Bulk-set any subset of the mutable fields. Replaces (does not merge). Useful for assigning everything at once after a provider call returns. The span is named from agentName when it starts, so pass agentName to startTurn if the name has to carry it. record still updates the field that end() writes to gen_ai.agent.name; it does not rename the span.

Parameters

object
required

Returns

this

setAttributes()

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

Parameters

Attributes
required

Returns

this

Examples

startLLM()

Start a child LLM span under this Turn.

Parameters

LLMInit
required
Type: LLMInit

Returns

LLM

startSubagent()

Start a child SubAgent span under this Turn.

Parameters

SubAgentInit
required

Returns

SubAgent

startTool()

Start a child Tool span under this Turn.

Parameters

ToolInit
required
Type: ToolInit

Returns

Tool
Last modified on September 30, 2026