Skip to content

Commit 582e993

Browse files
committed
Add sugar to make the api less verbose
1 parent 6914c45 commit 582e993

5 files changed

Lines changed: 302 additions & 75 deletions

File tree

src/ai/agents/hooks.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,7 @@ async def _hook_impl(call: middleware_.HookContext) -> pydantic.BaseModel:
229229
)
230230

231231
await rt.put_hook(hook_part)
232-
sp.events.append(
233-
telemetry.SpanEvent(
234-
name=telemetry.HOOK_DEFERRED,
235-
time_ns=telemetry.now_ns(),
236-
attributes={},
237-
)
238-
)
232+
sp.add_event(telemetry.HOOK_DEFERRED)
239233
await sp.push()
240234

241235
# Await resolution — may be resolved externally or cancelled.
@@ -247,13 +241,7 @@ async def _hook_impl(call: middleware_.HookContext) -> pydantic.BaseModel:
247241
attrs: dict[str, Any] = {}
248242
if exc.args and exc.args[0] is not None:
249243
attrs["reason"] = exc.args[0]
250-
sp.events.append(
251-
telemetry.SpanEvent(
252-
name=telemetry.HOOK_CANCELLED,
253-
time_ns=telemetry.now_ns(),
254-
attributes=attrs,
255-
)
256-
)
244+
sp.add_event(telemetry.HOOK_CANCELLED, attrs)
257245
await sp.push()
258246
raise
259247
finally:
@@ -262,13 +250,7 @@ async def _hook_impl(call: middleware_.HookContext) -> pydantic.BaseModel:
262250

263251
sp.data.status = "resolved"
264252
sp.data.resolution = resolution
265-
sp.events.append(
266-
telemetry.SpanEvent(
267-
name=telemetry.HOOK_RESOLVED,
268-
time_ns=telemetry.now_ns(),
269-
attributes={},
270-
)
271-
)
253+
sp.add_event(telemetry.HOOK_RESOLVED)
272254
await sp.push()
273255

274256
# Emit resolved signal.

src/ai/experimental_telemetry/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
ToolExecutionSpanData,
2828
create_span,
2929
current,
30+
enabled,
3031
flush,
3132
now_ns,
33+
push_all,
3234
register,
3335
span,
3436
unregister,
@@ -60,8 +62,10 @@
6062
"ToolExecutionSpanData",
6163
"create_span",
6264
"current",
65+
"enabled",
6366
"flush",
6467
"now_ns",
68+
"push_all",
6569
"register",
6670
"span",
6771
"unregister",

0 commit comments

Comments
 (0)