diff --git a/python/packages/core/agent_framework/_agent_hooks.py b/python/packages/core/agent_framework/_agent_hooks.py index 669cdb262a..71fe28884f 100644 --- a/python/packages/core/agent_framework/_agent_hooks.py +++ b/python/packages/core/agent_framework/_agent_hooks.py @@ -857,9 +857,15 @@ def _agent_updates_from_response(response: AgentResponse[Any]) -> list[AgentResp def _tool_names(context: AgentContext) -> list[str]: """Project the registered tool names for ``agent_startup`` (spec ``tools_registered``).""" - from ._tools import _get_tool_name, normalize_tools # type: ignore[reportPrivateUsage] + from ._tools import _get_tool_name, normalize_tools # pyright: ignore[reportPrivateUsage] - tools: Any = context.tools if context.tools is not None else getattr(context.agent, "tools", None) + if context.tools is not None: + tools: Any = context.tools + else: + tools = getattr(context.agent, "tools", None) + default_options = getattr(context.agent, "default_options", None) + if tools is None and isinstance(default_options, Mapping): + tools = cast(Any, cast(Mapping[str, Any], default_options).get("tools")) if tools is None: return [] try: diff --git a/python/packages/core/tests/core/test_agent_hooks.py b/python/packages/core/tests/core/test_agent_hooks.py index 347d7bae4f..de347f3836 100644 --- a/python/packages/core/tests/core/test_agent_hooks.py +++ b/python/packages/core/tests/core/test_agent_hooks.py @@ -275,6 +275,22 @@ async def test_full_tool_run_emits_complete_ordered_session(chat_client_base: Mo assert pre_tool["tool_call"]["id"] == "call_1" +@requires_sdk +async def test_agent_startup_projects_constructor_registered_tools(chat_client_base: MockBaseChatClient) -> None: + guard = AllowGuard() + agent = Agent( + client=chat_client_base, + tools=[weather_tool], + middleware=[create_agent_hooks_middleware([guard])], + ) + + await agent.run("hello") + + startup = guard.contexts_for("agent_startup") + assert len(startup) == 1 + assert startup[0]["agent_init"]["tools_registered"] == ["weather_tool"] + + @requires_sdk async def test_input_projection_is_faithful(chat_client_base: MockBaseChatClient) -> None: guard = AllowGuard()