Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions python/packages/core/agent_framework/_agent_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions python/packages/core/tests/core/test_agent_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading