Skip to content
Merged
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
3 changes: 2 additions & 1 deletion python/packages/azure-ai/agent_framework_azure_ai/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,10 @@ async def _get_agent_reference_or_create(
args["text"] = PromptAgentDefinitionText(format=create_text_format_config(response_format))

# Combine instructions from messages and options
# instructions is accessed from chat_options since the base class excludes it from run_options
combined_instructions = [
instructions
for instructions in [messages_instructions, run_options.get("instructions")]
for instructions in [messages_instructions, chat_options.get("instructions") if chat_options else None]
if instructions
]
if combined_instructions:
Expand Down
25 changes: 23 additions & 2 deletions python/packages/azure-ai/tests/test_azure_ai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,16 +695,37 @@ async def test_agent_creation_with_instructions(
mock_agent.version = "1.0"
mock_project_client.agents.create_version = AsyncMock(return_value=mock_agent)

run_options = {"model": "test-model", "instructions": "Option instructions. "}
run_options = {"model": "test-model"}
chat_options = {"instructions": "Option instructions. "}
messages_instructions = "Message instructions. "

await client._get_agent_reference_or_create(run_options, messages_instructions) # type: ignore
await client._get_agent_reference_or_create(run_options, messages_instructions, chat_options) # type: ignore

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


async def test_agent_creation_with_instructions_from_chat_options(
mock_project_client: MagicMock,
) -> None:
"""Test agent creation with instructions passed only via chat_options."""
client = create_test_azure_ai_client(mock_project_client, agent_name="test-agent")

mock_agent = MagicMock()
mock_agent.name = "test-agent"
mock_agent.version = "1.0"
mock_project_client.agents.create_version = AsyncMock(return_value=mock_agent)

run_options = {"model": "test-model"}
chat_options = {"instructions": "Chat options instructions."}

await client._get_agent_reference_or_create(run_options, None, chat_options) # type: ignore

call_args = mock_project_client.agents.create_version.call_args
assert call_args[1]["definition"].instructions == "Chat options instructions."


async def test_agent_creation_with_additional_args(
mock_project_client: MagicMock,
) -> None:
Expand Down
Loading