-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Labels
needs-more-infoWaiting for a reply/more info from the authorWaiting for a reply/more info from the authorquestionQuestion about using the SDKQuestion about using the SDK
Description
Please read this first
- Have you read the docs? Agents SDK docs
- Have you searched for related issues? Others may have had similar requests
Describe the feature
Feature
Add two optional async methods to RunHooksBase:
async def on_run_start(
context: RunContextWrapper[TContext]
) -> None:
...
async def on_run_end(
context: RunContextWrapper[TContext],
result: Optional[Any],
) -> None:
...Called exactly once per run (before first agent starts; after final agent finishes).
Why
Current hooks are per-agent or per-tool. Missing global boundaries makes it hard to:
- Start/end a root trace span
- Capture total run latency and aggregated metrics
- Initialize and tear down shared resources
- Emit a single audit/compliance record
Although it is technically possible to simulate run-level start/end by calling custom pre/post functions outside Runner.run(), that splits lifecycle logic across two places: global boundaries outside the runner and per‑agent/tool events inside hooks.
First‑class on_run_start/ on_run_end centralizes all lifecycle concerns in one hooks class, and keeps instrumentation symmetrical.
Metadata
Metadata
Assignees
Labels
needs-more-infoWaiting for a reply/more info from the authorWaiting for a reply/more info from the authorquestionQuestion about using the SDKQuestion about using the SDK