mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Fix AzureAIClient dropping agent instructions (Responses API) (#3636)
This commit is contained in:
committed by
GitHub
Unverified
parent
6fdf6111e6
commit
8d939f8ffa
@@ -352,9 +352,10 @@ class AzureAIClient(OpenAIBaseResponsesClient[TAzureAIClientOptions], Generic[TA
|
||||
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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user