diff --git a/src/agents/_run_impl.py b/src/agents/_run_impl.py index 4ac8b316b..3a6d7d3e3 100644 --- a/src/agents/_run_impl.py +++ b/src/agents/_run_impl.py @@ -553,9 +553,9 @@ async def run_single_tool( span_fn.span_data.input = tool_call.arguments try: _, _, result = await asyncio.gather( - hooks.on_tool_start(tool_context, agent, func_tool), + hooks.on_tool_start(context=tool_context, agent=agent, tool=func_tool), ( - agent.hooks.on_tool_start(tool_context, agent, func_tool) + agent.hooks.on_tool_start(context=tool_context, agent=agent, tool=func_tool) if agent.hooks else _coro.noop_coroutine() ), @@ -563,9 +563,9 @@ async def run_single_tool( ) await asyncio.gather( - hooks.on_tool_end(tool_context, agent, func_tool, result), + hooks.on_tool_end(context=tool_context, agent=agent, tool=func_tool, result=result), ( - agent.hooks.on_tool_end(tool_context, agent, func_tool, result) + agent.hooks.on_tool_end(context=tool_context, agent=agent, tool=func_tool, result=result) if agent.hooks else _coro.noop_coroutine() ), @@ -874,8 +874,8 @@ async def run_final_output_hooks( final_output: Any, ): await asyncio.gather( - hooks.on_agent_end(context_wrapper, agent, final_output), - agent.hooks.on_end(context_wrapper, agent, final_output) + hooks.on_agent_end(context=context_wrapper, agent=agent, output=final_output), + agent.hooks.on_end(context=context_wrapper, agent=agent, output=final_output) if agent.hooks else _coro.noop_coroutine(), ) @@ -1035,9 +1035,9 @@ async def execute( ) _, _, output = await asyncio.gather( - hooks.on_tool_start(context_wrapper, agent, action.computer_tool), + hooks.on_tool_start(context=context_wrapper, agent=agent, tool=action.computer_tool), ( - agent.hooks.on_tool_start(context_wrapper, agent, action.computer_tool) + agent.hooks.on_tool_start(context=context_wrapper, agent=agent, tool=action.computer_tool) if agent.hooks else _coro.noop_coroutine() ), @@ -1045,9 +1045,9 @@ async def execute( ) await asyncio.gather( - hooks.on_tool_end(context_wrapper, agent, action.computer_tool, output), + hooks.on_tool_end(context=context_wrapper, agent=agent, tool=action.computer_tool, result=output), ( - agent.hooks.on_tool_end(context_wrapper, agent, action.computer_tool, output) + agent.hooks.on_tool_end(context=context_wrapper, agent=agent, tool=action.computer_tool, result=output) if agent.hooks else _coro.noop_coroutine() ), @@ -1138,9 +1138,9 @@ async def execute( config: RunConfig, ) -> RunItem: await asyncio.gather( - hooks.on_tool_start(context_wrapper, agent, call.local_shell_tool), + hooks.on_tool_start(context=context_wrapper, agent=agent, tool=call.local_shell_tool), ( - agent.hooks.on_tool_start(context_wrapper, agent, call.local_shell_tool) + agent.hooks.on_tool_start(context=context_wrapper, agent=agent, tool=call.local_shell_tool) if agent.hooks else _coro.noop_coroutine() ), @@ -1157,9 +1157,9 @@ async def execute( result = output await asyncio.gather( - hooks.on_tool_end(context_wrapper, agent, call.local_shell_tool, result), + hooks.on_tool_end(context=context_wrapper, agent=agent, tool=call.local_shell_tool, result=result), ( - agent.hooks.on_tool_end(context_wrapper, agent, call.local_shell_tool, result) + agent.hooks.on_tool_end(context=context_wrapper, agent=agent, tool=call.local_shell_tool, result=result) if agent.hooks else _coro.noop_coroutine() ), diff --git a/src/agents/guardrail.py b/src/agents/guardrail.py index a96f0f7d7..546c56ff3 100644 --- a/src/agents/guardrail.py +++ b/src/agents/guardrail.py @@ -241,7 +241,9 @@ async def my_async_guardrail(...): ... def decorator( f: _InputGuardrailFuncSync[TContext_co] | _InputGuardrailFuncAsync[TContext_co], ) -> InputGuardrail[TContext_co]: - return InputGuardrail(guardrail_function=f, name=name) + + # The function name should be the name of the guardrail if no name is defined + return InputGuardrail(guardrail_function=f, name=name if name else f._name_) if func is not None: # Decorator was used without parentheses diff --git a/src/agents/run.py b/src/agents/run.py index e5f9378ec..50a65a60e 100644 --- a/src/agents/run.py +++ b/src/agents/run.py @@ -785,9 +785,9 @@ async def _run_single_turn_streamed( ) -> SingleStepResult: if should_run_agent_start_hooks: await asyncio.gather( - hooks.on_agent_start(context_wrapper, agent), + hooks.on_agent_start(context=context_wrapper, agent=agent), ( - agent.hooks.on_start(context_wrapper, agent) + agent.hooks.on_start(context=context_wrapper, agent=agent) if agent.hooks else _coro.noop_coroutine() ), @@ -889,9 +889,9 @@ async def _run_single_turn( # Ensure we run the hooks before anything else if should_run_agent_start_hooks: await asyncio.gather( - hooks.on_agent_start(context_wrapper, agent), + hooks.on_agent_start(context=context_wrapper, agent=agent), ( - agent.hooks.on_start(context_wrapper, agent) + agent.hooks.on_start(context=context_wrapper, agent=agent) if agent.hooks else _coro.noop_coroutine() ),