Skip to content

Commit 3cd805f

Browse files
authored
Added additional arguments for Azure AI agent (#2922)
1 parent c7ddb8a commit 3cd805f

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ async def _get_agent_reference_or_create(
335335

336336
if "tools" in run_options:
337337
args["tools"] = run_options["tools"]
338+
if "temperature" in run_options:
339+
args["temperature"] = run_options["temperature"]
340+
if "top_p" in run_options:
341+
args["top_p"] = run_options["top_p"]
338342

339343
if "response_format" in run_options:
340344
response_format = run_options["response_format"]
@@ -413,7 +417,7 @@ async def prepare_options(
413417

414418
# Remove properties that are not supported on request level
415419
# but were configured on agent level
416-
exclude = ["model", "tools", "response_format"]
420+
exclude = ["model", "tools", "response_format", "temperature", "top_p"]
417421

418422
for property in exclude:
419423
run_options.pop(property, None)

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,30 @@ async def test_azure_ai_client_agent_creation_with_instructions(
477477
assert call_args[1]["definition"].instructions == "Message instructions. Option instructions. "
478478

479479

480+
async def test_azure_ai_client_agent_creation_with_additional_args(
481+
mock_project_client: MagicMock,
482+
) -> None:
483+
"""Test agent creation with additional arguments."""
484+
client = create_test_azure_ai_client(mock_project_client, agent_name="test-agent")
485+
486+
# Mock agent creation response
487+
mock_agent = MagicMock()
488+
mock_agent.name = "test-agent"
489+
mock_agent.version = "1.0"
490+
mock_project_client.agents.create_version = AsyncMock(return_value=mock_agent)
491+
492+
run_options = {"model": "test-model", "temperature": 0.9, "top_p": 0.8}
493+
messages_instructions = "Message instructions. "
494+
495+
await client._get_agent_reference_or_create(run_options, messages_instructions) # type: ignore
496+
497+
# Verify agent was created with provided arguments
498+
call_args = mock_project_client.agents.create_version.call_args
499+
definition = call_args[1]["definition"]
500+
assert definition.temperature == 0.9
501+
assert definition.top_p == 0.8
502+
503+
480504
async def test_azure_ai_client_agent_creation_with_tools(
481505
mock_project_client: MagicMock,
482506
) -> None:

0 commit comments

Comments
 (0)