chat span with gen_ai.* attributes.
Created by weave.startLLM() (or turn.startLLM()) and terminated with
end(). Only one LLM may be active in an async context at a time; nest
tool/subagent calls under it via startTool / startSubagent.
Populate inputMessages / outputMessages / usage / reasoning directly,
or via the helper functions (output, think, attachMedia, record).
All recorded data is flushed to the span at end().
Example
Table of contents
Properties
Methods
Properties
inputMessages
• inputMessages:Message[] = []
Input messages sent to the model. Flushed to gen_ai.input.messages on
end().
Defined in
genai/llm.ts:78model
•Readonly model: string
Defined in
genai/llm.ts:98outputMessages
• outputMessages:Message[] = []
Assistant messages returned by the model. Flushed to
gen_ai.output.messages on end().
Defined in
genai/llm.ts:83providerName
•Readonly providerName: string
Defined in
genai/llm.ts:99reasoning
•Optional reasoning: Reasoning
Chain-of-thought content. Folded into the last assistant message as a
ReasoningPart at serialization time.
Defined in
genai/llm.ts:90usage
• usage:Usage = {}
Token counts and cache stats. Flushed to gen_ai.usage.* on end().
Defined in
genai/llm.ts:85Methods
attachMedia
▸ attachMedia(opts): this
Attach a media part to the last input message. Pick exactly one of
content (inline base64 bytes), uri (URI reference), or fileId
(pre-uploaded file id).
Parameters
| Name | Type |
|---|---|
opts | AttachMediaOpts |
Returns
this
Defined in
genai/llm.ts:168attachMediaUrl
▸ attachMediaUrl(url, opts): this
Convenience for attachMedia({uri, modality}).
Parameters
| Name | Type |
|---|---|
url | string |
opts | Object |
opts.modality | Modality |
Returns
this
Defined in
genai/llm.ts:186end
▸ end(opts?): void
Flush accumulated state to the span and close it. Idempotent. Pass
error to mark the span as failed.
Parameters
| Name | Type |
|---|---|
opts? | Object |
opts.error? | Error |
Returns
void
Defined in
genai/llm.ts:246output
▸ output(content): this
Append an assistant message to the response.
Parameters
| Name | Type |
|---|---|
content | string |
Returns
this
Defined in
genai/llm.ts:141record
▸ record(opts): this
Bulk-set any subset of the mutable fields. Replaces (does not merge).
Useful for assigning everything at once after a provider call returns.
Parameters
| Name | Type |
|---|---|
opts | LLMRecordOpts |
Returns
this
Defined in
genai/llm.ts:197startSubagent
▸ startSubagent(opts): SubAgent
Start a child SubAgent span nested under this LLM.
Parameters
| Name | Type |
|---|---|
opts | SubAgentInit |
Returns
SubAgent
Defined in
genai/llm.ts:230startTool
▸ startTool(opts): Tool
Start a child Tool span nested under this LLM.
Parameters
| Name | Type |
|---|---|
opts | ToolInit |
Returns
Tool
Defined in
genai/llm.ts:221think
▸ think(content): this
Set or extend the model’s reasoning/chain-of-thought content. Accumulates
into this.reasoning.content. Folded into the last assistant message as
a ReasoningPart at serialization time, matching the Python SDK’s
on-the-wire shape.
Parameters
| Name | Type |
|---|---|
content | string |
Returns
this
Defined in
genai/llm.ts:153create
▸ create(opts): LLM
Parameters
| Name | Type |
|---|---|
opts | LLMInit & ChildSpanContext |
Returns
LLM