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
6 changes: 6 additions & 0 deletions python/packages/foundry/agent_framework_foundry/_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ def __init__(
credential: AzureCredentialTypes | None = None,
project_client: AIProjectClient | None = None,
allow_preview: bool | None = None,
default_headers: Mapping[str, str] | None = None,
tools: FunctionTool | Callable[..., Any] | Sequence[FunctionTool | Callable[..., Any]] | None = None,
context_providers: Sequence[ContextProvider] | None = None,
middleware: Sequence[MiddlewareTypes] | None = None,
Expand Down Expand Up @@ -639,6 +640,7 @@ def __init__(
credential: Azure credential for authentication.
project_client: An existing AIProjectClient to use.
allow_preview: Enables preview opt-in on internally-created AIProjectClient.
default_headers: Additional HTTP headers for requests made through the OpenAI client.
tools: Function tools to provide to the agent. Only ``FunctionTool`` objects are accepted.
context_providers: Optional context providers for injecting dynamic context.
middleware: Optional agent-level middleware.
Expand Down Expand Up @@ -672,6 +674,7 @@ def __init__(
"credential": credential,
"project_client": project_client,
"allow_preview": allow_preview,
"default_headers": default_headers,
"env_file_path": env_file_path,
"env_file_encoding": env_file_encoding,
}
Expand Down Expand Up @@ -894,6 +897,7 @@ def __init__(
credential: AzureCredentialTypes | None = None,
project_client: AIProjectClient | None = None,
allow_preview: bool | None = None,
default_headers: Mapping[str, str] | None = None,
tools: FunctionTool | Callable[..., Any] | Sequence[FunctionTool | Callable[..., Any]] | None = None,
context_providers: Sequence[ContextProvider] | None = None,
middleware: Sequence[MiddlewareTypes] | None = None,
Expand Down Expand Up @@ -936,6 +940,7 @@ def __init__(
Set this to ``True`` for HostedAgents that need preview-only
session APIs, including lazy service session creation from
``isolation_key``.
default_headers: Additional HTTP headers for requests made through the OpenAI client.
tools: Function tools to provide to the agent. Only ``FunctionTool`` objects are accepted.
context_providers: Optional context providers.
middleware: Optional agent-level middleware.
Expand Down Expand Up @@ -963,6 +968,7 @@ def __init__(
credential=credential,
project_client=project_client,
allow_preview=allow_preview,
default_headers=default_headers,
tools=tools,
context_providers=context_providers,
middleware=middleware,
Expand Down
42 changes: 42 additions & 0 deletions python/packages/foundry/tests/foundry/test_foundry_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,46 @@ def test_raw_foundry_agent_init_creates_client() -> None:
assert agent.client.agent_name == "test-agent"


def test_raw_foundry_agent_init_passes_default_headers_to_client() -> None:
"""Test that RawFoundryAgent passes default_headers to the underlying client."""

mock_project = MagicMock()
mock_project.get_openai_client.return_value = MagicMock()
default_headers = {"x-ms-user-isolation-key": "user-1"}

RawFoundryAgent(
project_client=mock_project,
agent_name="hosted-agent",
allow_preview=True,
default_headers=default_headers,
)
Comment on lines +515 to +520

mock_project.get_openai_client.assert_called_once_with(
default_headers=default_headers,
agent_name="hosted-agent",
)
Comment on lines +522 to +525


def test_foundry_agent_init_passes_default_headers_to_client() -> None:
"""Test that FoundryAgent passes default_headers to the underlying client."""

mock_project = MagicMock()
mock_project.get_openai_client.return_value = MagicMock()
default_headers = {"x-ms-user-isolation-key": "user-1"}

FoundryAgent(
project_client=mock_project,
agent_name="hosted-agent",
allow_preview=True,
default_headers=default_headers,
)

mock_project.get_openai_client.assert_called_once_with(
default_headers=default_headers,
agent_name="hosted-agent",
)
Comment on lines +542 to +545


def test_raw_foundry_agent_init_with_custom_client_type() -> None:
"""Test that client_type parameter is respected."""

Expand All @@ -523,6 +563,7 @@ def test_raw_foundry_agent_init_with_custom_client_type() -> None:
def test_raw_foundry_agent_init_uses_explicit_parameters() -> None:
signature = inspect.signature(RawFoundryAgent.__init__)

assert "default_headers" in signature.parameters
assert "instructions" in signature.parameters
assert "default_options" in signature.parameters
assert "compaction_strategy" in signature.parameters
Expand All @@ -534,6 +575,7 @@ def test_raw_foundry_agent_init_uses_explicit_parameters() -> None:
def test_foundry_agent_init_uses_explicit_parameters() -> None:
signature = inspect.signature(FoundryAgent.__init__)

assert "default_headers" in signature.parameters
assert "instructions" in signature.parameters
assert "default_options" in signature.parameters
assert "compaction_strategy" in signature.parameters
Expand Down