-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Labels
Description
Describe the bug
Passing an AgentHooks
instance to the global hooks
parameter of Runner.run(...)
leads to a confusing runtime error. The runner expects RunHooks
, but there’s no runtime type check. As soon as the run invokes lifecycle callbacks, it either:
- raises AttributeError (missing
on_agent_start
), or - when those methods exist, raises TypeError at handoff because
RunHooks.on_handoff(context, from_agent, to_agent)
kwargs are used, which do not matchAgentHooks.on_handoff(context, agent, source)
.
This makes the failure mode opaque to users and hard to diagnose.
- Agents SDK version: 0.3.0 (from
/references/openai-agents-python-0.3.0
) - Python version: 3.13.5
Repro steps
- Minimal pure repro (no external frameworks), fully based on
/references
:- Run this script:
- What it does:
- Imports Agents SDK from
/references/openai-agents-python-0.3.0/src
and test helpers from/references/openai-agents-python-0.3.0/tests
to avoid model API calls. - Sets up two agents and a
FakeModel
that emits a handoff tool call. - Intentionally passes a subclass of
AgentHooks
toRunner.run(..., hooks=...)
so the run reaches the handoff and triggers the kwargs mismatch.
- Imports Agents SDK from
- Actual output:
- Raises:
TypeError: AgentHooksBase.on_handoff() got an unexpected keyword argument 'from_agent'
- Raises:

Expected behavior
- Either:
- A clear runtime error if the wrong hook type is supplied (e.g., “hooks must be RunHooks, got AgentHooks”), or
- Support both hook types (global and agent-scoped) in a way that avoids kwargs mismatch and confusing errors.