Skip to content

Commit 8d939f8

Browse files
authored
Fix AzureAIClient dropping agent instructions (Responses API) (#3636)
1 parent 6fdf611 commit 8d939f8

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

python/packages/azure-ai/agent_framework_azure_ai/_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,10 @@ async def _get_agent_reference_or_create(
352352
args["text"] = PromptAgentDefinitionText(format=create_text_format_config(response_format))
353353

354354
# Combine instructions from messages and options
355+
# instructions is accessed from chat_options since the base class excludes it from run_options
355356
combined_instructions = [
356357
instructions
357-
for instructions in [messages_instructions, run_options.get("instructions")]
358+
for instructions in [messages_instructions, chat_options.get("instructions") if chat_options else None]
358359
if instructions
359360
]
360361
if combined_instructions:

python/packages/azure-ai/tests/test_azure_ai_client.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,16 +695,37 @@ async def test_agent_creation_with_instructions(
695695
mock_agent.version = "1.0"
696696
mock_project_client.agents.create_version = AsyncMock(return_value=mock_agent)
697697

698-
run_options = {"model": "test-model", "instructions": "Option instructions. "}
698+
run_options = {"model": "test-model"}
699+
chat_options = {"instructions": "Option instructions. "}
699700
messages_instructions = "Message instructions. "
700701

701-
await client._get_agent_reference_or_create(run_options, messages_instructions) # type: ignore
702+
await client._get_agent_reference_or_create(run_options, messages_instructions, chat_options) # type: ignore
702703

703704
# Verify agent was created with combined instructions
704705
call_args = mock_project_client.agents.create_version.call_args
705706
assert call_args[1]["definition"].instructions == "Message instructions. Option instructions. "
706707

707708

709+
async def test_agent_creation_with_instructions_from_chat_options(
710+
mock_project_client: MagicMock,
711+
) -> None:
712+
"""Test agent creation with instructions passed only via chat_options."""
713+
client = create_test_azure_ai_client(mock_project_client, agent_name="test-agent")
714+
715+
mock_agent = MagicMock()
716+
mock_agent.name = "test-agent"
717+
mock_agent.version = "1.0"
718+
mock_project_client.agents.create_version = AsyncMock(return_value=mock_agent)
719+
720+
run_options = {"model": "test-model"}
721+
chat_options = {"instructions": "Chat options instructions."}
722+
723+
await client._get_agent_reference_or_create(run_options, None, chat_options) # type: ignore
724+
725+
call_args = mock_project_client.agents.create_version.call_args
726+
assert call_args[1]["definition"].instructions == "Chat options instructions."
727+
728+
708729
async def test_agent_creation_with_additional_args(
709730
mock_project_client: MagicMock,
710731
) -> None:

0 commit comments

Comments
 (0)