mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Fixed instructions duplication in model clients (#1332)
* Small fix * Updated instruction handling in chat clients
This commit is contained in:
@@ -830,7 +830,11 @@ class AzureAIAgentClient(BaseChatClient):
|
||||
run_options["additional_messages"] = additional_messages
|
||||
|
||||
# Add instruction from existing agent at the beginning
|
||||
if agent_definition is not None and agent_definition.instructions:
|
||||
if (
|
||||
agent_definition is not None
|
||||
and agent_definition.instructions
|
||||
and agent_definition.instructions not in instructions
|
||||
):
|
||||
instructions.insert(0, agent_definition.instructions)
|
||||
|
||||
if len(instructions) > 0:
|
||||
|
||||
@@ -554,6 +554,19 @@ async def test_azure_ai_chat_client_create_run_options_with_messages(mock_ai_pro
|
||||
assert len(run_options["additional_messages"]) == 1 # Only user message
|
||||
|
||||
|
||||
async def test_azure_ai_chat_client_instructions_sent_once(mock_ai_project_client: MagicMock) -> None:
|
||||
"""Ensure instructions are only sent once for AzureAIAgentClient."""
|
||||
chat_client = create_test_azure_ai_chat_client(mock_ai_project_client)
|
||||
|
||||
instructions = "You are a helpful assistant."
|
||||
chat_options = ChatOptions(instructions=instructions)
|
||||
messages = chat_client.prepare_messages([ChatMessage(role=Role.USER, text="Hello")], chat_options)
|
||||
|
||||
run_options, _ = await chat_client._create_run_options(messages, chat_options) # type: ignore
|
||||
|
||||
assert run_options.get("instructions") == instructions
|
||||
|
||||
|
||||
async def test_azure_ai_chat_client_inner_get_response(mock_ai_project_client: MagicMock) -> None:
|
||||
"""Test _inner_get_response method."""
|
||||
chat_client = create_test_azure_ai_chat_client(mock_ai_project_client, agent_id="test-agent")
|
||||
|
||||
Reference in New Issue
Block a user