async def test_azure_foundry_agent_constructor_defaults(  # Added async and mock arguments
    mock_project_client_class: MagicMock, mock_credential_class: MagicMock
):
    """Test the constructor of AzureFoundryAgent with default values."""
    endpoint = "https://test-endpoint.com"
    model = "gpt-4o"
    name = "test-azure-agent-defaults"
    instructions = "You are a test agent. (defaults)"
    thread_id = None
    verbose = False
    run_retrieve_sleep_time = 1.0

    mock_project_client_instance = MagicMock(spec=AIProjectClient)
    mock_azure_agent_instance = MagicMock(spec=AzureAgent)
    mock_azure_agent_instance.id = "mock_agent_id_defaults"
    mock_thread_instance = MagicMock(spec=AgentThread)
    mock_thread_instance.id = "mock_thread_id_defaults"

    # Patch async methods with AsyncMock
    mock_project_client_instance.agents.create_agent = AsyncMock(
        return_value=mock_azure_agent_instance
    )
    mock_project_client_instance.agents.threads.create = AsyncMock(
        return_value=mock_thread_instance
    )

    with patch(
        "llama_index.agent.azure_foundry_agent.base.DefaultAzureCredential", MagicMock()
    ):
        with patch(
            "llama_index.agent.azure_foundry_agent.base.AIProjectClient",
            return_value=mock_project_client_instance,
        ):
            # Test initialization with defaults
            agent_defaults = AzureFoundryAgent(
                endpoint=endpoint,
                model=model,
                name=name,
                instructions=instructions,
                thread_id=thread_id,
                verbose=verbose,
                run_retrieve_sleep_time=run_retrieve_sleep_time,
            )

            assert agent_defaults.name == name
            assert agent_defaults._endpoint == endpoint
            assert agent_defaults._model == model
            assert agent_defaults._instructions == instructions
            assert agent_defaults._thread_id is None
            assert agent_defaults._verbose is False
            assert agent_defaults._run_retrieve_sleep_time == run_retrieve_sleep_time
            assert agent_defaults._client == mock_project_client_instance

            # Ensure that create_agent and threads.create are called only after _ensure_agent
            await agent_defaults._ensure_agent([])
            print(
                f"create_agent call count: {mock_project_client_instance.agents.create_agent.call_count}"
            )
            print(
                f"threads.create call count: {mock_project_client_instance.agents.threads.create.call_count}"
            )
            mock_project_client_instance.agents.create_agent.assert_called_once()
            mock_project_client_instance.agents.threads.create.assert_called_once()

            # Check that the thread_id was set to the created thread's ID
            assert agent_defaults._thread_id == mock_thread_instance.id
Test the constructor of AzureFoundryAgent with default values.
llama-index-integrations/agent/llama-index-agent-azure/tests/test_azure_foundry_agent.py