A tool invocation. Emits an execute_tool span carrying the tool name,
the arguments, the tool-call id, and the result. String arguments and
results are recorded as-is; other JSON values are serialized.
Created by weave.startTool() (or turn.startTool(), or
llm.startTool()) and terminated with end(), which accepts the result and
optional error metadata.
Defined in: src/genai/tool.ts:65
Example
Extends
Properties
args
readonly args: string
Defined in: src/genai/tool.ts:76
name
readonly name: string
Defined in: src/genai/tool.ts:75
result
Deprecated. Pass result to end() instead.
optional result: string
Tool output as a string. Prefer passing result to end().
Defined in: src/genai/tool.ts:71
readonly toolCallId: string
Defined in: src/genai/tool.ts:77
Methods
addEvent()
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
Parameters
name
string
attributes?
Attributes
startTime?
TimeInput
Returns
this
Example
Inherited from
SpanBase.addEvent
end()
end(opts?): void
Record an optional result and error type, then close the span. Idempotent.
Pass error to mark the span as failed and endTime to backdate the close.
Defined in: src/genai/tool.ts:111
Parameters
opts?
ToolEndOptions
Returns
void
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
Parameters
attributes
Attributes
Returns
this
Example
Inherited from
SpanBase.setAttributes