mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Fix AzureAIAgentClient dropping agent instructions in sequential workflows (#3563)
In _prepare_options(), the 'instructions' key was excluded from run_options but never re-added. This caused instructions passed via as_agent(instructions=...) to be silently dropped, making agents in sequential workflows ignore their configured instructions. Fixes #3507
This commit is contained in:
committed by
GitHub
Unverified
parent
2f7250fe0f
commit
184ee9d518
@@ -948,6 +948,10 @@ class AzureAIAgentClient(BaseChatClient[TAzureAIAgentOptions], Generic[TAzureAIA
|
||||
if additional_messages:
|
||||
run_options["additional_messages"] = additional_messages
|
||||
|
||||
# Add instructions from options (agent's instructions set via as_agent())
|
||||
if options_instructions := options.get("instructions"):
|
||||
instructions.append(options_instructions)
|
||||
|
||||
# Add instruction from existing agent at the beginning
|
||||
if (
|
||||
agent_definition is not None
|
||||
|
||||
@@ -467,6 +467,56 @@ async def test_azure_ai_chat_client_prepare_options_with_messages(mock_agents_cl
|
||||
assert len(run_options["additional_messages"]) == 1 # Only user message
|
||||
|
||||
|
||||
async def test_azure_ai_chat_client_prepare_options_with_instructions_from_options(
|
||||
mock_agents_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test _prepare_options includes instructions passed via options.
|
||||
|
||||
This verifies that agent instructions set via as_agent(instructions=...)
|
||||
are properly included in the API call.
|
||||
"""
|
||||
chat_client = create_test_azure_ai_chat_client(mock_agents_client, agent_id="test-agent")
|
||||
mock_agents_client.get_agent = AsyncMock(return_value=None)
|
||||
|
||||
messages = [ChatMessage(role=Role.USER, text="Hello")]
|
||||
chat_options: ChatOptions = {
|
||||
"instructions": "You are a thoughtful reviewer. Give brief feedback.",
|
||||
}
|
||||
|
||||
run_options, _ = await chat_client._prepare_options(messages, chat_options) # type: ignore
|
||||
|
||||
assert "instructions" in run_options
|
||||
assert "reviewer" in run_options["instructions"].lower()
|
||||
|
||||
|
||||
async def test_azure_ai_chat_client_prepare_options_merges_instructions_from_messages_and_options(
|
||||
mock_agents_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test _prepare_options merges instructions from both system messages and options.
|
||||
|
||||
When instructions come from both system/developer messages AND from options,
|
||||
both should be included in the final instructions.
|
||||
"""
|
||||
chat_client = create_test_azure_ai_chat_client(mock_agents_client, agent_id="test-agent")
|
||||
mock_agents_client.get_agent = AsyncMock(return_value=None)
|
||||
|
||||
messages = [
|
||||
ChatMessage(role=Role.SYSTEM, text="Context: You are reviewing marketing copy."),
|
||||
ChatMessage(role=Role.USER, text="Review this tagline"),
|
||||
]
|
||||
chat_options: ChatOptions = {
|
||||
"instructions": "Be concise and constructive in your feedback.",
|
||||
}
|
||||
|
||||
run_options, _ = await chat_client._prepare_options(messages, chat_options) # type: ignore
|
||||
|
||||
assert "instructions" in run_options
|
||||
instructions_text = run_options["instructions"]
|
||||
# Both instruction sources should be present
|
||||
assert "marketing" in instructions_text.lower()
|
||||
assert "concise" in instructions_text.lower()
|
||||
|
||||
|
||||
async def test_azure_ai_chat_client_inner_get_response(mock_agents_client: MagicMock) -> None:
|
||||
"""Test _inner_get_response method."""
|
||||
chat_client = create_test_azure_ai_chat_client(mock_agents_client, agent_id="test-agent")
|
||||
|
||||
Reference in New Issue
Block a user