mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [BREAKING] parameter naming and other fixes (#1255)
* parameter naming and other fixes * fix test * fix azure openai responses decorator ordering * fix test * fix mypy * fixes in options handling * fix tests * final fixes * exclude macos tests * fix model param
This commit is contained in:
@@ -351,22 +351,28 @@ class AzureAIAgentClient(BaseChatClient):
|
||||
Returns:
|
||||
str: The agent_id to use
|
||||
"""
|
||||
run_options = run_options or {}
|
||||
# If no agent_id is provided, create a temporary agent
|
||||
if self.agent_id is None:
|
||||
if not self.model_id:
|
||||
raise ServiceInitializationError("Model deployment name is required for agent creation.")
|
||||
if "model" not in run_options or not run_options["model"]:
|
||||
raise ServiceInitializationError(
|
||||
"Model deployment name is required for agent creation, "
|
||||
"can also be passed to the get_response methods."
|
||||
)
|
||||
|
||||
agent_name: str = self.agent_name or "UnnamedAgent"
|
||||
args: dict[str, Any] = {"model": self.model_id, "name": agent_name}
|
||||
if run_options:
|
||||
if "tools" in run_options:
|
||||
args["tools"] = run_options["tools"]
|
||||
if "tool_resources" in run_options:
|
||||
args["tool_resources"] = run_options["tool_resources"]
|
||||
if "instructions" in run_options:
|
||||
args["instructions"] = run_options["instructions"]
|
||||
if "response_format" in run_options:
|
||||
args["response_format"] = run_options["response_format"]
|
||||
args: dict[str, Any] = {
|
||||
"model": run_options["model"],
|
||||
"name": agent_name,
|
||||
}
|
||||
if "tools" in run_options:
|
||||
args["tools"] = run_options["tools"]
|
||||
if "tool_resources" in run_options:
|
||||
args["tool_resources"] = run_options["tool_resources"]
|
||||
if "instructions" in run_options:
|
||||
args["instructions"] = run_options["instructions"]
|
||||
if "response_format" in run_options:
|
||||
args["response_format"] = run_options["response_format"]
|
||||
created_agent = await self.project_client.agents.create_agent(**args)
|
||||
self.agent_id = str(created_agent.id)
|
||||
self._should_delete_agent = True
|
||||
@@ -673,7 +679,10 @@ class AzureAIAgentClient(BaseChatClient):
|
||||
|
||||
if chat_options is not None:
|
||||
run_options["max_completion_tokens"] = chat_options.max_tokens
|
||||
run_options["model"] = chat_options.model_id
|
||||
if chat_options.model_id is not None:
|
||||
run_options["model"] = chat_options.model_id
|
||||
else:
|
||||
run_options["model"] = self.model_id
|
||||
run_options["top_p"] = chat_options.top_p
|
||||
run_options["temperature"] = chat_options.temperature
|
||||
run_options["parallel_tool_calls"] = chat_options.allow_multiple_tool_calls
|
||||
|
||||
@@ -285,7 +285,7 @@ async def test_azure_ai_chat_client_get_agent_id_or_create_create_new(
|
||||
azure_ai_settings = AzureAISettings(model_deployment_name=azure_ai_unit_test_env["AZURE_AI_MODEL_DEPLOYMENT_NAME"])
|
||||
chat_client = create_test_azure_ai_chat_client(mock_ai_project_client, azure_ai_settings=azure_ai_settings)
|
||||
|
||||
agent_id = await chat_client._get_agent_id_or_create() # type: ignore
|
||||
agent_id = await chat_client._get_agent_id_or_create(run_options={"model": azure_ai_settings.model_deployment_name}) # type: ignore
|
||||
|
||||
assert agent_id == "test-agent-id"
|
||||
assert chat_client._should_delete_agent # type: ignore
|
||||
@@ -577,6 +577,7 @@ async def test_azure_ai_chat_client_get_agent_id_or_create_with_run_options(
|
||||
"tools": [{"type": "function", "function": {"name": "test_tool"}}],
|
||||
"instructions": "Test instructions",
|
||||
"response_format": {"type": "json_object"},
|
||||
"model": azure_ai_settings.model_deployment_name,
|
||||
}
|
||||
|
||||
agent_id = await chat_client._get_agent_id_or_create(run_options) # type: ignore
|
||||
@@ -1277,7 +1278,7 @@ async def test_azure_ai_chat_client_get_agent_id_or_create_with_agent_name(
|
||||
# Ensure agent_name is None to test the default
|
||||
chat_client.agent_name = None # type: ignore
|
||||
|
||||
agent_id = await chat_client._get_agent_id_or_create() # type: ignore
|
||||
agent_id = await chat_client._get_agent_id_or_create(run_options={"model": azure_ai_settings.model_deployment_name}) # type: ignore
|
||||
|
||||
assert agent_id == "test-agent-id"
|
||||
# Verify create_agent was called with default "UnnamedAgent"
|
||||
@@ -1294,7 +1295,7 @@ async def test_azure_ai_chat_client_get_agent_id_or_create_with_response_format(
|
||||
chat_client = create_test_azure_ai_chat_client(mock_ai_project_client, azure_ai_settings=azure_ai_settings)
|
||||
|
||||
# Test with response_format in run_options
|
||||
run_options = {"response_format": {"type": "json_object"}}
|
||||
run_options = {"response_format": {"type": "json_object"}, "model": azure_ai_settings.model_deployment_name}
|
||||
|
||||
agent_id = await chat_client._get_agent_id_or_create(run_options) # type: ignore
|
||||
|
||||
@@ -1313,7 +1314,10 @@ async def test_azure_ai_chat_client_get_agent_id_or_create_with_tool_resources(
|
||||
chat_client = create_test_azure_ai_chat_client(mock_ai_project_client, azure_ai_settings=azure_ai_settings)
|
||||
|
||||
# Test with tool_resources in run_options
|
||||
run_options = {"tool_resources": {"vector_store_ids": ["vs-123"]}}
|
||||
run_options = {
|
||||
"tool_resources": {"vector_store_ids": ["vs-123"]},
|
||||
"model": azure_ai_settings.model_deployment_name,
|
||||
}
|
||||
|
||||
agent_id = await chat_client._get_agent_id_or_create(run_options) # type: ignore
|
||||
|
||||
|
||||
Reference in New Issue
Block a user