Skip to content

MCQ 96 - Default Behavior of Runhooks and Agenthook

Question: What is the fundamental difference in execution behavior between RunHooks and AgentHooks when they are not explicitly configured on an agent?

Answer: D

Python
if hooks is None:
    hooks = RunHooks[Any]()

Python
await asyncio.gather(
    hooks.on_handoff(
        context=context_wrapper,
        from_agent=agent,
        to_agent=new_agent,
    ),
    (
        agent.hooks.on_handoff(
            context_wrapper,
            agent=new_agent,
            source=agent,
        )
        if agent.hooks
        else _coro.noop_coroutine()
    ),
)

Sources:

  • openai-agents-python/src/agents/run.py
  • openai-agents-python/src/agents/_run_impl.py

RunHooks are configured by default, AgentHooks are not configured by default.