Skip to content

Commit 84fb734

Browse files
authoredApr 9, 2025
Adding scope and span_data doc strings (#463)
Built docs and tested outputs locally
1 parent d089886 commit 84fb734

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
 

‎src/agents/tracing/scope.py

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919

2020
class Scope:
21+
"""
22+
Manages the current span and trace in the context.
23+
"""
24+
2125
@classmethod
2226
def get_current_span(cls) -> "Span[Any] | None":
2327
return _current_span.get()

‎src/agents/tracing/span_data.py

+60
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,28 @@
99

1010

1111
class SpanData(abc.ABC):
12+
"""
13+
Represents span data in the trace.
14+
"""
15+
1216
@abc.abstractmethod
1317
def export(self) -> dict[str, Any]:
18+
"""Export the span data as a dictionary."""
1419
pass
1520

1621
@property
1722
@abc.abstractmethod
1823
def type(self) -> str:
24+
"""Return the type of the span."""
1925
pass
2026

2127

2228
class AgentSpanData(SpanData):
29+
"""
30+
Represents an Agent Span in the trace.
31+
Includes name, handoffs, tools, and output type.
32+
"""
33+
2334
__slots__ = ("name", "handoffs", "tools", "output_type")
2435

2536
def __init__(
@@ -49,6 +60,11 @@ def export(self) -> dict[str, Any]:
4960

5061

5162
class FunctionSpanData(SpanData):
63+
"""
64+
Represents a Function Span in the trace.
65+
Includes input, output and MCP data (if applicable).
66+
"""
67+
5268
__slots__ = ("name", "input", "output", "mcp_data")
5369

5470
def __init__(
@@ -78,6 +94,11 @@ def export(self) -> dict[str, Any]:
7894

7995

8096
class GenerationSpanData(SpanData):
97+
"""
98+
Represents a Generation Span in the trace.
99+
Includes input, output, model, model configuration, and usage.
100+
"""
101+
81102
__slots__ = (
82103
"input",
83104
"output",
@@ -116,6 +137,11 @@ def export(self) -> dict[str, Any]:
116137

117138

118139
class ResponseSpanData(SpanData):
140+
"""
141+
Represents a Response Span in the trace.
142+
Includes response and input.
143+
"""
144+
119145
__slots__ = ("response", "input")
120146

121147
def __init__(
@@ -140,6 +166,11 @@ def export(self) -> dict[str, Any]:
140166

141167

142168
class HandoffSpanData(SpanData):
169+
"""
170+
Represents a Handoff Span in the trace.
171+
Includes source and desitnation agents.
172+
"""
173+
143174
__slots__ = ("from_agent", "to_agent")
144175

145176
def __init__(self, from_agent: str | None, to_agent: str | None):
@@ -159,6 +190,11 @@ def export(self) -> dict[str, Any]:
159190

160191

161192
class CustomSpanData(SpanData):
193+
"""
194+
Represents a Custom Span in the trace.
195+
Includes name and data property bag.
196+
"""
197+
162198
__slots__ = ("name", "data")
163199

164200
def __init__(self, name: str, data: dict[str, Any]):
@@ -178,6 +214,11 @@ def export(self) -> dict[str, Any]:
178214

179215

180216
class GuardrailSpanData(SpanData):
217+
"""
218+
Represents a Guardrail Span in the trace.
219+
Includes name and triggered status.
220+
"""
221+
181222
__slots__ = ("name", "triggered")
182223

183224
def __init__(self, name: str, triggered: bool = False):
@@ -197,6 +238,11 @@ def export(self) -> dict[str, Any]:
197238

198239

199240
class TranscriptionSpanData(SpanData):
241+
"""
242+
Represents a Transcription Span in the trace.
243+
Includes input, output, model, and model configuration.
244+
"""
245+
200246
__slots__ = (
201247
"input",
202248
"output",
@@ -236,6 +282,11 @@ def export(self) -> dict[str, Any]:
236282

237283

238284
class SpeechSpanData(SpanData):
285+
"""
286+
Represents a Speech Span in the trace.
287+
Includes input, output, model, model configuration, and first content timestamp.
288+
"""
289+
239290
__slots__ = ("input", "output", "model", "model_config", "first_content_at")
240291

241292
def __init__(
@@ -273,6 +324,10 @@ def export(self) -> dict[str, Any]:
273324

274325

275326
class SpeechGroupSpanData(SpanData):
327+
"""
328+
Represents a Speech Group Span in the trace.
329+
"""
330+
276331
__slots__ = "input"
277332

278333
def __init__(
@@ -293,6 +348,11 @@ def export(self) -> dict[str, Any]:
293348

294349

295350
class MCPListToolsSpanData(SpanData):
351+
"""
352+
Represents an MCP List Tools Span in the trace.
353+
Includes server and result.
354+
"""
355+
296356
__slots__ = (
297357
"server",
298358
"result",

0 commit comments

Comments
 (0)